Revert const hacks and use const closures in std rust-lang/rust#155957
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,libsexpanded to 8 candidates- Random selection from
Mark-Simulacrum,jhpratt,nia-e,scottmcm
r=me from a libs side with the one question resolved. I'm not a compiler reviewer, but the small change is obviously correct.
library/core/src/ops/try_trait.rs · resolved
| 398 | 398 | /// Not currently planned to be exposed publicly, so just `pub(crate)`. |
| 399 | 399 | #[repr(transparent)] |
| 400 | 400 | pub(crate) struct NeverShortCircuit<T>(pub T); |
| 401 | // FIXME(const-hack): replace with `|a| NeverShortCircuit(f(a))` when const closures added. |
Are these simply not needed any more?
yeah, they were only for wrap_mut_1. but, i think the wrap_mut_1 function should still exist? it wasnt added as a const hack.
hmm... I guess we could keep it and return a const closure from it, but is it really worth it?
i mean i think so.. thats what was done pre const hack at least, and i dont think it was a bad design?
the fixme i wrote on the const-hack was intended to be put in wrap_mut_1
View on GitHub
The job aarch64-gnu-llvm-21-2 failed! Check out the build log: (web) (plain enhanced) (plain)
Click to see the possible cause of the failure (guessed by this bot)
Executing "/scripts/stage_2_test_set2.sh"
+ /scripts/stage_2_test_set2.sh
PR_CI_JOB set; skipping tidy
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest
##[group]Building bootstrap
Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://static.rust-lang.org/dist/2026-04-14/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz
---
[RUSTC-TIMING] vec_deque_alloc_error test:true 0.277
error[E0658]: const closures are experimental
##[error] --> alloctests/../alloc/src/raw_vec/mod.rs:903:14
|
903 | .map(const |(layout, _pad)| layout)
| ^^^^^
|
= note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
= help: add `#![feature(const_closures)]` to the crate attributes to enable
= note: this compiler was built on 2026-04-29; consider upgrading it if it is out of date
error[E0658]: const closures are experimental
##[error] --> alloctests/../alloc/src/raw_vec/mod.rs:904:18
|
904 | .map_err(const |_| CapacityOverflow.into())
| ^^^^^
|
= note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
= help: add `#![feature(const_closures)]` to the crate attributes to enable
= note: this compiler was built on 2026-04-29; consider upgrading it if it is out of date
error: `Result::<T, E>::map` is not yet stable as a const fn
##[error] --> alloctests/../alloc/src/raw_vec/mod.rs:901:5
|
901 | / elem_layout
902 | | .repeat(cap)
903 | | .map(const |(layout, _pad)| layout)
| |___________________________________________^
|
help: add `#![feature(const_result_trait_fn)]` to the crate attributes to enable
--> alloctests/lib.rs:70:1
|
70 + #![feature(const_result_trait_fn)]
|
error: `Result::<T, E>::map_err` is not yet stable as a const fn
##[error] --> alloctests/../alloc/src/raw_vec/mod.rs:901:5
|
901 | / elem_layout
902 | | .repeat(cap)
903 | | .map(const |(layout, _pad)| layout)
904 | | .map_err(const |_| CapacityOverflow.into())
| |___________________________________________________^
|
help: add `#![feature(const_result_trait_fn)]` to the crate attributes to enable
--> alloctests/lib.rs:70:1
|
---
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] corebenches test:true 7.935
[RUSTC-TIMING] alloctests test:true 14.879
[RUSTC-TIMING] coretests test:true 74.907
env -u RUSTC_WRAPPER CARGO_ENCODED_RUSTDOCFLAGS="-Zannotate-moves\u{1f}-Zrandomize-layout\u{1f}-Zunstable-options\u{1f}--check-cfg=cfg(bootstrap)\u{1f}-Wrustdoc::invalid_codeblock_attributes\u{1f}--crate-version\u{1f}1.97.0-nightly\t(a7694c44e\t2026-04-29)" CARGO_ENCODED_RUSTFLAGS="-Zannotate-moves\u{1f}-Zrandomize-layout\u{1f}-Zunstable-options\u{1f}--check-cfg=cfg(bootstrap)\u{1f}-Zmacro-backtrace\u{1f}-Csplit-debuginfo=off\u{1f}-Clink-arg=-L/usr/lib/llvm-21/lib\u{1f}-Cllvm-args=-import-instr-limit=10\u{1f}-Clink-args=-Wl,-z,origin\u{1f}-Clink-args=-Wl,-rpath,$ORIGIN/../lib\u{1f}--cap-lints=allow\u{1f}--cfg\u{1f}randomized_layouts" RUSTC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustc-clif" RUSTDOC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustdoc-clif" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo" "test" "--manifest-path" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/sysroot_tests/Cargo.toml" "--target-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/sysroot_tests_target" "--locked" "--target" "aarch64-unknown-linux-gnu" "-p" "coretests" "-p" "alloctests" "--tests" "--" "-q" exited with status ExitStatus(unix_wait_status(25856))
Bootstrap failed while executing `--stage 2 test --skip tidy --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run -Zwarnings --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=release --manifest-path /checkout/compiler/rustc_codegen_cranelift/build_system/Cargo.toml -- test --download-dir /checkout/obj/build/cg_clif_download --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif --no-unstable-features --use-backend cranelift --sysroot llvm --skip-test testsuite.extended_sysroot [workdir=/checkout/compiler/rustc_codegen_cranelift]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/test.rs:3955:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:4000:26
--- BACKTRACE vvv
0: std::backtrace_rs::backtrace::libunwind::trace
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
1: std::backtrace_rs::backtrace::trace_unsynchronized::<<std::backtrace::Backtrace>::create::{closure#0}>
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
2: <std::backtrace::Backtrace>::create
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/backtrace.rs:331:13
3: <bootstrap::utils::exec::DeferredCommand>::finish_process
at /checkout/src/bootstrap/src/utils/exec.rs:939:17
4: <bootstrap::utils::exec::DeferredCommand>::wait_for_output::<&bootstrap::utils::exec::ExecutionContext>
at /checkout/src/bootstrap/src/utils/exec.rs:831:21
5: <bootstrap::utils::exec::ExecutionContext>::run
at /checkout/src/bootstrap/src/utils/exec.rs:741:45
6: <bootstrap::utils::exec::BootstrapCommand>::run::<&bootstrap::core::builder::Builder>
at /checkout/src/bootstrap/src/utils/exec.rs:339:27
7: <bootstrap::core::build_steps::test::CodegenCranelift as bootstrap::core::builder::Step>::run
at /checkout/src/bootstrap/src/core/build_steps/test.rs:4000:26
8: <bootstrap::core::builder::Builder>::ensure::<bootstrap::core::build_steps::test::CodegenCranelift>
at /checkout/src/bootstrap/src/core/builder/mod.rs:1579:36
9: <bootstrap::core::build_steps::test::CodegenCranelift as bootstrap::core::builder::Step>::make_run
at /checkout/src/bootstrap/src/core/build_steps/test.rs:3941:17
10: <bootstrap::core::builder::StepDescription>::maybe_run
at /checkout/src/bootstrap/src/core/builder/mod.rs:476:13
11: bootstrap::core::builder::cli_paths::match_paths_to_steps_and_run
at /checkout/src/bootstrap/src/core/builder/cli_paths.rs:141:22
12: <bootstrap::core::builder::Builder>::run_step_descriptions
at /checkout/src/bootstrap/src/core/builder/mod.rs:1122:9
13: <bootstrap::core::builder::Builder>::execute_cli
at /checkout/src/bootstrap/src/core/builder/mod.rs:1101:14
14: <bootstrap::Build>::build
at /checkout/src/bootstrap/src/lib.rs:803:25
15: bootstrap::main
at /checkout/src/bootstrap/src/bin/main.rs:130:11
16: <fn() as core::ops::function::FnOnce<()>>::call_once
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/core/src/ops/function.rs:250:5
17: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/sys/backtrace.rs:166:18
18: std::rt::lang_start::<()>::{closure#0}
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/rt.rs:206:18
19: <&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync as core::ops::function::FnOnce<()>>::call_once
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/core/src/ops/function.rs:287:21
20: std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panicking.rs:581:40
21: std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync>
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panicking.rs:544:19
22: std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panic.rs:359:14
23: std::rt::lang_start_internal::{closure#0}
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/rt.rs:175:24
24: std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panicking.rs:581:40
---
31: __libc_start_main
32: _start
Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:24:10
local time: Wed Apr 29 07:40:07 UTC 2026
network time: Wed, 29 Apr 2026 07:40:08 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"
Does this fix #155781?
library/core/src/array/mod.rs · outdated
| 111 | 111 | F: [const] FnMut(usize) -> T + [const] Destruct, |
| 112 | 112 | { |
| 113 | try_from_fn(NeverShortCircuit::wrap_mut_1(f)).0 |
|
| 113 | try_from_fn(const move |a| NeverShortCircuit(f(a))).0 |
Yea, the Wrapped type was only used in these two cases
library/alloc/src/raw_vec/mod.rs
| 899 | 899 | debug_assert!(elem_layout.size() == elem_layout.pad_to_align().size()); |
| 900 | 900 | |
| 901 | // FIXME(const-hack) return to using `map` and `map_err` once `const_closures` is implemented |
|
| 902 | match elem_layout.repeat_packed(cap) { |
why isn't it repeat_packed?
I think this was a very recent change and I messed up a rebase over it, fixed
Does this fix #155781?
oh. yes! I ran into this issue but didn't realize there was an issue open for it
View on GitHub
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.
@bors r=jhpratt
@bors rollup
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
This pull request was unapproved.
This PR was contained in a rollup (#156108), which was unapproved.
View on GitHub
⌛ Trying commit c9725eb with merge 6389d03…
To cancel the try build, run the command @bors try cancel.
Workflow: https://github.com/rust-lang/rust/actions/runs/25281899584
library/core/src/iter/traits/iterator.rs
| 228 | 228 | { |
| 229 | // FIXME(const-hack): revert this to a const closure |
|
| 230 | #[rustc_const_unstable(feature = "const_iter", issue = "92476")] |
|
| 231 | #[rustc_inherit_overflow_checks] |
Right probably caused by the removal of rustc_inherit_overflow_checks
💔 Test for 6389d03 failed: CI. Failed job:
try - dist-i586-gnu-i586-i686-musl(web logs, enhanced plaintext logs)
View on GitHub
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 -------------------------------
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.
@bors r=jhpratt
@rust-timer build cbb3ca4
View on GitHub
Queued cbb3ca4 with parent 740679e, future comparison URL.
There is currently 1 preceding artifact in the queue.
It will probably take at least ~1.7 hours until the benchmark run finishes.
Finished benchmarking commit (cbb3ca4): comparison URL.
Overall result: ❌✅ regressions and improvements - no action needed
Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.
@rustbot label: -S-waiting-on-perf -perf-regression
Instruction count
Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
0.3% | [0.3%, 0.3%] | 1 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
- | - | 0 |
| Improvements ✅ (secondary) |
-1.8% | [-1.8%, -1.8%] | 1 |
| All ❌✅ (primary) | 0.3% | [0.3%, 0.3%] | 1 |
Max RSS (memory usage)
Results (primary 0.2%, secondary -3.7%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
2.7% | [2.7%, 2.8%] | 2 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
-2.2% | [-2.3%, -2.2%] | 2 |
| Improvements ✅ (secondary) |
-3.7% | [-8.1%, -0.7%] | 3 |
| All ❌✅ (primary) | 0.2% | [-2.3%, 2.8%] | 4 |
Cycles
Results (primary 2.4%, secondary -0.3%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
2.4% | [2.4%, 2.4%] | 1 |
| Regressions ❌ (secondary) |
0.6% | [0.6%, 0.6%] | 2 |
| Improvements ✅ (primary) |
- | - | 0 |
| Improvements ✅ (secondary) |
-1.3% | [-1.6%, -0.9%] | 2 |
| All ❌✅ (primary) | 2.4% | [2.4%, 2.4%] | 1 |
Binary size
Results (primary 0.2%, secondary -0.6%)
A less reliable metric. May be of interest, but not used to determine the overall result above.
| mean | range | count | |
|---|---|---|---|
| Regressions ❌ (primary) |
0.2% | [0.1%, 0.2%] | 2 |
| Regressions ❌ (secondary) |
- | - | 0 |
| Improvements ✅ (primary) |
- | - | 0 |
| Improvements ✅ (secondary) |
-0.6% | [-0.6%, -0.6%] | 1 |
| All ❌✅ (primary) | 0.2% | [0.1%, 0.2%] | 2 |
Bootstrap: 495.494s -> 495.34s (-0.03%)
Artifact size: 394.42 MiB -> 394.46 MiB (0.01%)
View all comments
This revealed some smaller bugs in stability checking that I fixed where needed:
Otherwise trivial reverts of the const hacks that were added
fixes #155781