From 033c92370e2a889a5d23fb36eba2986383d71faf Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Fri, 17 Apr 2026 13:02:23 +0200 Subject: [PATCH 1/7] Add temporary scope to assert_matches Addresses https://github.com/rust-lang/rust/issues/154406 in part. assert_eq will be done in a separate PR. (cherry picked from commit e0ef87f8808a094339605fc5e859ac5baa810c0b) --- library/core/src/macros/mod.rs | 8 ++++---- library/coretests/tests/macros.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 33397e56b86c5..08a12b6447e61 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -168,7 +168,7 @@ macro_rules! assert_ne { #[allow_internal_unstable(panic_internals)] #[rustc_macro_transparency = "semiopaque"] pub macro assert_matches { - ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => { + ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {{ match $left { $( $pattern )|+ $( if $guard )? => {} ref left_val => { @@ -179,8 +179,8 @@ pub macro assert_matches { ); } } - }, - ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => { + }}, + ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => {{ match $left { $( $pattern )|+ $( if $guard )? => {} ref left_val => { @@ -191,7 +191,7 @@ pub macro assert_matches { ); } } - }, + }}, } /// Selects code at compile-time based on `cfg` predicates. diff --git a/library/coretests/tests/macros.rs b/library/coretests/tests/macros.rs index 50b5eb63e43a7..52435b226e654 100644 --- a/library/coretests/tests/macros.rs +++ b/library/coretests/tests/macros.rs @@ -1,5 +1,7 @@ #![allow(unused_must_use)] +use std::{assert_matches, debug_assert_matches}; + #[allow(dead_code)] trait Trait { fn blah(&self); @@ -219,3 +221,24 @@ fn _matches_does_not_trigger_non_exhaustive_omitted_patterns_lint(o: core::sync: // Ordering is a #[non_exhaustive] enum from a separate crate let _m = matches!(o, core::sync::atomic::Ordering::Relaxed); } + +struct MutRefWithDrop<'a>(&'a mut u32); + +// MutRefWithDrop needs to have a non-trivial drop to encounter potential lifetime issues if the +// macros don't introduce a temporary scope. +impl Drop for MutRefWithDrop<'_> { + fn drop(&mut self) { + *self.0 = u32::MAX; + } +} + +#[test] +fn temporary_scope_introduction() { + // Fails to compile if the macros don't introduce a temporary scope, since `&mut val` would + // create a second mutable borrow while `MutRefWithDrop` still holds a unique ref. + let mut val = 0; + + (assert_matches!(*MutRefWithDrop(&mut val).0, 0), std::mem::take(&mut val)); + + (debug_assert_matches!(*MutRefWithDrop(&mut val).0, 0), std::mem::take(&mut val)); +} From cbdde36f5e9f2cd9775f769a3ceeda025c1ba20c Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Sat, 18 Apr 2026 15:12:33 +0200 Subject: [PATCH 2/7] Apply review feedback (cherry picked from commit 3a0c0e9cb7b3797dd8f669a317d703fe74dfbfe7) --- library/coretests/tests/macros.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/coretests/tests/macros.rs b/library/coretests/tests/macros.rs index 52435b226e654..9f73ebd253c3b 100644 --- a/library/coretests/tests/macros.rs +++ b/library/coretests/tests/macros.rs @@ -236,9 +236,12 @@ impl Drop for MutRefWithDrop<'_> { fn temporary_scope_introduction() { // Fails to compile if the macros don't introduce a temporary scope, since `&mut val` would // create a second mutable borrow while `MutRefWithDrop` still holds a unique ref. + // See https://github.com/rust-lang/rust/issues/154406 for reference. let mut val = 0; (assert_matches!(*MutRefWithDrop(&mut val).0, 0), std::mem::take(&mut val)); + (assert_matches!(*MutRefWithDrop(&mut val).0, 0, "msg"), std::mem::take(&mut val)); (debug_assert_matches!(*MutRefWithDrop(&mut val).0, 0), std::mem::take(&mut val)); + (debug_assert_matches!(*MutRefWithDrop(&mut val).0, 0, "msg"), std::mem::take(&mut val)); } From 6e1bb230d13bfb64948c207c77b557ce19d3f23c Mon Sep 17 00:00:00 2001 From: romandev <84428770+romancitodev@users.noreply.github.com> Date: Tue, 28 Apr 2026 16:32:55 -0300 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20=E2=9C=8F=EF=B8=8F=20forgot=20to=20c?= =?UTF-8?q?hange=20the=20stable=20version=20for=20`assert=5Fmatches!`=20ma?= =?UTF-8?q?cro.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit a449ea5ee60c30b13efbd8338e99a8510862747e) --- library/core/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 299aa9f113bf6..90f52ecc71254 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -207,7 +207,7 @@ use prelude::rust_2024::*; #[macro_use] mod macros; -#[stable(feature = "assert_matches", since = "1.95.0")] +#[stable(feature = "assert_matches", since = "1.96.0")] pub use crate::macros::{assert_matches, debug_assert_matches}; #[unstable(feature = "derive_from", issue = "144889")] From 131939252d8c6bf2d240d626eea37331b1247d72 Mon Sep 17 00:00:00 2001 From: romandev <84428770+romancitodev@users.noreply.github.com> Date: Tue, 28 Apr 2026 16:59:56 -0300 Subject: [PATCH 4/7] fix: adding missing corrections (cherry picked from commit 910e2d2cd0d396e237622c06a8de96cce5b4b3d6) --- library/core/src/macros/mod.rs | 4 ++-- library/std/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 08a12b6447e61..5fd7766633ce8 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -164,7 +164,7 @@ macro_rules! assert_ne { /// assert_matches!(a, Some(x) if x > 100); /// // assert_matches!(a, Some(x) if x < 100); // panics /// ``` -#[stable(feature = "assert_matches", since = "1.95.0")] +#[stable(feature = "assert_matches", since = "1.96.0")] #[allow_internal_unstable(panic_internals)] #[rustc_macro_transparency = "semiopaque"] pub macro assert_matches { @@ -391,7 +391,7 @@ macro_rules! debug_assert_ne { /// debug_assert_matches!(a, Some(x) if x > 100); /// // debug_assert_matches!(a, Some(x) if x < 100); // panics /// ``` -#[stable(feature = "assert_matches", since = "1.95.0")] +#[stable(feature = "assert_matches", since = "1.96.0")] #[allow_internal_unstable(assert_matches)] #[rustc_macro_transparency = "semiopaque"] pub macro debug_assert_matches($($arg:tt)*) { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index ae19d88d8faad..feb6df13d5f53 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -731,7 +731,7 @@ pub use core::{ assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, r#try, unimplemented, unreachable, write, writeln, }; -#[stable(feature = "assert_matches", since = "1.95.0")] +#[stable(feature = "assert_matches", since = "1.96.0")] pub use core::{assert_matches, debug_assert_matches}; // Re-export unstable derive macro defined through core. From b7085f62e187e41b3b6731b2b9f0d891c92f26a1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 19 Apr 2026 13:32:40 +0200 Subject: [PATCH 5/7] codegen-options docs: remove -Csoft-float (cherry picked from commit 02a898206954e96b0a12171042427cace253169c) --- src/doc/rustc/src/codegen-options/index.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index f0f991ed0c909..7af10298470ee 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -655,16 +655,6 @@ deleted once compilation finishes. It takes one of the following values: * `y`, `yes`, `on`, `true` or no value: save temporary files. * `n`, `no`, `off` or `false`: delete temporary files (the default). -## soft-float - -This option controls whether `rustc` generates code that emulates floating -point instructions in software. It takes one of the following values: - -* `y`, `yes`, `on`, `true` or no value: use soft floats. -* `n`, `no`, `off` or `false`: use hardware floats (the default). - -This flag only works on `*eabihf` targets and **is unsound and deprecated**. - ## split-debuginfo This option controls the emission of "split debuginfo" for debug information From 270461e77eb0ab347a20550ffbee0fe88c60f00b Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 28 Apr 2026 02:46:10 +0000 Subject: [PATCH 6/7] Fix passing paths with space into dlltool (cherry picked from commit 23c7bf054b341275b864a7882bcae1ce2ca5710e) --- compiler/rustc_codegen_ssa/src/back/archive.rs | 13 ++++++------- tests/run-make/raw-dylib-custom-dlltool/script.cmd | 2 +- .../raw-dylib/windows/dlltool-failed.rs | 1 - .../raw-dylib/windows/dlltool-failed.stderr | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index 3f12e857391b2..9b9fa737d6d8d 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -217,12 +217,10 @@ fn create_mingw_dll_import_lib( // able to control the *exact* spelling of each of the symbols that are being imported: // hence we don't want `dlltool` adding leading underscores automatically. let dlltool = find_binutils_dlltool(sess); - let temp_prefix = { - let mut path = PathBuf::from(&output_path); - path.pop(); - path.push(lib_name); - path - }; + // temp_prefix doesn't handle paths with spaces so + // use a relative path and set the current working directory + let cwd = output_path.parent().unwrap_or(output_path); + let temp_prefix = lib_name; // dlltool target architecture args from: // https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69 let (dlltool_target_arch, dlltool_target_bitness) = match &sess.target.arch { @@ -246,7 +244,8 @@ fn create_mingw_dll_import_lib( .arg(dlltool_target_bitness) .arg("--no-leading-underscore") .arg("--temp-prefix") - .arg(temp_prefix); + .arg(temp_prefix) + .current_dir(cwd); match dlltool_cmd.output() { Err(e) => { diff --git a/tests/run-make/raw-dylib-custom-dlltool/script.cmd b/tests/run-make/raw-dylib-custom-dlltool/script.cmd index 51834590be034..c88878151af48 100644 --- a/tests/run-make/raw-dylib-custom-dlltool/script.cmd +++ b/tests/run-make/raw-dylib-custom-dlltool/script.cmd @@ -1,2 +1,2 @@ -echo Called dlltool via script.cmd> actual.txt +echo Called dlltool via script.cmd> %~dp0\actual.txt dlltool.exe %* diff --git a/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs b/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs index dac878c1cd992..ae326193550bc 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs +++ b/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs @@ -7,7 +7,6 @@ //@ normalize-stderr: "[^ ]*/foo.dll_imports.lib" -> "$$LIB_FILE" //@ normalize-stderr: "-m [^ ]*" -> "$$TARGET_MACHINE" //@ normalize-stderr: "-f [^ ]*" -> "$$ASM_FLAGS" -//@ normalize-stderr: "--temp-prefix [^ ]*/foo.dll" -> "$$TEMP_PREFIX" #[link(name = "foo", kind = "raw-dylib")] extern "C" { // `@1` is an invalid name to export, as it usually indicates that something diff --git a/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.stderr b/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.stderr index 6fcb07cf3882c..b7279f23e6676 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.stderr +++ b/tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.stderr @@ -1,4 +1,4 @@ -error: dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX: +error: dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore --temp-prefix foo.dll: $DLLTOOL: Syntax error in def file $DEF_FILE:1␍ From 0a34f9d9401fc7feb5998e0c55333871ee72c589 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 28 Apr 2026 20:57:57 +0000 Subject: [PATCH 7/7] Test that raw-dylib works with whitespace paths (cherry picked from commit 6d20c98b819a008062f38ac65f5c0e8c3da840bb) --- tests/run-make/raw-dylib-whitespace/main.rs | 18 ++++++++++++++++++ tests/run-make/raw-dylib-whitespace/rmake.rs | 15 +++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/run-make/raw-dylib-whitespace/main.rs create mode 100644 tests/run-make/raw-dylib-whitespace/rmake.rs diff --git a/tests/run-make/raw-dylib-whitespace/main.rs b/tests/run-make/raw-dylib-whitespace/main.rs new file mode 100644 index 0000000000000..023c3570c3262 --- /dev/null +++ b/tests/run-make/raw-dylib-whitespace/main.rs @@ -0,0 +1,18 @@ +type BOOL = i32; + +#[cfg_attr( + target_arch = "x86", + link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated") +)] +#[cfg_attr(not(target_arch = "x86"), link(name = "bcryptprimitives", kind = "raw-dylib"))] +extern "system" { + fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL; +} + +fn main() { + let mut num: u8 = 0; + unsafe { + ProcessPrng(&mut num, 1); + } + println!("{num}"); +} diff --git a/tests/run-make/raw-dylib-whitespace/rmake.rs b/tests/run-make/raw-dylib-whitespace/rmake.rs new file mode 100644 index 0000000000000..4f90eeb055142 --- /dev/null +++ b/tests/run-make/raw-dylib-whitespace/rmake.rs @@ -0,0 +1,15 @@ +// Ensure that raw-dylib still works if the output directory contains spaces. + +//@ only-windows-gnu +//@ ignore-cross-compile +//@ needs-dlltool +// Reason: this test specifically checks the dlltool feature, +// which is only used on windows-gnu. + +use run_make_support::{rfs, rustc}; + +fn main() { + let out_dir = std::path::absolute("path with spaces").unwrap(); + rfs::create_dir_all(&out_dir); + rustc().crate_type("bin").input("main.rs").out_dir(&out_dir).env("TMP", &out_dir).run(); +}