From 98cc20913969e36763f3d0b1ef69e2b2248f0247 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Mon, 2 Nov 2026 17:57:15 +0800 Subject: [PATCH 01/11] Revert "riscv: stabilize 'd' and 'f' target features" Revert on beta to let the fix and the stabilization itself bake for another release cycle. Discussed whether to backport a fix or postpone stabilization in . The call there was to be safer and postpone the stabilization by a release cycle. This reverts commit 430e887aaeeffb6a33e6f3fe699aed7c6a7f1fef, reversing changes made to d9b3213975afe2fec76b6456b8aeba65c6e25a21. --- compiler/rustc_target/src/target_features.rs | 6 +++--- ...i-incompatible-target-feature-flag-enable.riscv.stderr | 8 +++++++- .../abi-incompatible-target-feature-flag-enable.rs | 1 + .../abi-required-target-feature-flag-disable.riscv.stderr | 8 +++++++- .../abi-required-target-feature-flag-disable.rs | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 2ee7dea9f8af3..e8970ea57e822 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -680,9 +680,9 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("a", Stable, &["zaamo", "zalrsc"]), ("b", Stable, &["zba", "zbb", "zbs"]), ("c", Stable, &["zca"]), - ("d", Stable, &["f"]), - ("e", Unstable(sym::riscv_target_feature), &[]), // negative feature! needs special care. - ("f", Stable, &["zicsr"]), + ("d", Unstable(sym::riscv_target_feature), &["f"]), + ("e", Unstable(sym::riscv_target_feature), &[]), + ("f", Unstable(sym::riscv_target_feature), &["zicsr"]), ( "forced-atomics", // Not implied by any CPU model or other feature. diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr index bc40b139095a5..1995f9d993a63 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr +++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr @@ -1,7 +1,13 @@ +warning: unstable feature specified for `-Ctarget-feature`: `d` + | + = note: this feature is not stably supported; its behavior can change in the future + = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #162235 + warning: target feature `d` must be disabled to ensure that the ABI of the current target can be implemented correctly | = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #162235 -warning: 1 warning emitted +warning: 2 warnings emitted diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs index c6b5e15599d8e..c6370f01c47d6 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs +++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs @@ -19,4 +19,5 @@ extern crate minicore; use minicore::*; //~? WARN must be disabled to ensure that the ABI of the current target can be implemented correctly +//[riscv]~? WARN unstable feature specified for `-Ctarget-feature` //[x86]~? WARN use a soft-float target instead diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr index e8a5e98793d10..c4ce26bfef8d3 100644 --- a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr +++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr @@ -1,7 +1,13 @@ +warning: unstable feature specified for `-Ctarget-feature`: `d` + | + = note: this feature is not stably supported; its behavior can change in the future + = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #162235 + warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly | = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #162235 -warning: 1 warning emitted +warning: 2 warnings emitted diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs b/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs index 4faef8d02d673..47b7abd50debb 100644 --- a/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs +++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs @@ -26,4 +26,4 @@ extern crate minicore; use minicore::*; //~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly -//[x86]~? WARN unstable feature specified for `-Ctarget-feature` +//[x86,riscv]~? WARN unstable feature specified for `-Ctarget-feature` From 20b511a8cf411fb64adb601adccd81470e24b2fe Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 12 Oct 2026 12:02:49 +0200 Subject: [PATCH 02/11] Move the creation of `IndividualTestOptions` into the test runner closure to ensure the temporary folder is removed right after the test is done running (cherry picked from commit 2cb8b0b58b7fff1df8b593ab0a70db280f12ddf8) --- src/librustdoc/doctest.rs | 20 +++++++++++----- src/librustdoc/doctest/runner.rs | 2 +- .../rustdoc-doctest-tempdir-cleanup/lib.rs | 18 +++++++++++++++ .../rustdoc-doctest-tempdir-cleanup/rmake.rs | 23 +++++++++++++++++++ tests/rustdoc-ui/issues/issue-98690.rs | 2 ++ tests/rustdoc-ui/issues/issue-98690.stderr | 1 - tests/rustdoc-ui/issues/issue-98690.stdout | 15 ++++++++++++ 7 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 tests/run-make/rustdoc-doctest-tempdir-cleanup/lib.rs create mode 100644 tests/run-make/rustdoc-doctest-tempdir-cleanup/rmake.rs delete mode 100644 tests/rustdoc-ui/issues/issue-98690.stderr create mode 100644 tests/rustdoc-ui/issues/issue-98690.stdout diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 0ecbc5927cf48..3ac1f3d944afb 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -582,7 +582,7 @@ pub(crate) struct RunnableDocTest<'a> { /// In a standalone test this is just the regular test code. full_test_code: String, full_test_line_offset: usize, - test_opts: &'a IndividualTestOptions, + test_opts: IndividualTestOptions, global_opts: &'a GlobalTestOptions, langstr: LangString, line: usize, @@ -1151,8 +1151,6 @@ fn generate_test_desc_and_fn( unused_externs: Arc>>, ) -> test::TestDescAndFn { let target_str = rustdoc_options.target.to_string(); - let rustdoc_test_options = - IndividualTestOptions::new(&rustdoc_options, &test.test_id, scraped_test.path()); debug!("creating test {}: {}", scraped_test.name, scraped_test.text); test::TestDescAndFn { @@ -1177,8 +1175,13 @@ fn generate_test_desc_and_fn( }, #[cfg(bootstrap)] testfn: test::DynTestFn(Box::new(move || { + let rustdoc_test_options = IndividualTestOptions::new( + &rustdoc_options, + &test.test_id, + scraped_test.path(), + ); doctest_run_fn( - &rustdoc_test_options, + rustdoc_test_options, &opts, &test, &scraped_test, @@ -1188,8 +1191,13 @@ fn generate_test_desc_and_fn( })), #[cfg(not(bootstrap))] testfn: test::DynTestFn(Arc::new(move || { + let rustdoc_test_options = IndividualTestOptions::new( + &rustdoc_options, + &test.test_id, + scraped_test.path(), + ); doctest_run_fn( - &rustdoc_test_options, + rustdoc_test_options, &opts, &test, &scraped_test, @@ -1201,7 +1209,7 @@ fn generate_test_desc_and_fn( } fn doctest_run_fn( - test_opts: &IndividualTestOptions, + test_opts: IndividualTestOptions, global_opts: &GlobalTestOptions, doctest: &DocTestBuilder, scraped_test: &ScrapedDocTest, diff --git a/src/librustdoc/doctest/runner.rs b/src/librustdoc/doctest/runner.rs index 43ed48aad95d4..2ec5061bb775d 100644 --- a/src/librustdoc/doctest/runner.rs +++ b/src/librustdoc/doctest/runner.rs @@ -197,7 +197,7 @@ test::test_main(test_args, tests) let runnable_test = RunnableDocTest { full_test_code: format!("{code_prefix}{code}", code = self.output), full_test_line_offset: 0, - test_opts: &test_options, + test_opts: test_options, global_opts: opts, langstr: LangString::default(), line: 0, diff --git a/tests/run-make/rustdoc-doctest-tempdir-cleanup/lib.rs b/tests/run-make/rustdoc-doctest-tempdir-cleanup/lib.rs new file mode 100644 index 0000000000000..a8585bd0bd082 --- /dev/null +++ b/tests/run-make/rustdoc-doctest-tempdir-cleanup/lib.rs @@ -0,0 +1,18 @@ +/// ``` +/// assert!(true); +/// ``` +pub fn a() {} + +/// ``` +/// let count = std::fs::read_dir(std::env::temp_dir()) +/// .unwrap() +/// .filter(|entry| { +/// entry.as_ref().unwrap().file_name().to_str().unwrap().starts_with("rustdoctest") +/// }) +/// .count(); +/// // It's 2 and not one because rustdoc creates a temp dir where it puts the `rustdoc-cfgs` +/// // file which contains the list of flags to be passed down to the doctests. It lives +/// // until all doctests have been run. +/// assert_eq!(count, 2); +/// ``` +pub fn b() {} diff --git a/tests/run-make/rustdoc-doctest-tempdir-cleanup/rmake.rs b/tests/run-make/rustdoc-doctest-tempdir-cleanup/rmake.rs new file mode 100644 index 0000000000000..789002533833c --- /dev/null +++ b/tests/run-make/rustdoc-doctest-tempdir-cleanup/rmake.rs @@ -0,0 +1,23 @@ +// This test ensures that a temporary doctest directory is removed as soon as the doctest +// was run to prevent "No space left on device". To ensure it works, we use a file with two +// doctests, run without the "merged doctests" feature (hence the "2021" edition) with +// one thread to prevent potential concurrent cleanups. +// Regression test for . + +//@ ignore-cross-compile +//@ only-linux + +use run_make_support::{is_windows, path, rfs, rustdoc}; + +fn main() { + let tmp = path("tmp"); + rfs::create_dir(&tmp); + + let mut cmd = rustdoc() + .env("TMPDIR", &tmp) + .input("lib.rs") + .edition("2021") + .arg("--test") + .arg("--test-args=--test-threads=1") + .run(); +} diff --git a/tests/rustdoc-ui/issues/issue-98690.rs b/tests/rustdoc-ui/issues/issue-98690.rs index 01708f3f64d3e..1c7eb844a272a 100644 --- a/tests/rustdoc-ui/issues/issue-98690.rs +++ b/tests/rustdoc-ui/issues/issue-98690.rs @@ -1,6 +1,8 @@ //@ compile-flags: --test --persist-doctests /../../ -Z unstable-options //@ failure-status: 101 //@ only-linux +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ normalize-stdout: ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL" #![crate_name = "foo"] diff --git a/tests/rustdoc-ui/issues/issue-98690.stderr b/tests/rustdoc-ui/issues/issue-98690.stderr deleted file mode 100644 index 47d94f99a4563..0000000000000 --- a/tests/rustdoc-ui/issues/issue-98690.stderr +++ /dev/null @@ -1 +0,0 @@ -Couldn't create directory for doctest executables: Permission denied (os error 13) diff --git a/tests/rustdoc-ui/issues/issue-98690.stdout b/tests/rustdoc-ui/issues/issue-98690.stdout new file mode 100644 index 0000000000000..970583175f18b --- /dev/null +++ b/tests/rustdoc-ui/issues/issue-98690.stdout @@ -0,0 +1,15 @@ + +running 1 test +test $DIR/issue-98690.rs - (line 9) ... FAILED + +failures: + +---- $DIR/issue-98690.rs - (line 9) stdout ---- +Couldn't create directory for doctest executables: Permission denied (os error 13) + + +failures: + $DIR/issue-98690.rs - (line 9) + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + From 17ae61d012af946741b750af8ebfff81b12be81b Mon Sep 17 00:00:00 2001 From: sreekaran Date: Mon, 19 Oct 2026 21:02:18 -0400 Subject: [PATCH 03/11] rustdoc: don't panic on a nested use group with no path prefix (cherry picked from commit b010f7985b7920013f6acf91d50cd697ad817084) --- src/librustdoc/clean/mod.rs | 2 +- .../ice-nested-use-without-prefix-164158.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc-ui/ice-nested-use-without-prefix-164158.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 64c6d46cea355..6e01b60f60ac2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3219,7 +3219,7 @@ fn clean_use_statement<'tcx>( for (tree, hir_id, def_id) in items { let mut segments = path.segments.to_vec(); segments.extend(tree.prefix.segments.iter()); - if segments.last().unwrap().ident.name == kw::SelfLower { + if segments.last().is_some_and(|seg| seg.ident.name == kw::SelfLower) { segments.pop(); } let path = hir::UsePath { diff --git a/tests/rustdoc-ui/ice-nested-use-without-prefix-164158.rs b/tests/rustdoc-ui/ice-nested-use-without-prefix-164158.rs new file mode 100644 index 0000000000000..c16af79f9b706 --- /dev/null +++ b/tests/rustdoc-ui/ice-nested-use-without-prefix-164158.rs @@ -0,0 +1,14 @@ +//@ check-pass +//@ edition: 2021 + +// Regression test for . +// A nested use group with no path in front of it made rustdoc panic. + +use {{}}; + +pub mod inner { + pub struct S; + pub struct T; +} + +pub use {inner::S, {inner::T}}; From aea1171d219e9bfc2dc911ab411abb533a5bb7b8 Mon Sep 17 00:00:00 2001 From: sreekaran Date: Sun, 25 Oct 2026 12:26:09 -0400 Subject: [PATCH 04/11] rustdoc: add edition 2015 nested glob use regression test Cover `mod { use {*}; }` in edition 2015 as requested in review. (cherry picked from commit 71f85a515531799f4d5a93d1538e3a00b38c1bb6) --- .../ice-nested-use-without-prefix-164158-edition2015.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/rustdoc-ui/ice-nested-use-without-prefix-164158-edition2015.rs diff --git a/tests/rustdoc-ui/ice-nested-use-without-prefix-164158-edition2015.rs b/tests/rustdoc-ui/ice-nested-use-without-prefix-164158-edition2015.rs new file mode 100644 index 0000000000000..a539d7998282b --- /dev/null +++ b/tests/rustdoc-ui/ice-nested-use-without-prefix-164158-edition2015.rs @@ -0,0 +1,9 @@ +//@ check-pass +//@ edition: 2015 + +// Regression test for . +// Nested glob use with no path prefix (edition 2015 form from review). + +mod what { + use {*}; +} From 56ccc64194136c75252846829b6313bdd5088b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 28 Oct 2026 12:10:36 +0100 Subject: [PATCH 05/11] add test showing the problem as shown in issue 165055, an unstable use of the `z` modifier should be rejected. That would make this test fail, but it doesn't yet. (cherry picked from commit d9d743eefc22ad5bf26168d435bf0f8a3804413d) --- .../feature-gate-asm_experimental_reg.loongarch.stderr | 8 ++++---- .../ui/feature-gates/feature-gate-asm_experimental_reg.rs | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr index 0f829dd65cb47..80ecc34905df6 100644 --- a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr +++ b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr @@ -1,5 +1,5 @@ error[E0658]: register class `vreg` can only be used as a clobber in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:60:41 + --> $DIR/feature-gate-asm_experimental_reg.rs:67:41 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: register class `vreg` can only be used as a clobber in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:60:54 + --> $DIR/feature-gate-asm_experimental_reg.rs:67:54 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: type `i8x16` cannot be used with this register class in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:60:51 + --> $DIR/feature-gate-asm_experimental_reg.rs:67:51 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^ @@ -29,7 +29,7 @@ LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: type `i8x16` cannot be used with this register class in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:60:63 + --> $DIR/feature-gate-asm_experimental_reg.rs:67:63 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^ diff --git a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs index c91036366a028..80454762b3058 100644 --- a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs +++ b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs @@ -47,6 +47,13 @@ unsafe fn predicate(p: svbool_t) { //[aarch64]~| ERROR type `svbool_t` cannot be used with this register class in stable } +#[cfg(aarch64)] +unsafe fn modifier(x: f64) -> f64 { + let y: f64; + unsafe { asm!("mov {1:z}.d, {0:z}.d", in(vreg) x, out(vreg) y) }; + y +} + #[cfg(loongarch)] #[repr(simd)] pub struct i8x16([i8; 16]); From 5bb2f6b34fbbc594980e664b507de3914a8d14f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 28 Oct 2026 12:37:18 +0100 Subject: [PATCH 06/11] ensure the `z` asm template modifier is gated under `asm_experimental_reg` This also correctly rejects the previous test. The other tests relying on the modifier are changed to enable the feature. (cherry picked from commit 6dc606cded012dc13102a4c1e4a9ff18a11b0f8c) --- compiler/rustc_ast_lowering/src/asm.rs | 3 ++- compiler/rustc_target/src/asm/aarch64.rs | 15 ++++++++++++-- compiler/rustc_target/src/asm/mod.rs | 14 +++++++++---- tests/assembly-llvm/asm/aarch64-modifiers.rs | 2 +- tests/ui/asm/aarch64/bad-reg.stderr | 4 ++-- ...e-gate-asm_experimental_reg.aarch64.stderr | 20 ++++++++++++++++++- ...gate-asm_experimental_reg.loongarch.stderr | 8 ++++---- .../feature-gate-asm_experimental_reg.rs | 2 ++ 8 files changed, 53 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 71bcdb0e27e8f..e7534c058c7f0 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -261,7 +261,8 @@ impl<'hir> LoweringContext<'_, 'hir> { if class == asm::InlineAsmRegClass::Err { continue; } - let valid_modifiers = class.valid_modifiers(asm_arch.unwrap()); + let valid_modifiers = + class.valid_modifiers(asm_arch.unwrap(), allow_experimental_reg); if !valid_modifiers.contains(&modifier) { let sub = if valid_modifiers.is_empty() { InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier { diff --git a/compiler/rustc_target/src/asm/aarch64.rs b/compiler/rustc_target/src/asm/aarch64.rs index 83d249262c104..4136d1a624588 100644 --- a/compiler/rustc_target/src/asm/aarch64.rs +++ b/compiler/rustc_target/src/asm/aarch64.rs @@ -18,10 +18,21 @@ def_reg_class! { } impl AArch64InlineAsmRegClass { - pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] { + pub fn valid_modifiers( + self, + _arch: super::InlineAsmArch, + allow_experimental_reg: bool, + ) -> &'static [char] { match self { Self::reg => &['w', 'x'], - Self::vreg | Self::vreg_low16 => &['b', 'h', 's', 'd', 'q', 'v', 'z'], + Self::vreg | Self::vreg_low16 => { + if allow_experimental_reg { + &['b', 'h', 's', 'd', 'q', 'v', 'z'] + } else { + &['b', 'h', 's', 'd', 'q', 'v'] + } + } + Self::preg | Self::ffr => &[], } } diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 6f9751e807490..500010dc426f4 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -711,13 +711,19 @@ impl InlineAsmRegClass { }) } - /// Returns the list of template modifiers that can be used with this - /// register class. - pub fn valid_modifiers(self, arch: InlineAsmArch) -> &'static [char] { + /// Returns the list of template modifiers that can be used with this register class, as well as + /// whether the `asm_experimental_reg` feature is enabled: there can be template modifiers that + /// apply to currently unstable registers, and we don't want to make these modifiers usable + /// without the feature gate. + pub fn valid_modifiers( + self, + arch: InlineAsmArch, + allow_experimental_reg: bool, + ) -> &'static [char] { match self { Self::X86(r) => r.valid_modifiers(arch), Self::Arm(r) => r.valid_modifiers(arch), - Self::AArch64(r) => r.valid_modifiers(arch), + Self::AArch64(r) => r.valid_modifiers(arch, allow_experimental_reg), Self::Amdgpu(r) => r.valid_modifiers(arch), Self::RiscV(r) => r.valid_modifiers(arch), Self::Nvptx(r) => r.valid_modifiers(arch), diff --git a/tests/assembly-llvm/asm/aarch64-modifiers.rs b/tests/assembly-llvm/asm/aarch64-modifiers.rs index 66be35de574f6..5c68c25a7b902 100644 --- a/tests/assembly-llvm/asm/aarch64-modifiers.rs +++ b/tests/assembly-llvm/asm/aarch64-modifiers.rs @@ -5,7 +5,7 @@ //@ compile-flags: -Zmerge-functions=disabled //@ needs-llvm-components: aarch64 -#![feature(no_core)] +#![feature(asm_experimental_reg, no_core)] #![crate_type = "rlib"] #![no_core] #![allow(asm_sub_register)] diff --git a/tests/ui/asm/aarch64/bad-reg.stderr b/tests/ui/asm/aarch64/bad-reg.stderr index 8937509763dec..14ffdb3e0059f 100644 --- a/tests/ui/asm/aarch64/bad-reg.stderr +++ b/tests/ui/asm/aarch64/bad-reg.stderr @@ -30,7 +30,7 @@ LL | asm!("{:r}", in(vreg) foo); | | | template modifier | - = note: the `vreg` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, `v`, and `z` + = note: the `vreg` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, and `v` error: invalid asm template modifier `r` for this register class --> $DIR/bad-reg.rs:26:15 @@ -40,7 +40,7 @@ LL | asm!("{:r}", in(vreg_low16) foo); | | | template modifier | - = note: the `vreg_low16` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, `v`, and `z` + = note: the `vreg_low16` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, and `v` error: asm template modifiers are not allowed for `const` arguments --> $DIR/bad-reg.rs:28:15 diff --git a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr index f19cb17a04a29..8c26351a9ea89 100644 --- a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr +++ b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr @@ -8,6 +8,24 @@ LL | asm!("/* {0} */", in(preg) p); = help: add `#![feature(asm_experimental_reg)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +error: invalid asm template modifier `z` for this register class + --> $DIR/feature-gate-asm_experimental_reg.rs:53:24 + | +LL | unsafe { asm!("mov {1:z}.d, {0:z}.d", in(vreg) x, out(vreg) y) }; + | ^^^^^ template modifier ----------- argument + | + = note: the `vreg` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, and `v` + +error: invalid asm template modifier `z` for this register class + --> $DIR/feature-gate-asm_experimental_reg.rs:53:33 + | +LL | unsafe { asm!("mov {1:z}.d, {0:z}.d", in(vreg) x, out(vreg) y) }; + | ^^^^^ ---------- argument + | | + | template modifier + | + = note: the `vreg` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, and `v` + error[E0658]: type `svint32_t` cannot be used with this register class in stable --> $DIR/feature-gate-asm_experimental_reg.rs:33:32 | @@ -48,6 +66,6 @@ LL | asm!("/* {0} */", in(preg) p); = help: add `#![feature(asm_experimental_reg)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 5 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr index 80ecc34905df6..0eee8e9af60af 100644 --- a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr +++ b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.loongarch.stderr @@ -1,5 +1,5 @@ error[E0658]: register class `vreg` can only be used as a clobber in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:67:41 + --> $DIR/feature-gate-asm_experimental_reg.rs:69:41 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: register class `vreg` can only be used as a clobber in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:67:54 + --> $DIR/feature-gate-asm_experimental_reg.rs:69:54 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: type `i8x16` cannot be used with this register class in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:67:51 + --> $DIR/feature-gate-asm_experimental_reg.rs:69:51 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^ @@ -29,7 +29,7 @@ LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: type `i8x16` cannot be used with this register class in stable - --> $DIR/feature-gate-asm_experimental_reg.rs:67:63 + --> $DIR/feature-gate-asm_experimental_reg.rs:69:63 | LL | asm!("xvadd.h {1:u}, {0:u}, {0:u}", out(vreg) y, in(vreg) x); | ^ diff --git a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs index 80454762b3058..f6c03e246dc46 100644 --- a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs +++ b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.rs @@ -51,6 +51,8 @@ unsafe fn predicate(p: svbool_t) { unsafe fn modifier(x: f64) -> f64 { let y: f64; unsafe { asm!("mov {1:z}.d, {0:z}.d", in(vreg) x, out(vreg) y) }; + //[aarch64]~^ ERROR invalid asm template modifier `z` for this register class + //[aarch64]~| ERROR invalid asm template modifier `z` for this register class y } From cbb9b4f89661bb8e03e596d0c7db618b5820013e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 28 Oct 2026 15:06:20 +0100 Subject: [PATCH 07/11] introduce unstable template modifier diagnostic variant This improves the error when using the `z` template modifier on stable, pointing towards the expected feature gate to enable it. (cherry picked from commit fd05e392b029aa87705c26cfe671569a19b73b92) --- compiler/rustc_ast_lowering/src/asm.rs | 50 +++++++++++++------ .../rustc_ast_lowering/src/diagnostics.rs | 12 +++++ ...e-gate-asm_experimental_reg.aarch64.stderr | 16 ++++-- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index e7534c058c7f0..92b3f77ce4a56 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -264,22 +264,42 @@ impl<'hir> LoweringContext<'_, 'hir> { let valid_modifiers = class.valid_modifiers(asm_arch.unwrap(), allow_experimental_reg); if !valid_modifiers.contains(&modifier) { - let sub = if valid_modifiers.is_empty() { - InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier { - class_name: class.name(), - } + // First check if the requested modifier is missing from the valid + // values because experimental registers are disabled. + let unstable_modifiers = class.valid_modifiers(asm_arch.unwrap(), true); + if !allow_experimental_reg && unstable_modifiers.contains(&modifier) { + self.tcx.sess.create_feature_err( + InvalidAsmTemplateModifierRegClass { + placeholder_span, + op_span: op_sp, + modifier: modifier.to_string(), + sub: InvalidAsmTemplateModifierRegClassSub::ModifierIsGated { + class_name: class.name(), + feature: sym::asm_experimental_reg, + stable_modifiers: valid_modifiers.to_vec().into(), + all_modifiers: unstable_modifiers.to_vec().into(), + }, + }, + sym::asm_experimental_reg, + ).emit(); } else { - InvalidAsmTemplateModifierRegClassSub::SupportModifier { - class_name: class.name(), - modifiers: valid_modifiers.to_vec().into(), - } - }; - self.dcx().emit_err(InvalidAsmTemplateModifierRegClass { - placeholder_span, - op_span: op_sp, - modifier: modifier.to_string(), - sub, - }); + let sub = if valid_modifiers.is_empty() { + InvalidAsmTemplateModifierRegClassSub::DoesNotSupportModifier { + class_name: class.name(), + } + } else { + InvalidAsmTemplateModifierRegClassSub::SupportModifier { + class_name: class.name(), + modifiers: valid_modifiers.to_vec().into(), + } + }; + self.dcx().emit_err(InvalidAsmTemplateModifierRegClass { + placeholder_span, + op_span: op_sp, + modifier: modifier.to_string(), + sub, + }); + } } } hir::InlineAsmOperand::Const { .. } => { diff --git a/compiler/rustc_ast_lowering/src/diagnostics.rs b/compiler/rustc_ast_lowering/src/diagnostics.rs index 8c298c57040e9..35a787f62858b 100644 --- a/compiler/rustc_ast_lowering/src/diagnostics.rs +++ b/compiler/rustc_ast_lowering/src/diagnostics.rs @@ -266,6 +266,18 @@ pub(crate) enum InvalidAsmTemplateModifierRegClassSub { SupportModifier { class_name: Symbol, modifiers: DiagSymbolList }, #[note("the `{$class_name}` register class does not support template modifiers")] DoesNotSupportModifier { class_name: Symbol }, + + /// Enabling a feature is needed to use the requested modifier. + #[note( + "the `{$class_name}` register class only supports the following template modifiers on stable: {$stable_modifiers}" + )] + #[note("enabling the `{$feature}` feature will allow using: {$all_modifiers}")] + ModifierIsGated { + class_name: Symbol, + feature: Symbol, + stable_modifiers: DiagSymbolList, + all_modifiers: DiagSymbolList, + }, } #[derive(Diagnostic)] diff --git a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr index 8c26351a9ea89..e1ac256ab7a79 100644 --- a/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr +++ b/tests/ui/feature-gates/feature-gate-asm_experimental_reg.aarch64.stderr @@ -8,15 +8,19 @@ LL | asm!("/* {0} */", in(preg) p); = help: add `#![feature(asm_experimental_reg)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: invalid asm template modifier `z` for this register class +error[E0658]: invalid asm template modifier `z` for this register class --> $DIR/feature-gate-asm_experimental_reg.rs:53:24 | LL | unsafe { asm!("mov {1:z}.d, {0:z}.d", in(vreg) x, out(vreg) y) }; | ^^^^^ template modifier ----------- argument | - = note: the `vreg` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, and `v` + = note: the `vreg` register class only supports the following template modifiers on stable: `b`, `h`, `s`, `d`, `q`, and `v` + = note: enabling the `asm_experimental_reg` feature will allow using: `b`, `h`, `s`, `d`, `q`, `v`, and `z` + = note: see issue #133416 for more information + = help: add `#![feature(asm_experimental_reg)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: invalid asm template modifier `z` for this register class +error[E0658]: invalid asm template modifier `z` for this register class --> $DIR/feature-gate-asm_experimental_reg.rs:53:33 | LL | unsafe { asm!("mov {1:z}.d, {0:z}.d", in(vreg) x, out(vreg) y) }; @@ -24,7 +28,11 @@ LL | unsafe { asm!("mov {1:z}.d, {0:z}.d", in(vreg) x, out(vreg) y) }; | | | template modifier | - = note: the `vreg` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, and `v` + = note: the `vreg` register class only supports the following template modifiers on stable: `b`, `h`, `s`, `d`, `q`, and `v` + = note: enabling the `asm_experimental_reg` feature will allow using: `b`, `h`, `s`, `d`, `q`, `v`, and `z` + = note: see issue #133416 for more information + = help: add `#![feature(asm_experimental_reg)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: type `svint32_t` cannot be used with this register class in stable --> $DIR/feature-gate-asm_experimental_reg.rs:33:32 From 7369200662ffeb5a962aca716aea6873f29a7e22 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 29 Oct 2026 13:06:54 +0100 Subject: [PATCH 08/11] Fix ICE in prelude edition lint (cherry picked from commit b1b7ce4fb8f487e681c413b9ede5f5a5555ba6dd) --- .../src/method/prelude_edition_lints.rs | 21 ++++++++----------- .../prelude-migration/nested-use-statement.rs | 19 +++++++++++++++++ .../nested-use-statement.stderr | 16 ++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 tests/ui/rust-2024/prelude-migration/nested-use-statement.rs create mode 100644 tests/ui/rust-2024/prelude-migration/nested-use-statement.stderr diff --git a/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs b/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs index ed61d557385dd..009608d7eee31 100644 --- a/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs +++ b/compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs @@ -1,10 +1,10 @@ use std::fmt::Write; +use hir::HirId; use hir::def_id::DefId; -use hir::{HirId, ItemKind}; use rustc_ast::join_path_idents; use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level}; -use rustc_hir as hir; +use rustc_hir::{self as hir, Node}; use rustc_hir::attrs::lang_items::LangItem; use rustc_lint::{ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER}; use rustc_lint_defs::builtin::{RUST_2021_PRELUDE_COLLISIONS, RUST_2024_PRELUDE_COLLISIONS}; @@ -436,12 +436,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let import_items: Vec<_> = applicable_trait .import_ids .iter() - .map(|&import_id| self.tcx.hir_expect_item(import_id)) + .map(|&import_id| match self.tcx.hir_node_by_def_id(import_id) { + Node::NestedUseTree(tree) => *tree, + Node::Item(it) => it.expect_use(), + node => span_bug!(span, "expected use tree, found {node:#?}"), + }) .collect(); // Find an identifier with which this trait was imported (note that `_` doesn't count). for item in import_items.iter() { - match item.expect_use().kind { + match item.kind { hir::UseKind::Single(ident) => { if ident.name != kw::Underscore { return Some(format!("{}", ident.name)); @@ -454,14 +458,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // All that is left is `_`! We need to use the full path. It doesn't matter which one we // pick, so just take the first one. - match import_items[0].kind { - ItemKind::Use(tree) => { - Some(join_path_idents(tree.prefix.segments.iter().map(|seg| seg.ident))) - } - _ => { - span_bug!(span, "unexpected item kind, expected a use: {:?}", import_items[0].kind); - } - } + Some(join_path_idents(import_items[0].prefix.segments.iter().map(|seg| seg.ident))) } /// Creates a string version of the `expr` that includes explicit adjustments. diff --git a/tests/ui/rust-2024/prelude-migration/nested-use-statement.rs b/tests/ui/rust-2024/prelude-migration/nested-use-statement.rs new file mode 100644 index 0000000000000..9f42d523ddea4 --- /dev/null +++ b/tests/ui/rust-2024/prelude-migration/nested-use-statement.rs @@ -0,0 +1,19 @@ +//! This test used to ICE because the lint did not handle +//! nested use trees in the new HIR representation. + +//@ check-pass + +#[warn(rust_2024_prelude_collisions)] +fn main() { + ().into_future() + //~^ WARN: `into_future` will become ambiguous + //~| WARN: is a hard error in Rust 2024 +} +#[rustfmt::skip] +use future::{IntoFuture}; +mod future { + pub trait IntoFuture { + fn into_future(&self) {} + } + impl IntoFuture for () {} +} diff --git a/tests/ui/rust-2024/prelude-migration/nested-use-statement.stderr b/tests/ui/rust-2024/prelude-migration/nested-use-statement.stderr new file mode 100644 index 0000000000000..af720c2141d73 --- /dev/null +++ b/tests/ui/rust-2024/prelude-migration/nested-use-statement.stderr @@ -0,0 +1,16 @@ +warning: trait method `into_future` will become ambiguous in Rust 2024 + --> $DIR/nested-use-statement.rs:8:5 + | +LL | ().into_future() + | ^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `IntoFuture::into_future(&())` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024! + = note: for more information, see +note: the lint level is defined here + --> $DIR/nested-use-statement.rs:6:8 + | +LL | #[warn(rust_2024_prelude_collisions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + From 91cd9f79304576b5d054a35e30ec42764cd5f83e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 29 Oct 2026 14:22:53 +0100 Subject: [PATCH 09/11] Update LLVM submodule (cherry picked from commit efb9fe53bc40cc95edfcc0870ac7d08181985d5c) --- src/llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-project b/src/llvm-project index f738f3b0ed65c..0a5579eb649d3 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit f738f3b0ed65c01edcb44a504a77edc12a82c319 +Subproject commit 0a5579eb649d3634a9c30ac873300cc2944fa070 From e0d9d65e7cd8e595ef0ce4b44731e1e8b825efa4 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Mon, 2 Nov 2026 09:56:36 +0800 Subject: [PATCH 10/11] Revert "Use saturating arithmetics for `adjust_max_width`" Reverts rust-lang/rustfmt#7152. This reverts commit 677b954590cc0d5e86cb97e7db4e4b5fb6290add, reversing changes made to b4260f44f5d8cd538718b9046eb51baaa1eb8f5e. --- src/tools/rustfmt/src/config/config_type.rs | 10 ++++------ src/tools/rustfmt/src/config/mod.rs | 17 ----------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/tools/rustfmt/src/config/config_type.rs b/src/tools/rustfmt/src/config/config_type.rs index 6611a387814ab..f559cc0d620c4 100644 --- a/src/tools/rustfmt/src/config/config_type.rs +++ b/src/tools/rustfmt/src/config/config_type.rs @@ -435,14 +435,14 @@ macro_rules! create_config { /// arms within a declarative macro. #[allow(unreachable_pub)] pub fn reduce_max_width(&mut self, delta: usize) { - self.adjust_max_width(-(delta.min(isize::MAX as usize) as isize)); + self.adjust_max_width(-(delta as isize)); } /// Increases the maximum width of the configuration. /// /// This method is intended to be used when creating a forked /// configuration for a particular formatting context in which the - /// total available width needs to be increased. This increases the + /// total available width needs to be reduced. This increases the /// size of max_width, and all other properties affected by small /// heuristics, without treating those adjustments as overrides. /// @@ -450,7 +450,7 @@ macro_rules! create_config { /// arms within a declarative macro. #[allow(unreachable_pub)] pub fn increase_max_width(&mut self, delta: usize) { - self.adjust_max_width(delta.min(isize::MAX as usize) as isize); + self.adjust_max_width(delta as isize); } /// Adjusts the maximum width of the configuration. @@ -464,9 +464,7 @@ macro_rules! create_config { /// As an example use case, this method is used when formatting /// arms within a declarative macro. fn adjust_max_width(&mut self, delta: isize) { - // NB: we need to either saturate or report an error (or some kind of testable - // warning). I picked to saturate here. - let adjust = |value: usize| value.saturating_add_signed(delta); + let adjust = |value: usize| (value as isize + delta) as usize; self.array_width.2 = adjust(self.array_width.2); self.attr_fn_like_width.2 = adjust(self.attr_fn_like_width.2); diff --git a/src/tools/rustfmt/src/config/mod.rs b/src/tools/rustfmt/src/config/mod.rs index 1aab68ac52ab1..a3f9842cd4f7f 100644 --- a/src/tools/rustfmt/src/config/mod.rs +++ b/src/tools/rustfmt/src/config/mod.rs @@ -701,23 +701,6 @@ mod test { assert_eq!(config.verbose(), Verbosity::Normal); } - #[test] - fn test_adjust_max_width() { - // Regression tests for #7147, where we didn't handle overflows / integral cast outside of - // range properly. - - // Reduce with huge amount saturates to zero instead of wraparound. - let mut config = Config::default(); - config.reduce_max_width(usize::MAX); - assert_eq!(config.max_width(), 0); - - // Increase with huge amount saturates instead of wraparound. - let mut config = Config::default(); - config.set().max_width(usize::MAX - 1); - config.increase_max_width(2); - assert_eq!(config.max_width(), usize::MAX); - } - #[test] fn test_config_used_to_toml() { let config = Config::default(); From 6552a3355bb8112575611def02c76eaaed92f88e Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Mon, 2 Nov 2026 10:05:20 +0800 Subject: [PATCH 11/11] Revert "Fixes adjustment of max_width within macros" Reverts rust-lang/rustfmt#6651 since it affects stable macro formatting, even though `format_macro_bodies` is unstable option (unstability applies only to the config, the "format macro bodies" value is stable default formatting). We generally cannot make this change on SE 2024. This reverts commit 93e78f2d3a0901718530aa871565257a41869983. --- src/tools/rustfmt/src/config/config_type.rs | 57 ------------------- src/tools/rustfmt/src/macros.rs | 6 +- .../tests/target/issue-6651/custom_width.rs | 7 +-- 3 files changed, 5 insertions(+), 65 deletions(-) diff --git a/src/tools/rustfmt/src/config/config_type.rs b/src/tools/rustfmt/src/config/config_type.rs index f559cc0d620c4..afac8d3fcf992 100644 --- a/src/tools/rustfmt/src/config/config_type.rs +++ b/src/tools/rustfmt/src/config/config_type.rs @@ -423,63 +423,6 @@ macro_rules! create_config { )+ } - /// Reduces the maximum width of the configuration. - /// - /// This method is intended to be used when creating a forked - /// configuration for a particular formatting context in which the - /// total available width needs to be reduced. This reduces the - /// size of max_width, and all other properties affected by small - /// heuristics, without treating those adjustments as overrides. - /// - /// As an example use case, this method is used when formatting - /// arms within a declarative macro. - #[allow(unreachable_pub)] - pub fn reduce_max_width(&mut self, delta: usize) { - self.adjust_max_width(-(delta as isize)); - } - - /// Increases the maximum width of the configuration. - /// - /// This method is intended to be used when creating a forked - /// configuration for a particular formatting context in which the - /// total available width needs to be reduced. This increases the - /// size of max_width, and all other properties affected by small - /// heuristics, without treating those adjustments as overrides. - /// - /// As an example use case, this method is used when formatting - /// arms within a declarative macro. - #[allow(unreachable_pub)] - pub fn increase_max_width(&mut self, delta: usize) { - self.adjust_max_width(delta as isize); - } - - /// Adjusts the maximum width of the configuration. - /// - /// This method is intended to be used when creating a forked - /// configuration for a particular formatting context in which the - /// total available width needs to be reduced. This adjusts the - /// size of max_width, and all other properties affected by small - /// heuristics, without treating those adjustments as overrides. - /// - /// As an example use case, this method is used when formatting - /// arms within a declarative macro. - fn adjust_max_width(&mut self, delta: isize) { - let adjust = |value: usize| (value as isize + delta) as usize; - - self.array_width.2 = adjust(self.array_width.2); - self.attr_fn_like_width.2 = adjust(self.attr_fn_like_width.2); - self.chain_width.2 = adjust(self.chain_width.2); - self.fn_call_width.2 = adjust(self.fn_call_width.2); - self.single_line_if_else_max_width.2 = adjust(self.single_line_if_else_max_width.2); - self.single_line_let_else_max_width.2 = - adjust(self.single_line_let_else_max_width.2); - self.struct_lit_width.2 = adjust(self.struct_lit_width.2); - self.struct_variant_width.2 = adjust(self.struct_variant_width.2); - - self.max_width.2 = adjust(self.max_width.2); - self.set_heuristics(); - } - fn set_width_heuristics(&mut self, heuristics: WidthHeuristics) { let max_width = self.max_width.2; let get_width_value = | diff --git a/src/tools/rustfmt/src/macros.rs b/src/tools/rustfmt/src/macros.rs index 9a88569b7909b..1f4a38db2d819 100644 --- a/src/tools/rustfmt/src/macros.rs +++ b/src/tools/rustfmt/src/macros.rs @@ -1361,13 +1361,15 @@ impl MacroBranch { } else { shape.indent.block_indent(&config) }; - config.reduce_max_width(body_indent.width()); + let new_width = config.max_width() - body_indent.width(); + config.set().max_width(new_width); // First try to format as items, then as statements. let new_body_snippet = match crate::format_snippet(&body_str, &config, true) { Some(new_body) => new_body, None => { - config.increase_max_width(config.tab_spaces()); + let new_width = new_width + config.tab_spaces(); + config.set().max_width(new_width); match crate::format_code_block(&body_str, &config, true) { Some(new_body) => new_body, None => { diff --git a/src/tools/rustfmt/tests/target/issue-6651/custom_width.rs b/src/tools/rustfmt/tests/target/issue-6651/custom_width.rs index b46bd5ef5ccab..b6bbe715290d3 100644 --- a/src/tools/rustfmt/tests/target/issue-6651/custom_width.rs +++ b/src/tools/rustfmt/tests/target/issue-6651/custom_width.rs @@ -16,11 +16,6 @@ macro_rules! medium { macro_rules! long { () => { - m!( - aaaaaaaaaaaaaaaa, - bbbbbbbbbbbbbbbb, - cccccccccccccccc, - ddddddddddddddd - ); + m!(aaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbb, cccccccccccccccc, ddddddddddddddd); }; }