Skip to content

Revert const hacks and use const closures in std#155957

Open
oli-obk wants to merge 2 commits intorust-lang:mainfrom
oli-obk:const-closure-std
Open

Revert const hacks and use const closures in std#155957
oli-obk wants to merge 2 commits intorust-lang:mainfrom
oli-obk:const-closure-std

Conversation

@oli-obk
Copy link
Copy Markdown
Contributor

@oli-obk oli-obk commented Apr 29, 2026

This revealed some smaller bugs in stability checking that I fixed where needed:

  • const closures use the const stability of their parent
  • trait method default bodies use the const stability of their trait

Otherwise trivial reverts of the const hacks that were added

fixes #155781

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 29, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e, scottmcm

Copy link
Copy Markdown
Member

@jhpratt jhpratt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me from a libs side with the one question resolved. I'm not a compiler reviewer, but the small change is obviously correct.

View changes since this review

Comment thread library/core/src/ops/try_trait.rs
@rust-log-analyzer

This comment has been minimized.

@theemathas
Copy link
Copy Markdown
Contributor

Does this fix #155781?

@jhpratt
Copy link
Copy Markdown
Member

jhpratt commented Apr 29, 2026

I'm pretty sure it will

Comment thread library/core/src/array/mod.rs Outdated
F: [const] FnMut(usize) -> T + [const] Destruct,
{
try_from_fn(NeverShortCircuit::wrap_mut_1(f)).0
try_from_fn(const move |a| NeverShortCircuit(f(a))).0
Copy link
Copy Markdown
Contributor Author

@oli-obk oli-obk Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, the Wrapped type was only used in these two cases

View changes since the review

debug_assert!(elem_layout.size() == elem_layout.pad_to_align().size());

// FIXME(const-hack) return to using `map` and `map_err` once `const_closures` is implemented
match elem_layout.repeat_packed(cap) {
Copy link
Copy Markdown
Contributor

@bend-n bend-n Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't it repeat_packed?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a very recent change and I messed up a rebase over it, fixed

@oli-obk oli-obk force-pushed the const-closure-std branch 2 times, most recently from 9b213cb to 3b0794b Compare April 29, 2026 16:25
@oli-obk
Copy link
Copy Markdown
Contributor Author

oli-obk commented Apr 29, 2026

Does this fix #155781?

oh. yes! I ran into this issue but didn't realize there was an issue open for it

@oli-obk oli-obk force-pushed the const-closure-std branch from 3b0794b to c9725eb Compare May 3, 2026 09:17
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 3, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@oli-obk
Copy link
Copy Markdown
Contributor Author

oli-obk commented May 3, 2026

@bors r=jhpratt

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 3, 2026

📌 Commit c9725eb has been approved by jhpratt

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 3, 2026
@oli-obk
Copy link
Copy Markdown
Contributor Author

oli-obk commented May 3, 2026

@bors rollup

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 3, 2026
Revert const hacks and use const closures in std

This revealed some smaller bugs in stability checking that I fixed where needed:

* const closures use the const stability of their parent
* trait method default bodies use the const stability of their trait

Otherwise trivial reverts of the const hacks that were added

fixes rust-lang#155781
rust-bors Bot pushed a commit that referenced this pull request May 3, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #156073 ([rustdoc] Fix `doc_cfg` feature on reexports)
 - #155433 (Rip out rustc_layout_scalar_valid_range_* attribute support)
 - #155957 (Revert const hacks and use const closures in std)
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors r-
#156108 (comment)

Not sure how this PR causes it, but the other 2 PRs in the rollup seem even less likely
@bors try jobs=dist-i586-gnu-i586-i686-musl

@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 3, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 3, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 3, 2026

This pull request was unapproved.

This PR was contained in a rollup (#156108), which was unapproved.

View changes since this unapproval

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 3, 2026
Revert const hacks and use const closures in std


try-job: dist-i586-gnu-i586-i686-musl
{
// FIXME(const-hack): revert this to a const closure
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
#[rustc_inherit_overflow_checks]
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right probably caused by the removal of rustc_inherit_overflow_checks

View changes since the review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 3, 2026

💔 Test for 6389d03 failed: CI. Failed job:

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job dist-i586-gnu-i586-i686-musl failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
failures:

---- [ui] tests/ui/iterators/iter-count-overflow-debug.rs stdout ----

error: test did not exit with success! code=Some(101) so test would pass with `run-fail`
status: exit status: 101
command: cd "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/iterators/iter-count-overflow-debug" && RUSTC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUST_TEST_THREADS="4" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/iterators/iter-count-overflow-debug/a"
stdout: none
--- stderr -------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PG-const-traits Project group: Const traits S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Const closures inside const_unstable functions are claimed to be exposed to stable

8 participants