From f7d8e4ab547b5ca3053a97014f41147400069797 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 17 Oct 2026 13:20:12 -0400 Subject: [PATCH 01/16] Remove the label starting with 0 in the test binary_asm_labels_allowed.rs 0-prefixed labels are not accepted anymore with GNU as, so this is necessary to make this test pass with rustc_codegen_gcc. --- tests/ui/asm/binary_asm_labels_allowed.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ui/asm/binary_asm_labels_allowed.rs b/tests/ui/asm/binary_asm_labels_allowed.rs index a21ab8d70f5b4..8393c8e411283 100644 --- a/tests/ui/asm/binary_asm_labels_allowed.rs +++ b/tests/ui/asm/binary_asm_labels_allowed.rs @@ -11,7 +11,6 @@ fn main() { asm!("0: bl 0b"); asm!("1: bl 1b"); asm!("10: bl 10b"); - asm!("01: bl 01b"); asm!("1001101: bl 1001101b"); } } From 4477617ac91c1a066ea01245f9c8c60955d07e59 Mon Sep 17 00:00:00 2001 From: arvindkhoisnam Date: Mon, 26 Oct 2026 22:28:02 +0530 Subject: [PATCH 02/16] Document allocator swap in BinaryHeap::append --- library/alloc/src/collections/binary_heap/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index f3698a997c925..64c15d06f653c 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -979,6 +979,10 @@ impl BinaryHeap { /// Moves all the elements of `other` into `self`, leaving `other` empty. /// + /// When `self` has fewer elements than `other`, a swap happens so as to optimize the time complexity. + /// This swap also swaps the allocator for `other` and `self`. + /// Whenever a drop occurs, dropping `self` drops the allocator that originally belonged to `other` and vice versa. + /// /// # Examples /// /// Basic usage: From 7b1da716091242c17a0144e3623b995ec7406e17 Mon Sep 17 00:00:00 2001 From: arvindkhoisnam Date: Tue, 27 Oct 2026 09:07:41 +0530 Subject: [PATCH 03/16] Apply review suggestion for BinaryHeap::append docs --- library/alloc/src/collections/binary_heap/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 64c15d06f653c..2f7d79960007c 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -979,9 +979,7 @@ impl BinaryHeap { /// Moves all the elements of `other` into `self`, leaving `other` empty. /// - /// When `self` has fewer elements than `other`, a swap happens so as to optimize the time complexity. - /// This swap also swaps the allocator for `other` and `self`. - /// Whenever a drop occurs, dropping `self` drops the allocator that originally belonged to `other` and vice versa. + /// For performance, `self` and `other` may be swapped before appending. /// /// # Examples /// From 20ae3b62c8d611de47a7b8f4bfdee61a4b7d4951 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 26 Oct 2026 18:15:20 -0500 Subject: [PATCH 04/16] std: Add UI tests for feature detection macros It can be a bit tricky to follow these macros, but we still want to provide good diagnostics. Add tests making sure these don't change. --- library/std_detect/src/detect/macros.rs | 2 + .../is_arch_feature_detected.AARCH64.stderr | 78 +++++++++++++++++++ .../std/is_arch_feature_detected.X86.stderr | 77 ++++++++++++++++++ tests/ui/std/is_arch_feature_detected.rs | 53 +++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 tests/ui/std/is_arch_feature_detected.AARCH64.stderr create mode 100644 tests/ui/std/is_arch_feature_detected.X86.stderr create mode 100644 tests/ui/std/is_arch_feature_detected.rs diff --git a/library/std_detect/src/detect/macros.rs b/library/std_detect/src/detect/macros.rs index 43f59e22c3a9b..0e5139cf03453 100644 --- a/library/std_detect/src/detect/macros.rs +++ b/library/std_detect/src/detect/macros.rs @@ -28,6 +28,8 @@ macro_rules! check_cfg_feature { }; } +// Make sure any additions to this macro are tested in +// `tests/ui/std/is_arch_feature_detected.AARCH64.stderr`. #[allow(unused)] macro_rules! features { ( diff --git a/tests/ui/std/is_arch_feature_detected.AARCH64.stderr b/tests/ui/std/is_arch_feature_detected.AARCH64.stderr new file mode 100644 index 0000000000000..9e0620f2917b8 --- /dev/null +++ b/tests/ui/std/is_arch_feature_detected.AARCH64.stderr @@ -0,0 +1,78 @@ +error: unknown x86 target feature: not-a-feature + --> $DIR/is_arch_feature_detected.rs:18:13 + | +LL | let _ = arch::is_x86_feature_detected!("not-a-feature"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: unknown aarch64 target feature: not-a-feature + --> $DIR/is_arch_feature_detected.rs:20:13 + | +LL | let _ = arch::is_aarch64_feature_detected!("not-a-feature"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: This macro cannot be used on the current target. + You can prevent it from being used in other architectures by + guarding it behind a cfg(any(target_arch = "x86", target_arch = "x86_64")). + --> $DIR/is_arch_feature_detected.rs:25:13 + | +LL | let _ = arch::is_x86_feature_detected!("sse"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: This macro cannot be used on the current target. + You can prevent it from being used in other architectures by + guarding it behind a cfg(any(target_arch = "x86", target_arch = "x86_64")). + --> $DIR/is_arch_feature_detected.rs:32:13 + | +LL | let _ = arch::is_x86_feature_detected!("avx512gfni"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `$crate::is_x86_feature_detected` which comes from the expansion of the macro `arch::is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: "ras" feature cannot be detected at run-time + --> $DIR/is_arch_feature_detected.rs:37:13 + | +LL | let _ = arch::is_aarch64_feature_detected!("ras"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0658]: use of unstable library feature `stdarch_mips_feature_detection` + --> $DIR/is_arch_feature_detected.rs:41:13 + | +LL | let _ = arch::is_mips_feature_detected!("msa"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #111188 for more information + = help: add `#![feature(stdarch_mips_feature_detection)]` 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: This macro cannot be used on the current target. + You can prevent it from being used in other architectures by + guarding it behind a cfg(target_arch = "mips"). + --> $DIR/is_arch_feature_detected.rs:41:13 + | +LL | let _ = arch::is_mips_feature_detected!("msa"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_mips_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0658]: use of unstable library feature `stdarch_aarch64_feature_detection` + --> $DIR/is_arch_feature_detected.rs:48:13 + | +LL | let _ = arch::is_aarch64_feature_detected!("wfxt"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #127764 for more information + = help: add `#![feature(stdarch_aarch64_feature_detection)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = note: this error originates in the macro `$crate::detect_feature` which comes from the expansion of the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/std/is_arch_feature_detected.X86.stderr b/tests/ui/std/is_arch_feature_detected.X86.stderr new file mode 100644 index 0000000000000..f2267c7042e1c --- /dev/null +++ b/tests/ui/std/is_arch_feature_detected.X86.stderr @@ -0,0 +1,77 @@ +error: unknown x86 target feature: not-a-feature + --> $DIR/is_arch_feature_detected.rs:18:13 + | +LL | let _ = arch::is_x86_feature_detected!("not-a-feature"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: unknown aarch64 target feature: not-a-feature + --> $DIR/is_arch_feature_detected.rs:20:13 + | +LL | let _ = arch::is_aarch64_feature_detected!("not-a-feature"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: This macro cannot be used on the current target. + You can prevent it from being used in other architectures by + guarding it behind a cfg(any(target_arch = "aarch64", target_arch = "arm64ec")). + --> $DIR/is_arch_feature_detected.rs:28:13 + | +LL | let _ = arch::is_aarch64_feature_detected!("neon"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: "ras" feature cannot be detected at run-time + --> $DIR/is_arch_feature_detected.rs:37:13 + | +LL | let _ = arch::is_aarch64_feature_detected!("ras"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0658]: use of unstable library feature `stdarch_mips_feature_detection` + --> $DIR/is_arch_feature_detected.rs:41:13 + | +LL | let _ = arch::is_mips_feature_detected!("msa"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #111188 for more information + = help: add `#![feature(stdarch_mips_feature_detection)]` 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: This macro cannot be used on the current target. + You can prevent it from being used in other architectures by + guarding it behind a cfg(target_arch = "mips"). + --> $DIR/is_arch_feature_detected.rs:41:13 + | +LL | let _ = arch::is_mips_feature_detected!("msa"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `arch::is_mips_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +warning: use of deprecated macro `deprecated_feature`: the `avx512gfni` feature has been renamed to `gfni` + --> $DIR/is_arch_feature_detected.rs:32:13 + | +LL | let _ = arch::is_x86_feature_detected!("avx512gfni"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(deprecated)]` on by default + = note: this warning originates in the macro `arch::is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0658]: use of unstable library feature `xop_target_feature` + --> $DIR/is_arch_feature_detected.rs:51:13 + | +LL | let _ = arch::is_x86_feature_detected!("xop"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #127208 for more information + = help: add `#![feature(xop_target_feature)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = note: this error originates in the macro `$crate::detect_feature` which comes from the expansion of the macro `arch::is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 7 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/std/is_arch_feature_detected.rs b/tests/ui/std/is_arch_feature_detected.rs new file mode 100644 index 0000000000000..a74c43dd4db99 --- /dev/null +++ b/tests/ui/std/is_arch_feature_detected.rs @@ -0,0 +1,53 @@ +//! Check accepted syntax and errors of feature detection macros. + +// Do separate revisions so we can always check another arch's macros +//@ revisions: AARCH64 X86 +//@[AARCH64] only-aarch64 +//@[X86] only-x86_64 + +use std::arch; + +fn main() { + // Correct uage + #[cfg(target_arch = "aarch64")] + let _ = arch::is_aarch64_feature_detected!("neon"); + #[cfg(target_arch = "x86_64")] + let _ = arch::is_x86_feature_detected!("sse"); + + // Invalid features get an error regardless of target + let _ = arch::is_x86_feature_detected!("not-a-feature"); + //~^ ERROR: unknown x86 target feature + let _ = arch::is_aarch64_feature_detected!("not-a-feature"); + //~^ ERROR: unknown aarch64 target feature + + // Valid features get an error if for the wrong target + #[cfg(target_arch = "aarch64")] + let _ = arch::is_x86_feature_detected!("sse"); + //[AARCH64]~^ ERROR: This macro cannot be used on the current target + #[cfg(target_arch = "x86_64")] + let _ = arch::is_aarch64_feature_detected!("neon"); + //[X86]~^ ERROR: This macro cannot be used on the current target + + // Check handling of deprecated features + let _ = arch::is_x86_feature_detected!("avx512gfni"); + //[X86]~^ WARN: use of deprecated macro + //[AARCH64]~^^ ERROR: This macro cannot be used on the current target + + // Check handling of features without runtime detection + let _ = arch::is_aarch64_feature_detected!("ras"); + //~^ ERROR: feature cannot be detected at run-time + + // Check gating of the unstable macro. + let _ = arch::is_mips_feature_detected!("msa"); + //~^ ERROR: use of unstable library feature `stdarch_mips_feature_detection` + //~| ERROR: This macro cannot be used on the current target + + // Check gating of unstable features in stable macros. Note that if this moves too much, it + // may be worth adding a `_demo-unstable` feature so we can test consistently. + #[cfg(target_arch = "aarch64")] + let _ = arch::is_aarch64_feature_detected!("wfxt"); + //[AARCH64]~^ ERROR: use of unstable library feature `stdarch_aarch64_feature_detection` + #[cfg(target_arch = "x86_64")] + let _ = arch::is_x86_feature_detected!("xop"); + //[X86]~^ ERROR: use of unstable library feature `xop_target_feature` +} From 030cab2c82817c41887f26b9583c2a6cd3c5d76c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 26 Oct 2026 18:03:23 -0500 Subject: [PATCH 05/16] std: Improve multi-line compile errors from `std_detect` Because of rewrapping, this prints as: error: This macro cannot be used on the current target. You can prevent it from being used in other architectures by guarding it behind a cfg(any(target_arch = "aarch64", target_arch = "arm64ec")). Bridge newlines so it instead prints as this: error: This macro cannot be used on the current target. You can prevent it from being used in other architectures by guarding it behind a `cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))`. --- library/std_detect/src/detect/macros.rs | 20 +++++++------------ .../is_arch_feature_detected.AARCH64.stderr | 18 ++++++++--------- .../std/is_arch_feature_detected.X86.stderr | 12 +++++------ 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/library/std_detect/src/detect/macros.rs b/library/std_detect/src/detect/macros.rs index 0e5139cf03453..7a7cb54f6ecbf 100644 --- a/library/std_detect/src/detect/macros.rs +++ b/library/std_detect/src/detect/macros.rs @@ -44,6 +44,7 @@ macro_rules! features { $(implied by target_features: [$($target_feature_lit:tt),*];)? $(#[$feature_comment:meta])*)* ) => { + // The current arch's version actually does the feature detection. #[macro_export] $(#[$macro_attrs])* #[allow_internal_unstable(stdarch_internal)] @@ -81,14 +82,12 @@ macro_rules! features { }; ($t:tt) => { compile_error!( - concat!( - concat!("unknown ", stringify!($target)), - concat!(" target feature: ", $t) - ) + concat!("unknown ", stringify!($target), " target feature: ", $t) ) }; } + // All other arches still validate the features, but also $(#[$macro_attrs])* #[macro_export] #[cfg(not($cfg))] @@ -98,11 +97,9 @@ macro_rules! features { ($feature_lit) => { compile_error!( concat!( - r#"This macro cannot be used on the current target. - You can prevent it from being used in other architectures by - guarding it behind a cfg("#, - stringify!($cfg), - ")." + "This macro cannot be used on the current target. You can prevent\n\ + it from being used in other architectures by guarding it behind\n\ + a `cfg(", stringify!($cfg), ")`." ) ) }; @@ -125,10 +122,7 @@ macro_rules! features { }; ($t:tt) => { compile_error!( - concat!( - concat!("unknown ", stringify!($target)), - concat!(" target feature: ", $t) - ) + concat!("unknown ", stringify!($target), " target feature: ", $t) ) }; } diff --git a/tests/ui/std/is_arch_feature_detected.AARCH64.stderr b/tests/ui/std/is_arch_feature_detected.AARCH64.stderr index 9e0620f2917b8..d5452993d2573 100644 --- a/tests/ui/std/is_arch_feature_detected.AARCH64.stderr +++ b/tests/ui/std/is_arch_feature_detected.AARCH64.stderr @@ -14,9 +14,9 @@ LL | let _ = arch::is_aarch64_feature_detected!("not-a-feature"); | = note: this error originates in the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) -error: This macro cannot be used on the current target. - You can prevent it from being used in other architectures by - guarding it behind a cfg(any(target_arch = "x86", target_arch = "x86_64")). +error: This macro cannot be used on the current target. You can prevent + it from being used in other architectures by guarding it behind + a `cfg(any(target_arch = "x86", target_arch = "x86_64"))`. --> $DIR/is_arch_feature_detected.rs:25:13 | LL | let _ = arch::is_x86_feature_detected!("sse"); @@ -24,9 +24,9 @@ LL | let _ = arch::is_x86_feature_detected!("sse"); | = note: this error originates in the macro `arch::is_x86_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) -error: This macro cannot be used on the current target. - You can prevent it from being used in other architectures by - guarding it behind a cfg(any(target_arch = "x86", target_arch = "x86_64")). +error: This macro cannot be used on the current target. You can prevent + it from being used in other architectures by guarding it behind + a `cfg(any(target_arch = "x86", target_arch = "x86_64"))`. --> $DIR/is_arch_feature_detected.rs:32:13 | LL | let _ = arch::is_x86_feature_detected!("avx512gfni"); @@ -52,9 +52,9 @@ LL | let _ = arch::is_mips_feature_detected!("msa"); = help: add `#![feature(stdarch_mips_feature_detection)]` 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: This macro cannot be used on the current target. - You can prevent it from being used in other architectures by - guarding it behind a cfg(target_arch = "mips"). +error: This macro cannot be used on the current target. You can prevent + it from being used in other architectures by guarding it behind + a `cfg(target_arch = "mips")`. --> $DIR/is_arch_feature_detected.rs:41:13 | LL | let _ = arch::is_mips_feature_detected!("msa"); diff --git a/tests/ui/std/is_arch_feature_detected.X86.stderr b/tests/ui/std/is_arch_feature_detected.X86.stderr index f2267c7042e1c..50105408bf422 100644 --- a/tests/ui/std/is_arch_feature_detected.X86.stderr +++ b/tests/ui/std/is_arch_feature_detected.X86.stderr @@ -14,9 +14,9 @@ LL | let _ = arch::is_aarch64_feature_detected!("not-a-feature"); | = note: this error originates in the macro `arch::is_aarch64_feature_detected` (in Nightly builds, run with -Z macro-backtrace for more info) -error: This macro cannot be used on the current target. - You can prevent it from being used in other architectures by - guarding it behind a cfg(any(target_arch = "aarch64", target_arch = "arm64ec")). +error: This macro cannot be used on the current target. You can prevent + it from being used in other architectures by guarding it behind + a `cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))`. --> $DIR/is_arch_feature_detected.rs:28:13 | LL | let _ = arch::is_aarch64_feature_detected!("neon"); @@ -42,9 +42,9 @@ LL | let _ = arch::is_mips_feature_detected!("msa"); = help: add `#![feature(stdarch_mips_feature_detection)]` 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: This macro cannot be used on the current target. - You can prevent it from being used in other architectures by - guarding it behind a cfg(target_arch = "mips"). +error: This macro cannot be used on the current target. You can prevent + it from being used in other architectures by guarding it behind + a `cfg(target_arch = "mips")`. --> $DIR/is_arch_feature_detected.rs:41:13 | LL | let _ = arch::is_mips_feature_detected!("msa"); From 7bc50e74493e54aa68a50bba77655461107ebe95 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Thu, 22 Oct 2026 12:20:57 -0500 Subject: [PATCH 06/16] std: Remove unneeded gates from `std_detect` We have a handful of `#[unstable]` gates that aren't even being used, because all that matters is the re-export in `std`. For example, the RISC-V macro appears unstable, but has actually been stable since 1.78 . --- library/std_detect/src/detect/arch/mod.rs | 37 +++++++++++------------ library/std_detect/src/detect/macros.rs | 1 - library/std_detect/src/detect/mod.rs | 1 - 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/library/std_detect/src/detect/arch/mod.rs b/library/std_detect/src/detect/arch/mod.rs index d3ef2b65c87aa..7e5e8d0f93ebd 100644 --- a/library/std_detect/src/detect/arch/mod.rs +++ b/library/std_detect/src/detect/arch/mod.rs @@ -22,40 +22,40 @@ mod s390x; cfg_select! { any(target_arch = "x86", target_arch = "x86_64") => { - #[stable(feature = "simd_x86", since = "1.27.0")] - pub use x86::*; + pub use x86::__is_feature_detected; + pub(crate) use x86::Feature; } target_arch = "arm" => { - #[unstable(feature = "stdarch_arm_feature_detection", issue = "111190")] - pub use arm::*; + pub use arm::__is_feature_detected; + pub(crate) use arm::Feature; } any(target_arch = "aarch64", target_arch = "arm64ec") => { - #[stable(feature = "simd_aarch64", since = "1.60.0")] - pub use aarch64::*; + pub use aarch64::__is_feature_detected; + pub(crate) use aarch64::Feature; } any(target_arch = "riscv32", target_arch = "riscv64") => { - #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] - pub use riscv::*; + pub use riscv::__is_feature_detected; + pub(crate) use riscv::Feature; } any(target_arch = "powerpc", target_arch = "powerpc64") => { - #[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")] - pub use powerpc::*; + pub use powerpc::__is_feature_detected; + pub(crate) use powerpc::Feature; } target_arch = "mips" => { - #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")] - pub use mips::*; + pub use mips::__is_feature_detected; + pub(crate) use mips::Feature; } target_arch = "mips64" => { - #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")] - pub use mips64::*; + pub use mips64::__is_feature_detected; + pub(crate) use mips64::Feature; } any(target_arch = "loongarch32", target_arch = "loongarch64") => { - #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] - pub use loongarch::*; + pub use loongarch::__is_feature_detected; + pub(crate) use loongarch::Feature; } target_arch = "s390x" => { - #[stable(feature = "stdarch_s390x_feature_detection", since = "1.93.0")] - pub use s390x::*; + pub use s390x::__is_feature_detected; + pub(crate) use s390x::Feature; } _ => { // Unimplemented architecture: @@ -64,7 +64,6 @@ cfg_select! { Null, } #[doc(hidden)] - #[unstable(feature = "stdarch_internal", issue = "none")] pub mod __is_feature_detected {} impl Feature { diff --git a/library/std_detect/src/detect/macros.rs b/library/std_detect/src/detect/macros.rs index 7a7cb54f6ecbf..1b6a31797d995 100644 --- a/library/std_detect/src/detect/macros.rs +++ b/library/std_detect/src/detect/macros.rs @@ -181,7 +181,6 @@ macro_rules! features { /// to change. #[doc(hidden)] #[cfg($cfg)] - #[unstable(feature = "stdarch_internal", issue = "none")] pub mod __is_feature_detected { $( diff --git a/library/std_detect/src/detect/mod.rs b/library/std_detect/src/detect/mod.rs index c888dd34d9db5..cd03390662f1a 100644 --- a/library/std_detect/src/detect/mod.rs +++ b/library/std_detect/src/detect/mod.rs @@ -24,7 +24,6 @@ mod arch; // This module needs to be public because the `is_{arch}_feature_detected!` // macros expand calls to items within it in user crates. -#[doc(hidden)] #[unstable(feature = "stdarch_internal", issue = "none")] pub use self::arch::__is_feature_detected; pub(crate) use self::arch::Feature; From 51ff312a18f8ecf9aa85a29ff2ecf7ccb6ccf29f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 26 Oct 2026 19:46:32 -0500 Subject: [PATCH 07/16] std: Add more documentation to the `std_detect` macros --- library/std_detect/src/detect/macros.rs | 62 +++++++++++++++++++------ 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/library/std_detect/src/detect/macros.rs b/library/std_detect/src/detect/macros.rs index 1b6a31797d995..61b834a0e8f81 100644 --- a/library/std_detect/src/detect/macros.rs +++ b/library/std_detect/src/detect/macros.rs @@ -1,3 +1,4 @@ +/// Forward a literal to the relevant `__is_feature_detected` function. #[macro_export] #[allow_internal_unstable(stdarch_internal)] #[unstable(feature = "stdarch_internal", issue = "none")] @@ -6,6 +7,7 @@ macro_rules! detect_feature { $crate::detect_feature!($feature, $feature_lit : $feature_lit) }; ($feature:tt, $feature_lit:tt : $($target_feature_lit:tt),*) => { + // Emit `true` if enabled at compile time $(cfg!(target_feature = $target_feature_lit) ||)* $crate::detect::__is_feature_detected::$feature() }; @@ -14,6 +16,7 @@ macro_rules! detect_feature { }; } +/// Verify that all features are known by `cfg!`. #[allow(unused_macros, reason = "it's used in the features! macro below")] macro_rules! check_cfg_feature { ($feature:tt, $feature_lit:tt) => { @@ -28,21 +31,34 @@ macro_rules! check_cfg_feature { }; } +/// Create the `is_*_feature_detected` macro for an architecture. // Make sure any additions to this macro are tested in // `tests/ui/std/is_arch_feature_detected.AARCH64.stderr`. #[allow(unused)] macro_rules! features { ( - @TARGET: $target:ident; - @CFG: $cfg:meta; - @MACRO_NAME: $macro_name:ident; - @MACRO_ATTRS: $(#[$macro_attrs:meta])* - $(@BIND_FEATURE_NAME: $bind_feature:tt; $feature_impl:tt; $(#[$deprecate_attr:meta];)?)* - $(@NO_RUNTIME_DETECTION: $nort_feature:tt; )* - $(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt; - $(without cfg check: $feature_cfg_check:tt;)? - $(implied by target_features: [$($target_feature_lit:tt),*];)? - $(#[$feature_comment:meta])*)* + // Target or target family name, for use in diagnostic messages + @TARGET: $target:ident; + // Cfg for which this macro should be allowed + @CFG: $cfg:meta; + // Name like `is_*_feature_detected` + @MACRO_NAME: $macro_name:ident; + // Docs and stability attributes + @MACRO_ATTRS: $(#[$macro_attrs:meta])* + // Synonyms, with possible deprecation + $(@BIND_FEATURE_NAME: $bind_feature:tt; $feature_impl:tt; $(#[$deprecate_attr:meta];)?)* + // Features that exist but can't be detected at runtime, so emit an error. + $(@NO_RUNTIME_DETECTION: $nort_feature:tt; )* + // List of features + $(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt; + // Skip verifying that the feature is known by `cfg!`, which also skips emitting `true` + // if the feature is enabled at compile time. + $(without cfg check: $feature_cfg_check:tt;)? + // If this feature is always enabled by some other feature, we can avoid the cost of + // checking them separately by instead only checking the root features. + $(implied by target_features: [$($target_feature_lit:tt),*];)? + // Doc comment for the feature. + $(#[$feature_comment:meta])*)* ) => { // The current arch's version actually does the feature detection. #[macro_export] @@ -51,11 +67,18 @@ macro_rules! features { #[cfg($cfg)] #[doc(cfg($cfg))] macro_rules! $macro_name { + // Emit all known features $( ($feature_lit) => { - $crate::detect_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? $(: $($target_feature_lit),*)?) + $crate::detect_feature!( + $feature, + $feature_lit + $(, without cfg check: $feature_cfg_check)? + $(: $($target_feature_lit),*)? + ) }; )* + // Emit all aliases, with a deprecation notice if applicable $( ($bind_feature) => { { @@ -67,6 +90,7 @@ macro_rules! features { } }; )* + // Emit an error for features that can't be detected at runtime $( ($nort_feature) => { compile_error!( @@ -77,9 +101,11 @@ macro_rules! features { ) }; )* + // Allow a trailing comma ($t:tt,) => { - $crate::$macro_name!($t) + $crate::$macro_name!($t) }; + // Fallback, error for unknown target features ($t:tt) => { compile_error!( concat!("unknown ", stringify!($target), " target feature: ", $t) @@ -93,6 +119,7 @@ macro_rules! features { #[cfg(not($cfg))] #[doc(cfg($cfg))] macro_rules! $macro_name { + // All known features get an error $( ($feature_lit) => { compile_error!( @@ -104,9 +131,11 @@ macro_rules! features { ) }; )* + // Forward deprecated features $( ($bind_feature) => { $crate::$macro_name!($feature_impl) }; )* + // Emit an error for features that can't be detected at runtime $( ($nort_feature) => { compile_error!( @@ -117,9 +146,11 @@ macro_rules! features { ) }; )* + // Allow a trailing comma ($t:tt,) => { $crate::$macro_name!($t); }; + // Fallback, error for unknown target features ($t:tt) => { compile_error!( concat!("unknown ", stringify!($target), " target feature: ", $t) @@ -131,7 +162,12 @@ macro_rules! features { #[deny(unfulfilled_lint_expectations)] const _: () = { $( - check_cfg_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? $(: $($target_feature_lit),*)?); + check_cfg_feature!( + $feature, + $feature_lit + $(, without cfg check: $feature_cfg_check)? + $(: $($target_feature_lit),*)?) + ; )* }; From 5f7505ca8e6b96719fb094a92908fd6fb0700226 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 27 Oct 2026 10:11:11 -0500 Subject: [PATCH 08/16] std: Simplify std_detect feature iteraion using a list Rather than transmuting discriminants, use the macros to generate a list of all features that we can iterate instead. This also allows us to remove the sentinel `_last` entry. --- library/std_detect/src/detect/arch/mod.rs | 2 ++ library/std_detect/src/detect/macros.rs | 8 ++++---- library/std_detect/src/detect/mod.rs | 14 +++++--------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/library/std_detect/src/detect/arch/mod.rs b/library/std_detect/src/detect/arch/mod.rs index 7e5e8d0f93ebd..2c0b464e32beb 100644 --- a/library/std_detect/src/detect/arch/mod.rs +++ b/library/std_detect/src/detect/arch/mod.rs @@ -67,6 +67,8 @@ cfg_select! { pub mod __is_feature_detected {} impl Feature { + #[doc(hidden)] + pub(crate) const ALL: &[Self] = &[]; #[doc(hidden)] pub(crate) fn from_str(_s: &str) -> Result { Err(()) diff --git a/library/std_detect/src/detect/macros.rs b/library/std_detect/src/detect/macros.rs index 61b834a0e8f81..09962d72378a9 100644 --- a/library/std_detect/src/detect/macros.rs +++ b/library/std_detect/src/detect/macros.rs @@ -186,17 +186,17 @@ macro_rules! features { $(#[$feature_comment])* $feature, )* - - // Do not add variants after last: - _last } #[cfg($cfg)] impl Feature { + pub(crate) const ALL: &[Feature] = &[ + $(Feature::$feature,)* + ]; + pub(crate) fn to_str(self) -> &'static str { match self { $(Feature::$feature => $feature_lit,)* - Feature::_last => unreachable!(), } } diff --git a/library/std_detect/src/detect/mod.rs b/library/std_detect/src/detect/mod.rs index cd03390662f1a..9978d3cf8af05 100644 --- a/library/std_detect/src/detect/mod.rs +++ b/library/std_detect/src/detect/mod.rs @@ -110,15 +110,11 @@ pub fn features() -> impl Iterator { target_arch = "loongarch32", target_arch = "loongarch64", target_arch = "s390x", - ) => { - (0_u8..Feature::_last as u8).map(|discriminant: u8| { - #[allow(bindings_with_variant_name)] // RISC-V has Feature::f - let f: Feature = unsafe { core::mem::transmute(discriminant) }; - let name: &'static str = f.to_str(); - let enabled: bool = check_for(f); - (name, enabled) - }) - } + ) => Feature::ALL.iter().copied().map(|feat| { + let name: &'static str = feat.to_str(); + let enabled: bool = check_for(feat); + (name, enabled) + }), _ => None.into_iter(), } } From 63f2b3938cabe1441c8fbc8247f551f3b941f8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kondzior?= Date: Sun, 1 Nov 2026 07:31:10 +0100 Subject: [PATCH 09/16] Fix constant-pattern suggestion spans in macros --- .../src/thir/pattern/const_to_pat.rs | 7 +- .../equality-suggestion-issue-164044.rs | 23 +++++ .../equality-suggestion-issue-164044.stderr | 92 +++++++++++++++++++ ...parison_instead_of_pattern_matching.stderr | 5 + 4 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.rs create mode 100644 tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.stderr diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index bd0e142bd3bd6..0963587b91696 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -322,9 +322,12 @@ impl<'tcx> ConstToPat<'tcx> { }) => { if let_expr.pat.span == self.span { // `if let CONST = expr` -> `if CONST == expr`. - Some(SuggestEq::ReplaceWithEq { + let matching_initializer = + let_expr.init.span.find_ancestor_in_same_ctxt(self.span); + + matching_initializer.map(|init_span| SuggestEq::ReplaceWithEq { removal: span.until(self.span), - eq: self.span.between(let_expr.init.span), + eq: self.span.between(init_span), ty, manual_partialeq_impl, }) diff --git a/tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.rs b/tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.rs new file mode 100644 index 0000000000000..fa9c1e53a98ec --- /dev/null +++ b/tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.rs @@ -0,0 +1,23 @@ +//@ edition:2024 +// Regression tests for https://github.com/rust-lang/rust/issues/164044 + +const V: Vec<()> = Vec::new(); + +macro_rules! generated_plain { + () => { + if let V = Vec::new() {} //~ ERROR constant of non-structural type + }; +} + +macro_rules! generated_nested { + () => { + if let V = vec![] {} //~ ERROR constant of non-structural type + }; +} + +fn main() { + if let V = Vec::new() {} //~ ERROR constant of non-structural type + if let V = vec![] {} //~ ERROR constant of non-structural type + generated_plain!(); + generated_nested!(); +} diff --git a/tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.stderr b/tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.stderr new file mode 100644 index 0000000000000..384c64033960f --- /dev/null +++ b/tests/ui/consts/const_in_pattern/equality-suggestion-issue-164044.stderr @@ -0,0 +1,92 @@ +error: constant of non-structural type `Vec<()>` in a pattern + --> $DIR/equality-suggestion-issue-164044.rs:19:12 + | +LL | const V: Vec<()> = Vec::new(); + | ---------------- constant defined here +... +LL | if let V = Vec::new() {} + | ^ constant of non-structural type + | + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | + = note: `Vec<()>` is not usable in patterns + | + = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details +help: check for equality instead of pattern matching + | +LL - if let V = Vec::new() {} +LL + if V == Vec::new() {} + | + +error: constant of non-structural type `Vec<()>` in a pattern + --> $DIR/equality-suggestion-issue-164044.rs:20:12 + | +LL | const V: Vec<()> = Vec::new(); + | ---------------- constant defined here +... +LL | if let V = vec![] {} + | ^ constant of non-structural type + | + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | + = note: `Vec<()>` is not usable in patterns + | + = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details +help: check for equality instead of pattern matching + | +LL - if let V = vec![] {} +LL + if V == vec![] {} + | + +error: constant of non-structural type `Vec<()>` in a pattern + --> $DIR/equality-suggestion-issue-164044.rs:8:16 + | +LL | const V: Vec<()> = Vec::new(); + | ---------------- constant defined here +LL | +LL | macro_rules! generated_plain { +LL | () => { +LL | if let V = Vec::new() {} + | ^ constant of non-structural type +... +LL | generated_plain!(); + | ------------------ in this macro invocation + | + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | + = note: `Vec<()>` is not usable in patterns + | + = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details +help: check for equality instead of pattern matching + | +LL - if let V = Vec::new() {} +LL + if V == Vec::new() {} + | + +error: constant of non-structural type `Vec<()>` in a pattern + --> $DIR/equality-suggestion-issue-164044.rs:14:16 + | +LL | const V: Vec<()> = Vec::new(); + | ---------------- constant defined here +... +LL | macro_rules! generated_nested { +LL | () => { +LL | if let V = vec![] {} + | ^ constant of non-structural type +... +LL | generated_nested!(); + | ------------------- in this macro invocation + | + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | + = note: `Vec<()>` is not usable in patterns + | + = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details +help: check for equality instead of pattern matching + | +LL - if let V = vec![] {} +LL + if V == vec![] {} + | + +error: aborting due to 4 previous errors + diff --git a/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr b/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr index 38440af675feb..e5bb353776559 100644 --- a/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr +++ b/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr @@ -147,6 +147,11 @@ LL | if let V = vec![] {} = note: `Vec<()>` is not usable in patterns | = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details +help: check for equality instead of pattern matching + | +LL - if let V = vec![] {} +LL + if V == vec![] {} + | error: constant of non-structural type `Vec<()>` in a pattern --> $DIR/suggest_equality_comparison_instead_of_pattern_matching.rs:28:13 From 34c44aa10a2be0debdafd808960954dc5816e818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kondzior?= Date: Mon, 2 Nov 2026 05:56:14 +0100 Subject: [PATCH 10/16] Fix explicit destructor-call suggestion spans in macros --- compiler/rustc_hir_typeck/src/callee.rs | 16 ++++--- compiler/rustc_hir_typeck/src/diagnostics.rs | 2 +- ...licit-drop-macro-suggestions-suppressed.rs | 11 +++++ ...t-drop-macro-suggestions-suppressed.stderr | 14 ++++++ .../explicit-drop-macro-suggestions.fixed | 18 ++++++++ .../drop/explicit-drop-macro-suggestions.rs | 18 ++++++++ .../explicit-drop-macro-suggestions.stderr | 44 +++++++++++++++++++ .../pin-ergonomics/pinned-drop-check.stderr | 36 +++++++++++++++ 8 files changed, 151 insertions(+), 8 deletions(-) create mode 100644 tests/ui/drop/explicit-drop-macro-suggestions-suppressed.rs create mode 100644 tests/ui/drop/explicit-drop-macro-suggestions-suppressed.stderr create mode 100644 tests/ui/drop/explicit-drop-macro-suggestions.fixed create mode 100644 tests/ui/drop/explicit-drop-macro-suggestions.rs create mode 100644 tests/ui/drop/explicit-drop-macro-suggestions.stderr diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 8ef6a19fdb511..790bb9a85c004 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -60,13 +60,15 @@ pub(crate) fn check_legal_trait_for_method_call( // Allow calling `Drop::pin_drop` in `Drop::drop` && !tcx.is_lang_item(tcx.parent(body_def_id), LangItem::Drop) { - let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) { - diagnostics::ExplicitDestructorCallSugg::Snippet { - lo: expr_span.shrink_to_lo().to(receiver.shrink_to_lo()), - hi: receiver.shrink_to_hi().to(expr_span.shrink_to_hi()), - } - } else { - diagnostics::ExplicitDestructorCallSugg::Empty(span) + let sugg = match receiver.filter(|s| !s.is_empty()) { + Some(receiver) => receiver + .find_ancestor_inside_same_ctxt(expr_span) + .filter(|receiver| !receiver.is_empty()) + .map(|receiver| diagnostics::ExplicitDestructorCallSugg::Snippet { + lo: expr_span.shrink_to_lo().to(receiver.shrink_to_lo()), + hi: receiver.shrink_to_hi().to(expr_span.shrink_to_hi()), + }), + None => Some(diagnostics::ExplicitDestructorCallSugg::Empty(span)), }; return Err(tcx.dcx().emit_err(diagnostics::ExplicitDestructorCall { span, sugg })); } diff --git a/compiler/rustc_hir_typeck/src/diagnostics.rs b/compiler/rustc_hir_typeck/src/diagnostics.rs index 3a04a4d28caa8..a1e5bf711a674 100644 --- a/compiler/rustc_hir_typeck/src/diagnostics.rs +++ b/compiler/rustc_hir_typeck/src/diagnostics.rs @@ -196,7 +196,7 @@ pub(crate) struct ExplicitDestructorCall { #[label("explicit destructor calls not allowed")] pub span: Span, #[subdiagnostic] - pub sugg: ExplicitDestructorCallSugg, + pub sugg: Option, } #[derive(Subdiagnostic)] diff --git a/tests/ui/drop/explicit-drop-macro-suggestions-suppressed.rs b/tests/ui/drop/explicit-drop-macro-suggestions-suppressed.rs new file mode 100644 index 0000000000000..cc7b2ff491676 --- /dev/null +++ b/tests/ui/drop/explicit-drop-macro-suggestions-suppressed.rs @@ -0,0 +1,11 @@ +//@ forbid-output: consider using `drop` function +// https://github.com/rust-lang/rust/issues/164044 +macro_rules! call_drop { + ($value:expr) => { + $value.drop() //~ ERROR explicit use of destructor method + }; +} + +fn main() { + call_drop!(Vec::::new()); +} diff --git a/tests/ui/drop/explicit-drop-macro-suggestions-suppressed.stderr b/tests/ui/drop/explicit-drop-macro-suggestions-suppressed.stderr new file mode 100644 index 0000000000000..2b36eabebfa9f --- /dev/null +++ b/tests/ui/drop/explicit-drop-macro-suggestions-suppressed.stderr @@ -0,0 +1,14 @@ +error[E0040]: explicit use of destructor method + --> $DIR/explicit-drop-macro-suggestions-suppressed.rs:5:16 + | +LL | macro_rules! call_drop { +LL | ($value:expr) => { +LL | $value.drop() + | ^^^^ explicit destructor calls not allowed +... +LL | call_drop!(Vec::::new()); + | ---------------------------- in this macro invocation + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0040`. diff --git a/tests/ui/drop/explicit-drop-macro-suggestions.fixed b/tests/ui/drop/explicit-drop-macro-suggestions.fixed new file mode 100644 index 0000000000000..1ab91492b9c37 --- /dev/null +++ b/tests/ui/drop/explicit-drop-macro-suggestions.fixed @@ -0,0 +1,18 @@ +//@ run-rustfix +// https://github.com/rust-lang/rust/issues/164044 +macro_rules! generated { + () => { + drop(vec![3_u8]); //~ ERROR explicit use of destructor method + //~| HELP consider using `drop` function + }; +} + +fn main() { + drop(vec![1_u8]); //~ ERROR explicit use of destructor method + //~| HELP consider using `drop` function + + drop(vec![2_u8]); //~ ERROR explicit use of destructor method + //~| HELP consider using `drop` function + + generated!(); +} diff --git a/tests/ui/drop/explicit-drop-macro-suggestions.rs b/tests/ui/drop/explicit-drop-macro-suggestions.rs new file mode 100644 index 0000000000000..dd58fe2d18e5d --- /dev/null +++ b/tests/ui/drop/explicit-drop-macro-suggestions.rs @@ -0,0 +1,18 @@ +//@ run-rustfix +// https://github.com/rust-lang/rust/issues/164044 +macro_rules! generated { + () => { + Drop::drop(&mut vec![3_u8]); //~ ERROR explicit use of destructor method + //~| HELP consider using `drop` function + }; +} + +fn main() { + vec![1_u8].drop(); //~ ERROR explicit use of destructor method + //~| HELP consider using `drop` function + + Drop::drop(&mut vec![2_u8]); //~ ERROR explicit use of destructor method + //~| HELP consider using `drop` function + + generated!(); +} diff --git a/tests/ui/drop/explicit-drop-macro-suggestions.stderr b/tests/ui/drop/explicit-drop-macro-suggestions.stderr new file mode 100644 index 0000000000000..cb33bf95318e3 --- /dev/null +++ b/tests/ui/drop/explicit-drop-macro-suggestions.stderr @@ -0,0 +1,44 @@ +error[E0040]: explicit use of destructor method + --> $DIR/explicit-drop-macro-suggestions.rs:11:16 + | +LL | vec![1_u8].drop(); + | ^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - vec![1_u8].drop(); +LL + drop(vec![1_u8]); + | + +error[E0040]: explicit use of destructor method + --> $DIR/explicit-drop-macro-suggestions.rs:14:5 + | +LL | Drop::drop(&mut vec![2_u8]); + | ^^^^^^^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - Drop::drop(&mut vec![2_u8]); +LL + drop(vec![2_u8]); + | + +error[E0040]: explicit use of destructor method + --> $DIR/explicit-drop-macro-suggestions.rs:5:9 + | +LL | macro_rules! generated { +LL | () => { +LL | Drop::drop(&mut vec![3_u8]); + | ^^^^^^^^^^ explicit destructor calls not allowed +... +LL | generated!(); + | ------------ in this macro invocation + | +help: consider using `drop` function + | +LL - Drop::drop(&mut vec![3_u8]); +LL + drop(vec![3_u8]); + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0040`. diff --git a/tests/ui/pin-ergonomics/pinned-drop-check.stderr b/tests/ui/pin-ergonomics/pinned-drop-check.stderr index 892413655a229..2a10ef06dcdbf 100644 --- a/tests/ui/pin-ergonomics/pinned-drop-check.stderr +++ b/tests/ui/pin-ergonomics/pinned-drop-check.stderr @@ -301,36 +301,72 @@ error[E0040]: explicit use of destructor method | LL | Drop::pin_drop(todo!()); | ^^^^^^^^^^^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - Drop::pin_drop(todo!()); +LL + drop(todo!()); + | error[E0040]: explicit use of destructor method --> $DIR/pinned-drop-check.rs:156:13 | LL | Drop::pin_drop(todo!()); | ^^^^^^^^^^^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - Drop::pin_drop(todo!()); +LL + drop(todo!()); + | error[E0040]: explicit use of destructor method --> $DIR/pinned-drop-check.rs:168:13 | LL | Drop::drop(todo!()); | ^^^^^^^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - Drop::drop(todo!()); +LL + drop(todo!()); + | error[E0040]: explicit use of destructor method --> $DIR/pinned-drop-check.rs:173:13 | LL | Drop::drop(todo!()); | ^^^^^^^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - Drop::drop(todo!()); +LL + drop(todo!()); + | error[E0040]: explicit use of destructor method --> $DIR/pinned-drop-check.rs:183:13 | LL | Drop::drop(todo!()); | ^^^^^^^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - Drop::drop(todo!()); +LL + drop(todo!()); + | error[E0040]: explicit use of destructor method --> $DIR/pinned-drop-check.rs:184:13 | LL | Drop::pin_drop(todo!()); | ^^^^^^^^^^^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +LL - Drop::pin_drop(todo!()); +LL + drop(todo!()); + | error: aborting due to 25 previous errors From f6db6659353503cded9487453b97fa8d286496f5 Mon Sep 17 00:00:00 2001 From: "Valaphee64.exe" Date: Mon, 2 Nov 2026 10:00:43 +0100 Subject: [PATCH 11/16] impl_from_endian_bytes for f16 and f128 --- library/alloc/src/io/read.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/io/read.rs b/library/alloc/src/io/read.rs index 145cee958aeb3..0b64c794c4504 100644 --- a/library/alloc/src/io/read.rs +++ b/library/alloc/src/io/read.rs @@ -1108,4 +1108,4 @@ macro_rules! impl_from_endian_bytes { )*}; } -impl_from_endian_bytes!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64); +impl_from_endian_bytes!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f16, f32, f64, f128); From ce9a8272dd068bbf543e58f879a7eb8007e979f7 Mon Sep 17 00:00:00 2001 From: "Valaphee64.exe" Date: Mon, 2 Nov 2026 11:03:59 +0100 Subject: [PATCH 12/16] fmt --- library/alloc/src/io/read.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/io/read.rs b/library/alloc/src/io/read.rs index 0b64c794c4504..f805ffa255422 100644 --- a/library/alloc/src/io/read.rs +++ b/library/alloc/src/io/read.rs @@ -1108,4 +1108,6 @@ macro_rules! impl_from_endian_bytes { )*}; } -impl_from_endian_bytes!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f16, f32, f64, f128); +impl_from_endian_bytes!( + u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f16, f32, f64, f128 +); From d239ae14ccaa2403844f7190e1f888cf4b87f499 Mon Sep 17 00:00:00 2001 From: "Valaphee64.exe" Date: Mon, 2 Nov 2026 11:04:56 +0100 Subject: [PATCH 13/16] add f16, f128 feature --- library/alloc/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 92fa5fdb1f1ec..37d6ac2fc9dcc 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -202,6 +202,8 @@ #![feature(coroutine_trait)] #![feature(decl_macro)] #![feature(dropck_eyepatch)] +#![feature(f16)] +#![feature(f128)] #![feature(fundamental)] #![feature(impl_restriction)] #![feature(intrinsics)] From 8d4158392bf7ababa9dbb0e810456dfef9e80673 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Tue, 3 Nov 2026 15:00:22 +0000 Subject: [PATCH 14/16] remove unusued query key impl --- compiler/rustc_middle/src/query/keys.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index c3d8ffbf4de3b..6f2fc5cac0024 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -346,24 +346,6 @@ impl<'tcx, T: QueryKeyBounds> QueryKey for (CanonicalQueryInput<'tcx, T>, bool) } } -impl<'tcx, T: QueryKeyBounds> QueryKey for (CanonicalQueryInput<'tcx, T>, usize) { - fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - -impl<'tcx> QueryKey for crate::traits::solve::CanonicalInput<'tcx> { - fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - -impl<'tcx> QueryKey for (crate::traits::solve::CanonicalInput<'tcx>, bool) { - fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { - DUMMY_SP - } -} - impl<'tcx> QueryKey for (crate::traits::solve::CanonicalInput<'tcx>, usize) { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP From 0a75b4c36695289c11ede1edaa32677c1c8609c3 Mon Sep 17 00:00:00 2001 From: Ubiratan Soares Date: Wed, 4 Nov 2026 00:12:25 +0100 Subject: [PATCH 15/16] docker: bump node to v24.22.2 in shared script --- src/ci/docker/run.sh | 2 +- src/ci/docker/scripts/nodejs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index 45f42b5d9c1f2..1ad39dfc082ca 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -74,7 +74,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then echo "$machine" >> $hash_key # Include cache version. Can be used to manually bust the Docker cache. - echo "3" >> $hash_key + echo "4" >> $hash_key echo "::group::Image checksum input" cat $hash_key diff --git a/src/ci/docker/scripts/nodejs.sh b/src/ci/docker/scripts/nodejs.sh index c6a1b2f51ff03..2656a9fb65926 100644 --- a/src/ci/docker/scripts/nodejs.sh +++ b/src/ci/docker/scripts/nodejs.sh @@ -2,7 +2,7 @@ set -ex -NODEJS_VERSION=v24.15.0 +NODEJS_VERSION=v24.22.2 YARN_VERSION=1.22.22 INSTALL_PATH=${1:-/node} From 0376ed93c941400f9798bd9f2bb11f16e102c27e Mon Sep 17 00:00:00 2001 From: Joy Date: Wed, 4 Nov 2026 01:00:57 +0000 Subject: [PATCH 16/16] [Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc) * alloc: Add test coverage for try_clone_from_ref_in * alloc: test cloning zero-sized values from references * alloc: format zero-sized clone test * alloctests: remove obsolete const_btree_len feature * alloctests: fix feature attribute formatting --- library/alloctests/tests/boxed.rs | 28 ++++++++++++++++++++++++++++ library/alloctests/tests/lib.rs | 1 + 2 files changed, 29 insertions(+) diff --git a/library/alloctests/tests/boxed.rs b/library/alloctests/tests/boxed.rs index 74db1c7de31e7..9ababf1f264c5 100644 --- a/library/alloctests/tests/boxed.rs +++ b/library/alloctests/tests/boxed.rs @@ -3,6 +3,34 @@ use core::cell::Cell; use core::mem::MaybeUninit; use core::ptr::NonNull; +#[test] +fn try_clone_from_ref_in_zero_sized_type_skips_allocation() { + use std::alloc::Global; + + struct CountingAllocator { + allocations: Cell, + } + + unsafe impl Allocator for CountingAllocator { + fn allocate(&self, layout: Layout) -> Result, AllocError> { + self.allocations.set(self.allocations.get() + 1); + Global.allocate(layout) + } + + unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { + unsafe { Global.deallocate(ptr, layout) } + } + } + + let alloc = CountingAllocator { allocations: Cell::new(0) }; + + let value = (); + let boxed = Box::try_clone_from_ref_in(&value, &alloc).unwrap(); + + assert_eq!(*boxed, ()); + assert_eq!(alloc.allocations.get(), 0); +} + #[test] #[expect(dangling_pointers_from_temporaries)] fn uninitialized_zero_size_box() { diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index d787c3c553d08..ed5287276aad8 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -13,6 +13,7 @@ #![feature(byte_str_to_string)] #![feature(can_vector)] #![feature(casefold)] +#![feature(clone_from_ref)] #![feature(const_cmp)] #![feature(const_heap)] #![feature(const_trait_impl)]