From 9487b1d994833709c6dd9568deeb1bcf3c50347b Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Sun, 25 Oct 2026 17:22:44 +0200 Subject: [PATCH 01/27] Specialize more builtin types for `<[MaybeUninit<_>]>::write_default()` --- library/core/src/mem/maybe_uninit.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 94703940baa1f..9a3ed42abd2b6 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -1375,6 +1375,8 @@ impl [MaybeUninit] { }; } + spec_default_zero!(bool); // The default is `false == 0`. + spec_default_zero!(char); spec_default_zero!(i8); spec_default_zero!(u8); spec_default_zero!(i16); @@ -1387,6 +1389,11 @@ impl [MaybeUninit] { spec_default_zero!(u128); spec_default_zero!(isize); spec_default_zero!(usize); + // +0.0 has binary representation of all-zeros: + spec_default_zero!(f16); + spec_default_zero!(f32); + spec_default_zero!(f64); + spec_default_zero!(f128); T::write_default(self) } From b59a3e40ad06ead8351468ae31fb1b346162bc5d Mon Sep 17 00:00:00 2001 From: ltdk Date: Mon, 2 Nov 2026 20:00:25 -0500 Subject: [PATCH 02/27] Autolabel library sys modules --- triagebot.toml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index 82cb1fe91ffc0..7f7726b4fd768 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -428,6 +428,7 @@ trigger_files = [ [autolabel."A-allocators"] trigger_files = [ "library/{core,alloc,std}/src/alloc{.rs,}", + "library/std/src/sys/**/alloc{.rs,}", ] [autolabel."A-array"] @@ -444,6 +445,7 @@ trigger_files = [ trigger_files = [ "library/backtrace", "library/{core,alloc,std}/src/backtrace{.rs,}", + "library/std/src/sys/**/backtrace{.rs,}", ] [autolabel."A-box"] @@ -484,11 +486,14 @@ trigger_files = [ [autolabel."A-env"] trigger_files = [ "library/{core,alloc,std}/src/env{.rs,}", + "library/std/src/sys/**/env{.rs,}", + "library/std/src/sys/**/env_consts{.rs,}", ] [autolabel."A-filesystem"] trigger_files = [ "library/{core,alloc,std}/src/fs{.rs,}", + "library/std/src/sys/**/fs{.rs,}", ] [autolabel."A-fmt"] @@ -499,6 +504,8 @@ trigger_files = [ [autolabel."A-io"] trigger_files = [ "library/{core,alloc,std}/src/io{.rs,}", + "library/std/src/sys/**/io{.rs,}", + "library/std/src/sys/**/stdio{.rs,}", ] [autolabel."A-iterators"] @@ -509,6 +516,7 @@ trigger_files = [ [autolabel."A-networking"] trigger_files = [ "library/{core,alloc,std}/src/net{.rs,}", + "library/std/src/sys/**/net{.rs,}", ] [autolabel."A-option-result"] @@ -520,6 +528,8 @@ trigger_files = [ [autolabel."A-path"] trigger_files = [ "library/{core,alloc,std}/src/path{.rs,}", + "library/std/src/sys/**/path{.rs,}", + "library/std/src/sys/**/paths{.rs,}", ] [autolabel."A-panic"] @@ -531,6 +541,7 @@ trigger_files = [ [autolabel."A-process"] trigger_files = [ "library/{core,alloc,std}/src/process{.rs,}", + "library/std/src/sys/**/process{.rs,}", ] [autolabel."A-raw-pointers"] @@ -541,6 +552,7 @@ trigger_files = [ [autolabel."A-random"] trigger_files = [ "library/{core,alloc,std}/src/random{.rs,}", + "library/std/src/sys/**/random{.rs,}", ] [autolabel."A-rc"] @@ -563,13 +575,14 @@ trigger_files = [ [autolabel."A-thread"] trigger_files = [ "library/{core,alloc,std}/src/thread{.rs,}", - "library/std/src/sys/thread", - "library/std/src/sys/thread_local", + "library/std/src/sys/**/thread{.rs,}", + "library/std/src/sys/**/thread_local{.rs,}", ] [autolabel."A-time"] trigger_files = [ "library/{core,alloc,std}/src/time{.rs,}", + "library/std/src/sys/**/time{.rs,}", ] [autolabel."O-android"] From 11814eb37cd276f92ccb4f8f573458e4b6147835 Mon Sep 17 00:00:00 2001 From: ltdk Date: Mon, 2 Nov 2026 20:15:13 -0500 Subject: [PATCH 03/27] Autolabel raw_vec module --- triagebot.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index 7f7726b4fd768..b2cbda573ccc3 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -483,6 +483,11 @@ trigger_files = [ "library/{core,alloc,std}/src/collections/vec_deque{.rs,}", ] +[autolabel."A-rawvec"] +trigger_files = [ + "library/{core,alloc,std}/src/raw_vec{.rs,}", +] + [autolabel."A-env"] trigger_files = [ "library/{core,alloc,std}/src/env{.rs,}", From f862ff00c0b590311e7da05220d4ceb2724a4712 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 4 Nov 2026 02:26:51 +0000 Subject: [PATCH 04/27] Suggest using `ExitCode` instead of calling `exit` --- compiler/rustc_error_codes/src/error_codes/E0580.md | 2 +- compiler/rustc_llvm/build.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0580.md b/compiler/rustc_error_codes/src/error_codes/E0580.md index 260575d5de4a2..c2edc4374ea7a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0580.md +++ b/compiler/rustc_error_codes/src/error_codes/E0580.md @@ -18,4 +18,4 @@ fn main() { ``` If you want to get command-line arguments, use `std::env::args`. To exit with a -specified exit code, use `std::process::exit`. +specified exit code, return `std::process::ExitCode` from main. diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 450b98f20cde9..42be146830fba 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -94,8 +94,7 @@ fn execute(cmd: &mut Command) -> Output { let output = match cmd.output() { Ok(status) => status, Err(e) => { - println!("\n\nfailed to execute command: {cmd:?}\nerror: {e}\n\n"); - std::process::exit(1); + panic!("failed to execute command: {cmd:?}\nerror: {e}"); } }; if !output.status.success() { From 2c8ae539aa7006853948c33aa4365be9b446d35f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 3 Nov 2026 18:22:35 +0100 Subject: [PATCH 05/27] rustdoc: Make implementors collapseable if there is more than one line of docs --- src/librustdoc/html/render/mod.rs | 22 ++++++++++--------- src/librustdoc/html/static/css/rustdoc.css | 1 - tests/rustdoc-gui/impl-doc-indent.goml | 3 +-- tests/rustdoc-gui/implementors.goml | 20 +++++++++++------ .../rustdoc-gui/src/lib2/implementors/lib.rs | 6 +++++ tests/rustdoc-gui/src/test_docs/lib.rs | 6 ----- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index bee0f61c3a69e..397dd02899cd3 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2329,7 +2329,6 @@ fn render_impl( )?; } if render_mode == RenderMode::Normal { - let toggled = !(impl_items.is_empty() && default_impl_items.is_empty()); let deprecation_attr = if impl_.is_deprecated || trait_.is_some_and(|trait_| trait_.is_deprecated(cx.tcx())) { @@ -2337,15 +2336,6 @@ fn render_impl( } else { "" }; - if toggled { - close_tags.push(""); - write!( - w, - "
\ - ", - if rendering_params.toggle_open_by_default { " open" } else { "" } - )?; - } let (before_dox, after_dox) = i .impl_item @@ -2364,6 +2354,18 @@ fn render_impl( }) .unwrap_or((None, None)); + let toggled = + !(impl_items.is_empty() && default_impl_items.is_empty() && after_dox.is_none()); + if toggled { + close_tags.push("
"); + write!( + w, + "
\ + ", + if rendering_params.toggle_open_by_default { " open" } else { "" } + )?; + } + write!( w, "{}", diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 2634a9a3d8a95..6f16be58654c8 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -3158,7 +3158,6 @@ in src-script.js and main.js } .variants > .docblock, -.implementors-toggle > .docblock, .impl-items > .toggle[open]:not(:last-child), .methods > .toggle[open]:not(:last-child), .implementors-toggle[open]:not(:last-child) { diff --git a/tests/rustdoc-gui/impl-doc-indent.goml b/tests/rustdoc-gui/impl-doc-indent.goml index d647fec6d732d..abc9bbeb8e92f 100644 --- a/tests/rustdoc-gui/impl-doc-indent.goml +++ b/tests/rustdoc-gui/impl-doc-indent.goml @@ -8,8 +8,7 @@ store-position: ("#impl-Context > .item-info", {"x": impl_item_x}) assert: |impl_x| < |impl_item_x| // And we ensure that all impl items have the same indent. -assert-position: ("#impl-Context > .docblock", {"x": |impl_item_x|}) -assert-position: ("#impl-Context + .docblock", {"x": |impl_item_x|}) +assert-position: ("#impl-Context > .docblock", {"x": |impl_item_x|}, ALL) // Same with the collapsible impl block. assert-position: ("#impl-Context-1 > .docblock", {"x": |impl_item_x|}) diff --git a/tests/rustdoc-gui/implementors.goml b/tests/rustdoc-gui/implementors.goml index d4542c6f78172..31de2f75721a8 100644 --- a/tests/rustdoc-gui/implementors.goml +++ b/tests/rustdoc-gui/implementors.goml @@ -3,7 +3,7 @@ go-to: "file://" + |DOC_PATH| + "/implementors/trait.Whatever.html" wait-for-css: ("#implementors-list", {"display": "block"}) // There are supposed to be four implementors listed. -assert-count: ("#implementors-list .impl", 4) +assert-count: ("#implementors-list .impl", 5) // There are supposed to be two non-negative implementors. assert-count: ("#implementors-list .negative-marker ~ *", 2) // Now we check that both implementors have an anchor, an ID and a similar DOM. @@ -17,9 +17,10 @@ define-function: ( ) call-function: ("check-dom", {"id": "#impl-Whatever-for-Struct2"}) -call-function: ("check-dom", {"id": "#impl-Whatever-2"}) -call-function: ("check-dom", {"id": "#impl-Whatever-for-Struct"}) +call-function: ("check-dom", {"id": "#impl-Whatever-for-Struct3"}) call-function: ("check-dom", {"id": "#impl-Whatever-3"}) +call-function: ("check-dom", {"id": "#impl-Whatever-for-Struct"}) +call-function: ("check-dom", {"id": "#impl-Whatever-4"}) // Ensure that negative impl are sorted first. assert-property: ( @@ -27,21 +28,26 @@ assert-property: ( {"textContent": "impl !Whatever for Struct2"}, ) assert-property: ( - "#implementors-list > *:nth-child(2) > h3", + "#implementors-list > *:nth-child(3) > h3", {"textContent": "impl !Whatever for StructToImplOnReexport"}, ) // Third one is the negative marker. -assert-attribute: ("#implementors-list > *:nth-child(3)", {"class": "negative-marker"}) +assert-attribute: ("#implementors-list > *:nth-child(4)", {"class": "negative-marker"}) // This one is a `` so the selector is a bit different. assert-property: ( - "#implementors-list > *:nth-child(4) section > h3", + "#implementors-list > *:nth-child(5) section > h3", {"textContent": "impl Whatever for Struct"}, ) assert-property: ( - "#implementors-list > *:nth-child(5) > h3", + "#implementors-list > *:nth-child(6) > h3", {"textContent": "impl Whatever for Foo"}, ) +// Ensure that implementors are collapsed by default if they have items. +assert: "details.implementors-toggle:not(:open) #impl-Whatever-for-Struct" +// Same for implementor with more than one line of docs. +assert: "details.implementors-toggle:not(:open) #impl-Whatever-for-Struct3" + go-to: "file://" + |DOC_PATH| + "/test_docs/struct.HasEmptyTraits.html" compare-elements-position-near-false: ( "#impl-EmptyTrait1-for-HasEmptyTraits", diff --git a/tests/rustdoc-gui/src/lib2/implementors/lib.rs b/tests/rustdoc-gui/src/lib2/implementors/lib.rs index f081820039275..99c0133e4cae0 100644 --- a/tests/rustdoc-gui/src/lib2/implementors/lib.rs +++ b/tests/rustdoc-gui/src/lib2/implementors/lib.rs @@ -8,6 +8,7 @@ pub trait Whatever { pub struct Struct; pub struct Struct2; +pub struct Struct3; impl Whatever for Struct { type Foo = u8; @@ -15,6 +16,11 @@ impl Whatever for Struct { impl !Whatever for Struct2 {} +/// fooo +/// +/// bar +impl !Whatever for Struct3 {} + impl http::HttpTrait for Struct {} mod traits { diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs index 1ffcd80581c24..c05ab64022083 100644 --- a/tests/rustdoc-gui/src/test_docs/lib.rs +++ b/tests/rustdoc-gui/src/test_docs/lib.rs @@ -770,12 +770,6 @@ pub mod impls_indent { pub struct Context; /// Working with objects. - /// - /// # Safety - /// - /// Functions that take indices of locals do not check bounds on these indices; - /// the caller must ensure that the indices are less than the number of locals - /// in the current stack frame. impl Context { } From a51b14af6219998514472199e9bcb57726a6f3e4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 28 Oct 2026 14:02:21 +0100 Subject: [PATCH 06/27] Use the `2.38` binutils version in CI --- src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh | 2 +- src/ci/docker/scripts/build-gcc.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh index 4935870dd8d65..21fc7c2a9cd77 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh @@ -16,7 +16,7 @@ python3 ../x.py build --set rust.debug=true opt-dist # Use GCC for building GCC components, as it seems to behave badly when built with Clang # Only build GCC on full builds, not try builds if [ "${DIST_TRY_BUILD:-0}" == "0" ]; then - # We add the binutils binary path to ensure that it uses the 2.47 version of binutils, + # We add the binutils binary path to ensure that it uses the 2.38 version of binutils, # which is needed for the `retain` attribute feature. export PATH="/tmp/binutils-install/bin:$PATH" diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 1a32433f54278..60443744455d9 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -6,7 +6,7 @@ source shared.sh # We have to build our own binutils for the GCC build, because the default CentOS 7 binutils are # too old, and they do not support `SHF_GNU_RETAIN`. -BINUTILS="2.47" +BINUTILS="2.38" BINUTILS_ROOT_PATH="$(pwd)/binutils-install" BINUTILS_PATH="$BINUTILS_ROOT_PATH/bin" curl https://ci-mirrors.rust-lang.org/rustc/gcc/binutils-$BINUTILS.tar.xz | xzcat | tar xf - From 70ed0432c97ac13f02980ca163052fb17a51b862 Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Thu, 5 Nov 2026 10:20:32 -0500 Subject: [PATCH 07/27] update Enzyem submodule --- src/tools/enzyme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/enzyme b/src/tools/enzyme index 7a55d0364ca1e..ffd1ec24186c9 160000 --- a/src/tools/enzyme +++ b/src/tools/enzyme @@ -1 +1 @@ -Subproject commit 7a55d0364ca1e7cb3c797a9d38a6c52061edf02e +Subproject commit ffd1ec24186c9fd7029c6c9925066a1ae2763d6b From 64fe27116b86a93932a1065610decf3bda51b2c2 Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:27:04 +0100 Subject: [PATCH 08/27] Update books --- src/doc/reference | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/reference b/src/doc/reference index 3989fe91f1a60..a2ae66d7037cb 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 3989fe91f1a601b51684a582ad17b2503f221787 +Subproject commit a2ae66d7037cbedac68746b9510b24cc34b96d69 From 39cd593627d09e4ca747fa2ab59188bfccdbf757 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 28 Oct 2026 18:16:58 +0100 Subject: [PATCH 09/27] Disable MAKEINFO when building binutils --- src/ci/docker/scripts/build-gcc.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 60443744455d9..e26684b75fac6 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -14,9 +14,10 @@ mkdir binutils-build mkdir "$BINUTILS_ROOT_PATH" cd binutils-build -hide_output ../binutils-$BINUTILS/configure --prefix="$BINUTILS_ROOT_PATH" --disable-werror -hide_output make -j$(nproc) -hide_output make install +hide_output ../binutils-$BINUTILS/configure \ + --prefix="$BINUTILS_ROOT_PATH" --disable-werror MAKEINFO=true +hide_output make -j$(nproc) MAKEINFO=true +hide_output make install MAKEINFO=true cd .. rm -rf binutils-build binutils-$BINUTILS From 266b16ca75d6d7f916cd6e574835062028c6c75f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 5 Nov 2026 16:10:40 +0100 Subject: [PATCH 10/27] Bump SCCACHE_C_CUSTOM_CACHE_BUSTER to force sccache refresh --- src/ci/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/run.sh b/src/ci/run.sh index 8607b294eb1e0..549f85f35e061 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -244,7 +244,7 @@ trap datecheck EXIT # Bump this value if you need to invalidate sccache's cache, if some wrong # builds go into it -export SCCACHE_C_CUSTOM_CACHE_BUSTER=1 +export SCCACHE_C_CUSTOM_CACHE_BUSTER=2 # We've had problems in the past of shell scripts leaking fds into the sccache # server (#48192) which causes Cargo to erroneously think that a build script From af6c6bc609b4258f21ca6f8a97bf5439442fc923 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 5 Nov 2026 22:25:07 +0100 Subject: [PATCH 11/27] Update CI GCC stamp --- src/bootstrap/download-ci-gcc-stamp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/download-ci-gcc-stamp b/src/bootstrap/download-ci-gcc-stamp index ec8d0fa3135d1..5bda219304547 100644 --- a/src/bootstrap/download-ci-gcc-stamp +++ b/src/bootstrap/download-ci-gcc-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-gcc` configuration download a new version of GCC from CI, even if the GCC submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/150873 +Last change is for: https://github.com/rust-lang/rust/pull/165078 From 2aa9a63eb422fb11efc0fdab317ecd11b5611aa4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 5 Nov 2026 22:31:11 +0100 Subject: [PATCH 12/27] Improve comment --- src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh index 21fc7c2a9cd77..f55fede851765 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh @@ -16,8 +16,10 @@ python3 ../x.py build --set rust.debug=true opt-dist # Use GCC for building GCC components, as it seems to behave badly when built with Clang # Only build GCC on full builds, not try builds if [ "${DIST_TRY_BUILD:-0}" == "0" ]; then - # We add the binutils binary path to ensure that it uses the 2.38 version of binutils, - # which is needed for the `retain` attribute feature. + # We add the binutils binary path to ensure that it uses the 2.38 version of binutils. + # We need the 2.36 version for the `retain` attribute feature but we're stuck with an + # old assembler in another CI image so we cannot go above 2.38, otherwise it doesn't + # work anymore. Fun times. export PATH="/tmp/binutils-install/bin:$PATH" CC=/rustroot/bin/cc CXX=/rustroot/bin/c++ \ From a8e658bcd5f82c4812db20870e4d39470868be31 Mon Sep 17 00:00:00 2001 From: panstromek Date: Fri, 6 Nov 2026 05:55:02 +0100 Subject: [PATCH 13/27] rename MIR_borrow_checking timing scope to less confusing name This phase contains a lot of checks, not only borrowck --- compiler/rustc_interface/src/passes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 6dc3f74f054f1..d393b14e8cdd9 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1159,7 +1159,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { // This improves performance by allowing lock-free access to them. tcx.untracked().definitions.freeze(); - sess.time("MIR_borrow_checking", || { + sess.time("MIR_checking", || { tcx.par_hir_body_owners(|def_id| { let not_typeck_child = !tcx.is_typeck_child(def_id.to_def_id()); if not_typeck_child { From 5f8034cd87a7f6aa034f32098aa8d84d0e714e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 11:29:52 +0100 Subject: [PATCH 14/27] metrics are actually optional Local runs don't emit metrics, trying to update the metrics.json file will always fail. --- src/tools/opt-dist/src/exec.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tools/opt-dist/src/exec.rs b/src/tools/opt-dist/src/exec.rs index bd91e66c16423..5fb3e13a78604 100644 --- a/src/tools/opt-dist/src/exec.rs +++ b/src/tools/opt-dist/src/exec.rs @@ -294,8 +294,9 @@ impl Bootstrap { pub fn run(self, timer: &mut TimerSection) -> anyhow::Result<()> { self.cmd.run()?; - let metrics = load_metrics(&self.metrics_path)?; - record_metrics(&metrics, timer); + if let Ok(metrics) = load_metrics(&self.metrics_path) { + record_metrics(&metrics, timer); + } Ok(()) } } From 9877fc8e242c22835b52381ddbb157d77b1e3090 Mon Sep 17 00:00:00 2001 From: yhx-12243 Date: Fri, 6 Nov 2026 18:45:18 +0800 Subject: [PATCH 15/27] feat: Implement #165545 --- library/core/src/str/mod.rs | 9 +++++++-- library/std/src/ffi/os_str.rs | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index b6c7950901f59..41f624c892859 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -997,7 +997,9 @@ impl str { /// The caller must ensure that `mid` is a valid byte offset from the start /// of the string and falls on the boundary of a UTF-8 code point. #[inline] - const unsafe fn split_at_unchecked(&self, mid: usize) -> (&str, &str) { + #[must_use] + #[unstable(feature = "str_split_at_unchecked", issue = "165545")] + pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&str, &str) { let len = self.len(); let ptr = self.as_ptr(); // SAFETY: caller guarantees `mid` is on a char boundary. @@ -1015,7 +1017,10 @@ impl str { /// /// The caller must ensure that `mid` is a valid byte offset from the start /// of the string and falls on the boundary of a UTF-8 code point. - const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut str, &mut str) { + #[inline] + #[must_use] + #[unstable(feature = "str_split_at_unchecked", issue = "165545")] + pub const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut str, &mut str) { let len = self.len(); let ptr = self.as_mut_ptr(); // SAFETY: caller guarantees `mid` is on a char boundary. diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 7a4a7049533ce..8c35988c07dcb 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1096,7 +1096,8 @@ impl OsStr { /// /// Any caller must ensure `mid` is within bounds and lies on /// a valid `OsStr` boundary for the platform. - unsafe fn split_at_unchecked(&self, mid: usize) -> (&OsStr, &OsStr) { + #[unstable(feature = "str_split_at_unchecked", issue = "165545")] + pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&OsStr, &OsStr) { // SAFETY: it's up to the caller to ensure this is safe. unsafe { let (first, second) = self.as_encoded_bytes().split_at_unchecked(mid); From 1b7f5809469d29c279892501383330e5ee32558e Mon Sep 17 00:00:00 2001 From: Samuel Bronson Date: Fri, 6 Nov 2026 13:20:07 -0500 Subject: [PATCH 16/27] fix: Remove confusing self-links from Diag docs I became a bit lost when I encountered these links, for example at: It appears that these were caused by commit f6f87798439e2ce7861da761b444fe0978335ed9 ("Reduce capabilities of `Diagnostic`."). Formerly, the docs for with_foo and foo would both link to the docs for foo on an "impl" struct, but that commit moved those methods over to the outer struct and changed the links to point to the original method there, for both the original and with_ variants. This *is* the appropriate target ... except you don't need to go see it when you're already seeing it. It's a bit of a big refactoring moving a bunch of code, so it is understandable that such a small detail wasn't really noticed with all of those method bodies flying around. --- compiler/rustc_errors/src/diagnostic.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 65dc8042fd409..6d60b031dd7c6 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -420,7 +420,6 @@ macro_rules! with_fn { } => { // The original function. $(#[$attrs])* - #[doc = concat!("See [`Diag::", stringify!($f), "()`].")] pub fn $f(&mut $self, $($name: $ty),*) -> &mut Self { $($body)* } From 189e271be2b27f5673d2d95ae7c913923b2a145d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 11:35:58 +0100 Subject: [PATCH 17/27] do not rebuild prebuilt rustc-perf right now, an opt-dist run starts with: - clear its opt-artifacts folder - copy a rustc-perf tree there - build the collector So, on every run, the built rustc-perf is deleted and rebuilt, even though there is a "prebuilt rustc-perf" configuration. This commit does not rebuild rustc-perf if there's a prebuilt dir, and returning that as the rustc-perf path to run benchmarks in. --- src/tools/opt-dist/src/environment.rs | 8 ++++++-- src/tools/opt-dist/src/main.rs | 15 ++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index f02f485ffe1f8..79bcbb3ca36e5 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -82,9 +82,13 @@ impl Environment { self.prebuilt_rustc_perf.clone() } - /// Path to the built rustc-perf benchmark suite. + /// Path to the rustc-perf benchmark suite, either built locally, or provided in a prebuilt + /// form. pub fn rustc_perf_dir(&self) -> Utf8PathBuf { - self.artifact_dir.join("rustc-perf") + match &self.prebuilt_rustc_perf { + Some(prebuilt_rustc_perf) => prebuilt_rustc_perf.clone(), + None => self.artifact_dir.join("rustc-perf"), + } } pub fn host_llvm_dir(&self) -> Utf8PathBuf { diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index cd01b41f8c998..d6fe7cfa8c20c 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -228,12 +228,13 @@ fn execute_pipeline( ) -> anyhow::Result<()> { reset_directory(&env.artifact_dir())?; - with_log_group("Building rustc-perf", || { - let rustc_perf_checkout_dir = match env.prebuilt_rustc_perf() { - Some(dir) => dir, - None => env.checkout_path().join("src").join("tools").join("rustc-perf"), - }; - copy_rustc_perf(env, &rustc_perf_checkout_dir) + with_log_group("Building rustc-perf", || match env.prebuilt_rustc_perf() { + Some(_) => Ok(()), + None => { + let rustc_perf_checkout_dir = + env.checkout_path().join("src").join("tools").join("rustc-perf"); + copy_and_build_rustc_perf(env, &rustc_perf_checkout_dir) + } })?; let optimize_clippy = !is_fast_try_build(); @@ -564,7 +565,7 @@ fn main() -> anyhow::Result<()> { } // Copy rustc-perf from the given path into the environment and build it. -fn copy_rustc_perf(env: &Environment, dir: &Utf8Path) -> anyhow::Result<()> { +fn copy_and_build_rustc_perf(env: &Environment, dir: &Utf8Path) -> anyhow::Result<()> { copy_directory(dir, &env.rustc_perf_dir())?; build_rustc_perf(env) } From 272aab3405e86d1d3455ee9cf4a13c733301b8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 14:06:08 +0100 Subject: [PATCH 18/27] make optimizing rustdoc optional Local runs are usually more concerned about optimizing the compiler, so optimizing rustdoc is off by default for these, but it still is on by default otherwise, to keep optimizing it on CI as we do today. --- src/tools/opt-dist/src/environment.rs | 5 ++++ src/tools/opt-dist/src/main.rs | 39 +++++++++++++++++++-------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index 79bcbb3ca36e5..2f3ea33e2eb1e 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -30,6 +30,11 @@ pub struct Environment { build_llvm: bool, #[builder(default)] stage0_root: Option, + + /// Whether we want to optimize rustdoc. We do on CI, so it's on by default, but it is an option + /// so local runs can avoid it. + #[builder(default = "true")] + pub(crate) optimize_rustdoc: bool, } impl Environment { diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index d6fe7cfa8c20c..6a3babaeeb389 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -111,6 +111,11 @@ enum EnvironmentCmd { /// Path to custom stage0 root #[arg(long)] stage0_root: Option, + + /// Do we want to optimize rustdoc in this run? Locally it's unlikely, so the default is not + /// to do it. + #[arg(long, default_value_t = false, action(clap::ArgAction::Set))] + optimize_rustdoc: bool, }, /// Perform an optimized build on Linux CI, from inside Docker. LinuxCi { @@ -149,6 +154,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> build_llvm, build_dir, stage0_root, + optimize_rustdoc, } => { let env = EnvironmentBuilder::default() .host_tuple(target_triple) @@ -166,6 +172,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .fast_try_build(is_fast_try_build) .build_llvm(build_llvm) .stage0_root(stage0_root) + .optimize_rustdoc(optimize_rustdoc) .build()?; (env, shared.build_args) @@ -239,6 +246,7 @@ fn execute_pipeline( let optimize_clippy = !is_fast_try_build(); let optimize_cranelift = !is_fast_try_build(); + let optimize_rustdoc = env.optimize_rustdoc; // Stage 1: Build PGO instrumented rustc // We use a normal build of LLVM, because gathering PGO profiles for LLVM and `rustc` at the @@ -252,11 +260,12 @@ fn execute_pipeline( // they are executed together within a single rustc-perf invocation. // Their profiles are then merged together into a single PGO profile. let mut builder = Bootstrap::build(env) - .with_rustdoc() .with_cargo() .rustc_pgo_instrument(&rustc_profile_dir_root) - .cargo_pgo_instrument(&rustc_profile_dir_root) - .rustdoc_pgo_instrument(&rustc_profile_dir_root); + .cargo_pgo_instrument(&rustc_profile_dir_root); + if optimize_rustdoc { + builder = builder.with_rustdoc().rustdoc_pgo_instrument(&rustc_profile_dir_root) + } if optimize_clippy { builder = builder.with_clippy().clippy_pgo_instrument(&rustc_profile_dir_root); } @@ -279,9 +288,14 @@ fn execute_pipeline( let rustc_profile = stage.section("Gather rustc profiles", |_| { gather_rustc_profiles(env, &rustc_profile_dir_root) })?; - let rustdoc_profile = stage.section("Gather rustdoc profiles", |_| { - gather_rustdoc_profiles(env, &rustc_profile_dir_root) - })?; + let rustdoc_profile = if optimize_rustdoc { + stage.section("Gather rustdoc profiles", |_| { + Ok(Some(gather_rustdoc_profiles(env, &rustc_profile_dir_root)?)) + })? + } else { + None + }; + let clippy_profile = if optimize_clippy { stage.section("Gather clippy profiles", |_| { Ok(Some(gather_clippy_profiles(env, &rustc_profile_dir_root)?)) @@ -300,11 +314,12 @@ fn execute_pipeline( stage.section("Build PGO optimized rustc", |section| { let mut cmd = Bootstrap::build(env) - .with_rustdoc() .with_cargo() .rustc_pgo_optimize(&rustc_profile) - .cargo_pgo_optimize(&rustc_profile) - .rustdoc_pgo_optimize(&rustdoc_profile); + .cargo_pgo_optimize(&rustc_profile); + if let Some(rustdoc_profile) = rustdoc_profile.as_ref() { + cmd = cmd.with_rustdoc().rustdoc_pgo_optimize(rustdoc_profile); + } if let Some(clippy_profile) = clippy_profile.as_ref() { cmd = cmd.with_clippy().clippy_pgo_optimize(clippy_profile); } @@ -452,8 +467,10 @@ fn execute_pipeline( let mut dist = Bootstrap::dist(env, &dist_args) .llvm_pgo_optimize(llvm_pgo_profile.as_ref()) .rustc_pgo_optimize(&rustc_pgo_profile) - .cargo_pgo_optimize(&rustc_pgo_profile) - .rustdoc_pgo_optimize(&rustdoc_pgo_profile); + .cargo_pgo_optimize(&rustc_pgo_profile); + if let Some(rustdoc_pgo_profile) = rustdoc_pgo_profile { + dist = dist.rustdoc_pgo_optimize(&rustdoc_pgo_profile); + } if let Some(clippy_pgo_profile) = clippy_pgo_profile { dist = dist.clippy_pgo_optimize(&clippy_pgo_profile); } From dcf98ccc72cc16727a89131b7c88053327c6c8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 14:53:29 +0100 Subject: [PATCH 19/27] make optimizing cranelift and clippy overridable on the CLI Make optimizing cranelift and clippy off by default for local runs. --- src/tools/opt-dist/src/environment.rs | 10 ++++++++++ src/tools/opt-dist/src/main.rs | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index 2f3ea33e2eb1e..786b3f815bf8c 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -31,6 +31,16 @@ pub struct Environment { #[builder(default)] stage0_root: Option, + /// Whether we want to optimize clippy. We do on CI, so it's on by default, but it is an option + /// so local runs can avoid it. + #[builder(default = "true")] + pub(crate) optimize_clippy: bool, + + /// Whether we want to optimize the cranelift backend. We do on CI, so it's on by default, but + /// it is an option so local runs can avoid it. + #[builder(default = "true")] + pub(crate) optimize_cranelift: bool, + /// Whether we want to optimize rustdoc. We do on CI, so it's on by default, but it is an option /// so local runs can avoid it. #[builder(default = "true")] diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 6a3babaeeb389..e8e440eb4de8b 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -112,6 +112,16 @@ enum EnvironmentCmd { #[arg(long)] stage0_root: Option, + /// Do we want to optimize clippy in this run? Locally it's unlikely, so the default is not + /// to do it. + #[arg(long, default_value_t = false, action(clap::ArgAction::Set))] + optimize_clippy: bool, + + /// Do we want to optimize the cranelift backend in this run? Locally it's unlikely, so the + /// default is not to do it. + #[arg(long, default_value_t = false, action(clap::ArgAction::Set))] + optimize_cranelift: bool, + /// Do we want to optimize rustdoc in this run? Locally it's unlikely, so the default is not /// to do it. #[arg(long, default_value_t = false, action(clap::ArgAction::Set))] @@ -154,6 +164,8 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> build_llvm, build_dir, stage0_root, + optimize_clippy, + optimize_cranelift, optimize_rustdoc, } => { let env = EnvironmentBuilder::default() @@ -172,6 +184,8 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .fast_try_build(is_fast_try_build) .build_llvm(build_llvm) .stage0_root(stage0_root) + .optimize_clippy(optimize_clippy) + .optimize_cranelift(optimize_cranelift) .optimize_rustdoc(optimize_rustdoc) .build()?; @@ -244,8 +258,8 @@ fn execute_pipeline( } })?; - let optimize_clippy = !is_fast_try_build(); - let optimize_cranelift = !is_fast_try_build(); + let optimize_clippy = !is_fast_try_build() && env.optimize_clippy; + let optimize_cranelift = !is_fast_try_build() && env.optimize_cranelift; let optimize_rustdoc = env.optimize_rustdoc; // Stage 1: Build PGO instrumented rustc From 4b13f0283b678b2081ee785baa08b08080c3e67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 14:59:57 +0100 Subject: [PATCH 20/27] make optimizing cargo optional The default is still on for CI, because we optimize by default, but off for local runs. --- src/tools/opt-dist/src/environment.rs | 5 +++++ src/tools/opt-dist/src/main.rs | 31 ++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index 786b3f815bf8c..5aeae30e0e3d8 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -31,6 +31,11 @@ pub struct Environment { #[builder(default)] stage0_root: Option, + /// Whether we want to optimize cargo. We do on CI, so it's on by default, but it is an option + /// so local runs can avoid it. + #[builder(default = "true")] + pub(crate) optimize_cargo: bool, + /// Whether we want to optimize clippy. We do on CI, so it's on by default, but it is an option /// so local runs can avoid it. #[builder(default = "true")] diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index e8e440eb4de8b..2c8144f89335f 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -112,6 +112,11 @@ enum EnvironmentCmd { #[arg(long)] stage0_root: Option, + /// Do we want to optimize cargo in this run? Locally it's unlikely, so the default is not + /// to do it. + #[arg(long, default_value_t = false, action(clap::ArgAction::Set))] + optimize_cargo: bool, + /// Do we want to optimize clippy in this run? Locally it's unlikely, so the default is not /// to do it. #[arg(long, default_value_t = false, action(clap::ArgAction::Set))] @@ -164,6 +169,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> build_llvm, build_dir, stage0_root, + optimize_cargo, optimize_clippy, optimize_cranelift, optimize_rustdoc, @@ -184,6 +190,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .fast_try_build(is_fast_try_build) .build_llvm(build_llvm) .stage0_root(stage0_root) + .optimize_cargo(optimize_cargo) .optimize_clippy(optimize_clippy) .optimize_cranelift(optimize_cranelift) .optimize_rustdoc(optimize_rustdoc) @@ -258,6 +265,7 @@ fn execute_pipeline( } })?; + let optimize_cargo = env.optimize_cargo; let optimize_clippy = !is_fast_try_build() && env.optimize_clippy; let optimize_cranelift = !is_fast_try_build() && env.optimize_cranelift; let optimize_rustdoc = env.optimize_rustdoc; @@ -273,10 +281,11 @@ fn execute_pipeline( // Rustc and rustdoc profiles are gathered together into the same directory, because // they are executed together within a single rustc-perf invocation. // Their profiles are then merged together into a single PGO profile. - let mut builder = Bootstrap::build(env) - .with_cargo() - .rustc_pgo_instrument(&rustc_profile_dir_root) - .cargo_pgo_instrument(&rustc_profile_dir_root); + let mut builder = + Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root); + if optimize_cargo { + builder = builder.with_cargo().cargo_pgo_instrument(&rustc_profile_dir_root) + } if optimize_rustdoc { builder = builder.with_rustdoc().rustdoc_pgo_instrument(&rustc_profile_dir_root) } @@ -327,10 +336,10 @@ fn execute_pipeline( print_free_disk_space()?; stage.section("Build PGO optimized rustc", |section| { - let mut cmd = Bootstrap::build(env) - .with_cargo() - .rustc_pgo_optimize(&rustc_profile) - .cargo_pgo_optimize(&rustc_profile); + let mut cmd = Bootstrap::build(env).rustc_pgo_optimize(&rustc_profile); + if optimize_cargo { + cmd = cmd.with_cargo().cargo_pgo_optimize(&rustc_profile); + } if let Some(rustdoc_profile) = rustdoc_profile.as_ref() { cmd = cmd.with_rustdoc().rustdoc_pgo_optimize(rustdoc_profile); } @@ -480,8 +489,10 @@ fn execute_pipeline( let mut dist = Bootstrap::dist(env, &dist_args) .llvm_pgo_optimize(llvm_pgo_profile.as_ref()) - .rustc_pgo_optimize(&rustc_pgo_profile) - .cargo_pgo_optimize(&rustc_pgo_profile); + .rustc_pgo_optimize(&rustc_pgo_profile); + if optimize_cargo { + dist = dist.cargo_pgo_optimize(&rustc_pgo_profile); + } if let Some(rustdoc_pgo_profile) = rustdoc_pgo_profile { dist = dist.rustdoc_pgo_optimize(&rustdoc_pgo_profile); } From 785cf3fbe023cf83eef4021cd1ff81406722a477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 15:30:08 +0100 Subject: [PATCH 21/27] improve a few comments --- src/tools/opt-dist/src/main.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 2c8144f89335f..650ae468e7edb 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -99,7 +99,7 @@ enum EnvironmentCmd { #[arg(long)] run_tests: bool, - /// Will be LLVM built during the run? + /// Will LLVM be built during the run? #[arg(long, default_value_t = true, action(clap::ArgAction::Set))] build_llvm: bool, @@ -270,14 +270,14 @@ fn execute_pipeline( let optimize_cranelift = !is_fast_try_build() && env.optimize_cranelift; let optimize_rustdoc = env.optimize_rustdoc; - // Stage 1: Build PGO instrumented rustc + // Stage 1: Build PGO-instrumented rustc // We use a normal build of LLVM, because gathering PGO profiles for LLVM and `rustc` at the // same time can cause issues, because the host and in-tree LLVM versions can diverge. let (rustc_pgo_profile, rustdoc_pgo_profile, clippy_pgo_profile, cranelift_pgo_profile) = timer .section("Stage 1 (Rustc + rustdoc + cargo + clippy PGO)", |stage| { let rustc_profile_dir_root = env.artifact_dir().join("rustc-pgo"); - stage.section("Build PGO instrumented rustc and LLVM", |section| { + stage.section("Build PGO-instrumented rustc, and vanilla LLVM", |section| { // Rustc and rustdoc profiles are gathered together into the same directory, because // they are executed together within a single rustc-perf invocation. // Their profiles are then merged together into a single PGO profile. @@ -335,7 +335,7 @@ fn execute_pipeline( }; print_free_disk_space()?; - stage.section("Build PGO optimized rustc", |section| { + stage.section("Build PGO-optimized rustc", |section| { let mut cmd = Bootstrap::build(env).rustc_pgo_optimize(&rustc_profile); if optimize_cargo { cmd = cmd.with_cargo().cargo_pgo_optimize(&rustc_profile); @@ -360,7 +360,7 @@ fn execute_pipeline( })?; // Stage 2: Gather LLVM PGO profiles - // Here we build a PGO instrumented LLVM, reusing the previously PGO optimized rustc. + // Here we build a PGO-instrumented LLVM, reusing the previously PGO-optimized rustc. // Then we use the instrumented LLVM to gather LLVM PGO profiles. let llvm_pgo_profile = if env.build_llvm() { timer.section("Stage 2 (LLVM PGO)", |stage| { @@ -369,7 +369,7 @@ fn execute_pipeline( let llvm_profile_dir_root = env.artifact_dir().join("llvm-pgo"); - stage.section("Build PGO instrumented LLVM", |section| { + stage.section("Build PGO-instrumented LLVM", |section| { Bootstrap::build(env) .llvm_pgo_instrument(&llvm_profile_dir_root) .avoid_rustc_rebuild() @@ -394,14 +394,14 @@ fn execute_pipeline( let bolt_profiles = if env.use_bolt() { // Stage 3: Build BOLT instrumented LLVM - // We build a PGO optimized LLVM in this step, then instrument it with BOLT and gather BOLT profiles. + // We build a PGO-optimized LLVM in this step, then instrument it with BOLT and gather BOLT profiles. // Note that we don't remove LLVM artifacts after this step, so that they are reused in the final dist build. // BOLT instrumentation is performed "on-the-fly" when the LLVM library is copied to the sysroot of rustc, // therefore the LLVM artifacts on disk are not "tainted" with BOLT instrumentation and they can be reused. let libdir = env.build_artifacts().join("stage2").join("lib"); timer.section("Stage 3 (BOLT)", |stage| { let llvm_data = if env.build_llvm() { - stage.section("Build PGO optimized LLVM", |stage| { + stage.section("Build PGO-optimized LLVM", |stage| { Bootstrap::build(env) .with_llvm_bolt_ldflags() .llvm_pgo_optimize(llvm_pgo_profile.as_ref()) @@ -503,7 +503,7 @@ fn execute_pipeline( dist = dist.cranelift_pgo_optimize(&cranelift_pgo_profile); } - // if LLVM is not built we'll have PGO optimized rustc + // if LLVM is not built we'll have PGO-optimized rustc dist = if env.supports_shared_llvm() || !env.build_llvm() { dist.avoid_rustc_rebuild() } else { @@ -515,7 +515,7 @@ fn execute_pipeline( } // Final stage: Assemble the dist artifacts - // The previous PGO optimized rustc build and PGO optimized LLVM builds should be reused. + // The previous PGO-optimized rustc build and PGO-optimized LLVM builds should be reused. timer.section("Stage 5 (final build)", |stage| dist.run(stage))?; // After dist has finished, run a subset of the test suite on the optimized artifacts to discover From efa477c251d0d3d7f9de5605be31b36a0bc3a850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 15:40:09 +0100 Subject: [PATCH 22/27] fix comment --- src/tools/opt-dist/src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 650ae468e7edb..0e8bcece05e4e 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -278,9 +278,12 @@ fn execute_pipeline( let rustc_profile_dir_root = env.artifact_dir().join("rustc-pgo"); stage.section("Build PGO-instrumented rustc, and vanilla LLVM", |section| { - // Rustc and rustdoc profiles are gathered together into the same directory, because - // they are executed together within a single rustc-perf invocation. - // Their profiles are then merged together into a single PGO profile. + // Note that we gather the profiles into the same directory: + // - we want the profiles of all the binaries using librustc_driver to optimize the + // driver according to the global use of rustc code + // - the profiles for the tool binaries themselves will be about different symbols + // and thus will not collide when merged + // The profiles are then merged together into a single PGO profile. let mut builder = Bootstrap::build(env).rustc_pgo_instrument(&rustc_profile_dir_root); if optimize_cargo { From 5cd5686ec39aad5d7480e516c1aaeb7a59b67b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 6 Nov 2026 15:55:26 +0100 Subject: [PATCH 23/27] make label for components that are actually optimized --- src/tools/opt-dist/src/main.rs | 40 ++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 0e8bcece05e4e..484ad09c58f8f 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -273,8 +273,17 @@ fn execute_pipeline( // Stage 1: Build PGO-instrumented rustc // We use a normal build of LLVM, because gathering PGO profiles for LLVM and `rustc` at the // same time can cause issues, because the host and in-tree LLVM versions can diverge. + let stage1_label = format!( + "Stage 1 ({} PGO)", + optimized_component_label( + optimize_rustdoc, + optimize_cargo, + optimize_clippy, + optimize_cranelift, + ) + ); let (rustc_pgo_profile, rustdoc_pgo_profile, clippy_pgo_profile, cranelift_pgo_profile) = timer - .section("Stage 1 (Rustc + rustdoc + cargo + clippy PGO)", |stage| { + .section(&stage1_label, |stage| { let rustc_profile_dir_root = env.artifact_dir().join("rustc-pgo"); stage.section("Build PGO-instrumented rustc, and vanilla LLVM", |section| { @@ -338,7 +347,16 @@ fn execute_pipeline( }; print_free_disk_space()?; - stage.section("Build PGO-optimized rustc", |section| { + let section_label = format!( + "Build PGO-optimized {}", + optimized_component_label( + rustdoc_profile.is_some(), + optimize_cargo, + clippy_profile.is_some(), + cranelift_profile.is_some(), + ) + ); + stage.section(§ion_label, |section| { let mut cmd = Bootstrap::build(env).rustc_pgo_optimize(&rustc_profile); if optimize_cargo { cmd = cmd.with_cargo().cargo_pgo_optimize(&rustc_profile); @@ -531,6 +549,24 @@ fn execute_pipeline( Ok(()) } +/// Compute a label of the components that will be optimized, in addition to rustc. +fn optimized_component_label(rustdoc: bool, cargo: bool, clippy: bool, cranelift: bool) -> String { + let mut label = String::from("rustc"); + if rustdoc { + label.push_str(" + rustdoc"); + } + if cargo { + label.push_str(" + cargo"); + } + if clippy { + label.push_str(" + clippy"); + } + if cranelift { + label.push_str(" + cranelift"); + } + label +} + fn main() -> anyhow::Result<()> { // Make sure that we get backtraces for easier debugging in CI unsafe { From 7f8f89f35cfa971a958e3cb3c05cb7fa8e622352 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Fri, 6 Nov 2026 23:05:26 +0100 Subject: [PATCH 24/27] fix `-Zvirtual-function-elimination` error message At least for now, only `lto=fat` is supported --- compiler/rustc_session/src/diagnostics.rs | 2 +- .../basic.rs} | 0 .../invalid-lto.lto_missing.stderr | 4 ++++ .../invalid-lto.lto_no.stderr | 4 ++++ .../invalid-lto.lto_thin.stderr | 4 ++++ .../codegen/virtual-function-elimination/invalid-lto.rs | 9 +++++++++ 6 files changed, 22 insertions(+), 1 deletion(-) rename tests/ui/codegen/{virtual-function-elimination.rs => virtual-function-elimination/basic.rs} (100%) create mode 100644 tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_missing.stderr create mode 100644 tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_no.stderr create mode 100644 tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_thin.stderr create mode 100644 tests/ui/codegen/virtual-function-elimination/invalid-lto.rs diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index e673435dae396..53a0fde70b089 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -363,7 +363,7 @@ pub(crate) struct SanitizerKcfiRequiresPanicAbort; pub(crate) struct SplitLtoUnitRequiresLto; #[derive(Diagnostic)] -#[diag("`-Zvirtual-function-elimination` requires `-Clto`")] +#[diag("`-Zvirtual-function-elimination` requires `-Clto=fat`")] pub(crate) struct UnstableVirtualFunctionElimination; #[derive(Diagnostic)] diff --git a/tests/ui/codegen/virtual-function-elimination.rs b/tests/ui/codegen/virtual-function-elimination/basic.rs similarity index 100% rename from tests/ui/codegen/virtual-function-elimination.rs rename to tests/ui/codegen/virtual-function-elimination/basic.rs diff --git a/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_missing.stderr b/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_missing.stderr new file mode 100644 index 0000000000000..f4f5667716d80 --- /dev/null +++ b/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_missing.stderr @@ -0,0 +1,4 @@ +error: `-Zvirtual-function-elimination` requires `-Clto=fat` + +error: aborting due to 1 previous error + diff --git a/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_no.stderr b/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_no.stderr new file mode 100644 index 0000000000000..f4f5667716d80 --- /dev/null +++ b/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_no.stderr @@ -0,0 +1,4 @@ +error: `-Zvirtual-function-elimination` requires `-Clto=fat` + +error: aborting due to 1 previous error + diff --git a/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_thin.stderr b/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_thin.stderr new file mode 100644 index 0000000000000..f4f5667716d80 --- /dev/null +++ b/tests/ui/codegen/virtual-function-elimination/invalid-lto.lto_thin.stderr @@ -0,0 +1,4 @@ +error: `-Zvirtual-function-elimination` requires `-Clto=fat` + +error: aborting due to 1 previous error + diff --git a/tests/ui/codegen/virtual-function-elimination/invalid-lto.rs b/tests/ui/codegen/virtual-function-elimination/invalid-lto.rs new file mode 100644 index 0000000000000..ab52388acce30 --- /dev/null +++ b/tests/ui/codegen/virtual-function-elimination/invalid-lto.rs @@ -0,0 +1,9 @@ +//@ revisions: lto_missing lto_no lto_thin +//@[lto_missing] compile-flags: -Zvirtual-function-elimination +//@[lto_no] compile-flags: -Zvirtual-function-elimination -Clto=no +//@[lto_thin] compile-flags: -Zvirtual-function-elimination -Clto=thin +//@ no-prefer-dynamic +//@ ignore-backends: gcc +#![crate_type = "staticlib"] + +//~? ERROR `-Zvirtual-function-elimination` requires `-Clto=fat` From f71d60d4c151ec8bb2bc683fd71ad574716a2058 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sat, 7 Nov 2026 07:29:36 +0900 Subject: [PATCH 25/27] test mutable move-expression captures --- tests/ui/move-expr/async-blocks.rs | 22 +++++++++++++++ tests/ui/move-expr/async-closures.rs | 22 +++++++++++++++ tests/ui/move-expr/gen-blocks.rs | 17 ++++++++++++ tests/ui/move-expr/nested-move-expr.rs | 14 ++++++++++ tests/ui/move-expr/plain-closure.rs | 38 ++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) diff --git a/tests/ui/move-expr/async-blocks.rs b/tests/ui/move-expr/async-blocks.rs index 4f211cc961572..0935bafe1b49c 100644 --- a/tests/ui/move-expr/async-blocks.rs +++ b/tests/ui/move-expr/async-blocks.rs @@ -1,6 +1,8 @@ //@ edition: 2021 //@ run-pass +// This needs to remain a run-pass test to check capture behavior at runtime. #![allow(incomplete_features)] +#![deny(unused_mut)] #![feature(move_expr)] use std::cell::Cell; @@ -74,4 +76,24 @@ fn main() { assert_eq!(Arc::strong_count(&z), 2); drop(fut); assert_eq!(Arc::strong_count(&z), 1); + + let data = vec![1]; + let future = async { + let data = &mut move(data); + data.push(2); + let mut pending = true; + std::future::poll_fn(|cx| { + if pending { + pending = false; + cx.waker().wake_by_ref(); + Poll::Pending + } else { + Poll::Ready(()) + } + }) + .await; + data.push(3); + data.len() + }; + assert_eq!(block_on(future), 3); } diff --git a/tests/ui/move-expr/async-closures.rs b/tests/ui/move-expr/async-closures.rs index b467248048367..a3dd2af8bfeb7 100644 --- a/tests/ui/move-expr/async-closures.rs +++ b/tests/ui/move-expr/async-closures.rs @@ -1,6 +1,8 @@ //@ edition: 2021 //@ run-pass +// This needs to remain a run-pass test to check capture behavior at runtime. #![allow(incomplete_features)] +#![deny(unused_mut)] #![feature(move_expr)] use std::cell::Cell; @@ -56,4 +58,24 @@ fn main() { (moved, b.len()) }; assert_eq!(block_on(call_once(c)), (String::from("a"), 3)); + + let data = vec![1]; + let mut f = async || { + let data = &mut move(data); + data.push(2); + let mut pending = true; + std::future::poll_fn(|cx| { + if pending { + pending = false; + cx.waker().wake_by_ref(); + Poll::Pending + } else { + Poll::Ready(()) + } + }) + .await; + data.len() + }; + assert_eq!(block_on(f()), 2); + assert_eq!(block_on(f()), 3); } diff --git a/tests/ui/move-expr/gen-blocks.rs b/tests/ui/move-expr/gen-blocks.rs index b38313b83a8f7..5d0555fd2bb16 100644 --- a/tests/ui/move-expr/gen-blocks.rs +++ b/tests/ui/move-expr/gen-blocks.rs @@ -1,6 +1,8 @@ //@ edition: 2024 //@ run-pass +// This needs to remain a run-pass test to check capture behavior at runtime. #![allow(incomplete_features)] +#![deny(unused_mut)] #![feature(gen_blocks, move_expr)] use std::cell::Cell; @@ -59,4 +61,19 @@ fn main() { assert_eq!(iter.next(), Some(2)); drop(iter); assert_eq!(Arc::strong_count(&z), 1); + + let data = vec![1]; + let mut iter = gen { + for _ in 0..2 { + let len = { + let data = &mut move(data); + data.push(2); + data.len() + }; + yield len; + } + }; + assert_eq!(iter.next(), Some(2)); + assert_eq!(iter.next(), Some(3)); + assert_eq!(iter.next(), None); } diff --git a/tests/ui/move-expr/nested-move-expr.rs b/tests/ui/move-expr/nested-move-expr.rs index b6e0f70b355d7..2e94fd10a0b04 100644 --- a/tests/ui/move-expr/nested-move-expr.rs +++ b/tests/ui/move-expr/nested-move-expr.rs @@ -1,5 +1,7 @@ //@ run-pass +// This needs to remain a run-pass test to check capture behavior at runtime. #![allow(incomplete_features)] +#![deny(unused_mut)] #![feature(move_expr)] use std::sync::Arc; @@ -18,4 +20,16 @@ fn main() { assert_eq!(Arc::strong_count(&v), 1); println!("{v}"); + + let data = vec![1]; + let f = || { + let mut inner = || { + let data = &mut move(move(data)); + data.push(2); + data.len() + }; + assert_eq!(inner(), 2); + assert_eq!(inner(), 3); + }; + f(); } diff --git a/tests/ui/move-expr/plain-closure.rs b/tests/ui/move-expr/plain-closure.rs index 3f58142f7ea9c..4c139dcf5876f 100644 --- a/tests/ui/move-expr/plain-closure.rs +++ b/tests/ui/move-expr/plain-closure.rs @@ -1,5 +1,7 @@ //@ run-pass +// This needs to remain a run-pass test to check capture behavior at runtime. #![allow(incomplete_features)] +#![deny(unused_mut)] #![feature(move_expr)] use std::cell::Cell; @@ -33,4 +35,40 @@ fn main() { println!("{} {}", x, y); }; c(); + + let data = vec![1]; + let mut f = || { + let data = &mut move(data); + data.push(2); + data.len() + }; + assert_eq!(f(), 2); + assert_eq!(f(), 3); + + let mut f = || { + let data = &mut move(Vec::::new()); + data.push(1); + data.len() + }; + assert_eq!(f(), 1); + assert_eq!(f(), 2); + + let mut f = || move(0) += 1; + f(); + + let mut f = || move(String::new()) = String::from("updated"); + f(); + f(); + + let data = String::from("raw"); + let mut f = || { + let _ = &raw mut move(data); + }; + f(); + f(); + + let data = String::from("hello"); + let f = || (&move(data)).len(); + assert_eq!(f(), 5); + assert_eq!(f(), 5); } From ce706c10b18e5f0ce1b605be64fba8021857d364 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sat, 7 Nov 2026 07:29:58 +0900 Subject: [PATCH 26/27] make move-expression capture temporaries mutable --- compiler/rustc_ast_lowering/src/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 470813615ae0b..26e3f88614efc 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -137,7 +137,7 @@ impl<'hir> LoweringContext<'_, 'hir> { .and_then(|state| state.as_ref()) .map_or(0, |state| state.occurrences.len()); let ident = Ident::from_str_and_span(&format!("__move_expr_{index}"), move_kw_span); - let (pat, binding) = self.pat_ident(inner.span, ident); + let (pat, binding) = self.pat_ident_binding_mode(inner.span, ident, hir::BindingMode::MUT); let Some(state) = self.move_expr_bindings.last_mut().and_then(|state| state.as_mut()) else { span_bug!(move_kw_span, "`move(...)` lowered without a closure-like body state"); @@ -188,7 +188,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // Evaluate the expression inside `move(...)` before creating the // closure/coroutine and store it in a synthetic local: // `|| move(foo).bar` becomes roughly - // `let __move_expr_0 = foo; || __move_expr_0.bar`. + // `let mut __move_expr_0 = foo; || __move_expr_0.bar`. let expr = initializers[&occurrence.id]; // This state has already been popped, so a nested `move(...)` in // the initializer is recorded by the immediately enclosing From 23486d45956580c484b6ddce2cb70f029e9426db Mon Sep 17 00:00:00 2001 From: yhx-12243 Date: Sat, 7 Nov 2026 10:32:28 +0800 Subject: [PATCH 27/27] feat: add ub check --- library/core/src/str/mod.rs | 14 ++++++++++++++ library/std/src/ffi/os_str.rs | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 41f624c892859..01c93465ca251 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -1002,6 +1002,13 @@ impl str { pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&str, &str) { let len = self.len(); let ptr = self.as_ptr(); + + assert_unsafe_precondition!( + check_library_ub, + "str::split_at_unchecked requires the index to be on a UTF-8 boundary", + (it: &str = self, mid: usize = mid) => it.is_char_boundary(mid), + ); + // SAFETY: caller guarantees `mid` is on a char boundary. unsafe { ( @@ -1023,6 +1030,13 @@ impl str { pub const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut str, &mut str) { let len = self.len(); let ptr = self.as_mut_ptr(); + + assert_unsafe_precondition!( + check_library_ub, + "str::split_at_mut_unchecked requires the index to be on a UTF-8 boundary", + (it: &str = self, mid: usize = mid) => it.is_char_boundary(mid), + ); + // SAFETY: caller guarantees `mid` is on a char boundary. unsafe { ( diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 8c35988c07dcb..0a8d7262748ab 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1098,6 +1098,11 @@ impl OsStr { /// a valid `OsStr` boundary for the platform. #[unstable(feature = "str_split_at_unchecked", issue = "165545")] pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&OsStr, &OsStr) { + debug_assert!( + self.inner.try_check_public_boundary(mid).is_some(), + "OsStr::split_at_unchecked requires the index to be on a valid `OsStr` boundary", + ); + // SAFETY: it's up to the caller to ensure this is safe. unsafe { let (first, second) = self.as_encoded_bytes().split_at_unchecked(mid);