Skip to content

Commit 72864ed

Browse files
committed
Auto merge of #156011 - cuviper:beta-next, r=cuviper
[beta] backports - Add temporary scope to assert_matches #155431 - fix: ✏️ forgot to change the stable version for `assert_matches!` macro. #155943 - codegen-options docs: remove -Csoft-float #155514 - `dlltool`: Set the working directory to workaround `--temp-prefix` bug #155899 r? cuviper
2 parents 8489f1a + 0a34f9d commit 72864ed

11 files changed

Lines changed: 75 additions & 28 deletions

File tree

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ fn create_mingw_dll_import_lib(
217217
// able to control the *exact* spelling of each of the symbols that are being imported:
218218
// hence we don't want `dlltool` adding leading underscores automatically.
219219
let dlltool = find_binutils_dlltool(sess);
220-
let temp_prefix = {
221-
let mut path = PathBuf::from(&output_path);
222-
path.pop();
223-
path.push(lib_name);
224-
path
225-
};
220+
// temp_prefix doesn't handle paths with spaces so
221+
// use a relative path and set the current working directory
222+
let cwd = output_path.parent().unwrap_or(output_path);
223+
let temp_prefix = lib_name;
226224
// dlltool target architecture args from:
227225
// https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69
228226
let (dlltool_target_arch, dlltool_target_bitness) = match &sess.target.arch {
@@ -246,7 +244,8 @@ fn create_mingw_dll_import_lib(
246244
.arg(dlltool_target_bitness)
247245
.arg("--no-leading-underscore")
248246
.arg("--temp-prefix")
249-
.arg(temp_prefix);
247+
.arg(temp_prefix)
248+
.current_dir(cwd);
250249

251250
match dlltool_cmd.output() {
252251
Err(e) => {

library/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ use prelude::rust_2024::*;
207207
#[macro_use]
208208
mod macros;
209209

210-
#[stable(feature = "assert_matches", since = "1.95.0")]
210+
#[stable(feature = "assert_matches", since = "1.96.0")]
211211
pub use crate::macros::{assert_matches, debug_assert_matches};
212212

213213
#[unstable(feature = "derive_from", issue = "144889")]

library/core/src/macros/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ macro_rules! assert_ne {
164164
/// assert_matches!(a, Some(x) if x > 100);
165165
/// // assert_matches!(a, Some(x) if x < 100); // panics
166166
/// ```
167-
#[stable(feature = "assert_matches", since = "1.95.0")]
167+
#[stable(feature = "assert_matches", since = "1.96.0")]
168168
#[allow_internal_unstable(panic_internals)]
169169
#[rustc_macro_transparency = "semiopaque"]
170170
pub macro assert_matches {
171-
($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
171+
($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {{
172172
match $left {
173173
$( $pattern )|+ $( if $guard )? => {}
174174
ref left_val => {
@@ -179,8 +179,8 @@ pub macro assert_matches {
179179
);
180180
}
181181
}
182-
},
183-
($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => {
182+
}},
183+
($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => {{
184184
match $left {
185185
$( $pattern )|+ $( if $guard )? => {}
186186
ref left_val => {
@@ -191,7 +191,7 @@ pub macro assert_matches {
191191
);
192192
}
193193
}
194-
},
194+
}},
195195
}
196196

197197
/// Selects code at compile-time based on `cfg` predicates.
@@ -391,7 +391,7 @@ macro_rules! debug_assert_ne {
391391
/// debug_assert_matches!(a, Some(x) if x > 100);
392392
/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
393393
/// ```
394-
#[stable(feature = "assert_matches", since = "1.95.0")]
394+
#[stable(feature = "assert_matches", since = "1.96.0")]
395395
#[allow_internal_unstable(assert_matches)]
396396
#[rustc_macro_transparency = "semiopaque"]
397397
pub macro debug_assert_matches($($arg:tt)*) {

library/coretests/tests/macros.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(unused_must_use)]
22

3+
use std::{assert_matches, debug_assert_matches};
4+
35
#[allow(dead_code)]
46
trait Trait {
57
fn blah(&self);
@@ -219,3 +221,27 @@ fn _matches_does_not_trigger_non_exhaustive_omitted_patterns_lint(o: core::sync:
219221
// Ordering is a #[non_exhaustive] enum from a separate crate
220222
let _m = matches!(o, core::sync::atomic::Ordering::Relaxed);
221223
}
224+
225+
struct MutRefWithDrop<'a>(&'a mut u32);
226+
227+
// MutRefWithDrop needs to have a non-trivial drop to encounter potential lifetime issues if the
228+
// macros don't introduce a temporary scope.
229+
impl Drop for MutRefWithDrop<'_> {
230+
fn drop(&mut self) {
231+
*self.0 = u32::MAX;
232+
}
233+
}
234+
235+
#[test]
236+
fn temporary_scope_introduction() {
237+
// Fails to compile if the macros don't introduce a temporary scope, since `&mut val` would
238+
// create a second mutable borrow while `MutRefWithDrop` still holds a unique ref.
239+
// See https://github.com/rust-lang/rust/issues/154406 for reference.
240+
let mut val = 0;
241+
242+
(assert_matches!(*MutRefWithDrop(&mut val).0, 0), std::mem::take(&mut val));
243+
(assert_matches!(*MutRefWithDrop(&mut val).0, 0, "msg"), std::mem::take(&mut val));
244+
245+
(debug_assert_matches!(*MutRefWithDrop(&mut val).0, 0), std::mem::take(&mut val));
246+
(debug_assert_matches!(*MutRefWithDrop(&mut val).0, 0, "msg"), std::mem::take(&mut val));
247+
}

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ pub use core::{
731731
assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, r#try, unimplemented,
732732
unreachable, write, writeln,
733733
};
734-
#[stable(feature = "assert_matches", since = "1.95.0")]
734+
#[stable(feature = "assert_matches", since = "1.96.0")]
735735
pub use core::{assert_matches, debug_assert_matches};
736736

737737
// Re-export unstable derive macro defined through core.

src/doc/rustc/src/codegen-options/index.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,16 +655,6 @@ deleted once compilation finishes. It takes one of the following values:
655655
* `y`, `yes`, `on`, `true` or no value: save temporary files.
656656
* `n`, `no`, `off` or `false`: delete temporary files (the default).
657657

658-
## soft-float
659-
660-
This option controls whether `rustc` generates code that emulates floating
661-
point instructions in software. It takes one of the following values:
662-
663-
* `y`, `yes`, `on`, `true` or no value: use soft floats.
664-
* `n`, `no`, `off` or `false`: use hardware floats (the default).
665-
666-
This flag only works on `*eabihf` targets and **is unsound and deprecated**.
667-
668658
## split-debuginfo
669659

670660
This option controls the emission of "split debuginfo" for debug information
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
echo Called dlltool via script.cmd> actual.txt
1+
echo Called dlltool via script.cmd> %~dp0\actual.txt
22
dlltool.exe %*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type BOOL = i32;
2+
3+
#[cfg_attr(
4+
target_arch = "x86",
5+
link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated")
6+
)]
7+
#[cfg_attr(not(target_arch = "x86"), link(name = "bcryptprimitives", kind = "raw-dylib"))]
8+
extern "system" {
9+
fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
10+
}
11+
12+
fn main() {
13+
let mut num: u8 = 0;
14+
unsafe {
15+
ProcessPrng(&mut num, 1);
16+
}
17+
println!("{num}");
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Ensure that raw-dylib still works if the output directory contains spaces.
2+
3+
//@ only-windows-gnu
4+
//@ ignore-cross-compile
5+
//@ needs-dlltool
6+
// Reason: this test specifically checks the dlltool feature,
7+
// which is only used on windows-gnu.
8+
9+
use run_make_support::{rfs, rustc};
10+
11+
fn main() {
12+
let out_dir = std::path::absolute("path with spaces").unwrap();
13+
rfs::create_dir_all(&out_dir);
14+
rustc().crate_type("bin").input("main.rs").out_dir(&out_dir).env("TMP", &out_dir).run();
15+
}

tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//@ normalize-stderr: "[^ ]*/foo.dll_imports.lib" -> "$$LIB_FILE"
88
//@ normalize-stderr: "-m [^ ]*" -> "$$TARGET_MACHINE"
99
//@ normalize-stderr: "-f [^ ]*" -> "$$ASM_FLAGS"
10-
//@ normalize-stderr: "--temp-prefix [^ ]*/foo.dll" -> "$$TEMP_PREFIX"
1110
#[link(name = "foo", kind = "raw-dylib")]
1211
extern "C" {
1312
// `@1` is an invalid name to export, as it usually indicates that something

0 commit comments

Comments
 (0)