Skip to content

Commit 002bfd6

Browse files
authored
Merge pull request #2392 from rust-lang/rustc-pull
Rustc pull update
2 parents 56c7e1a + eb422b5 commit 002bfd6

File tree

66 files changed

+148
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+148
-174
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "miri"
66
repository = "https://github.com/rust-lang/miri"
77
version = "0.1.0"
88
default-run = "miri"
9-
edition = "2021"
9+
edition = "2024"
1010

1111
[lib]
1212
test = true # we have unit tests

cargo-miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT OR Apache-2.0"
55
name = "cargo-miri"
66
repository = "https://github.com/rust-lang/miri"
77
version = "0.1.0"
8-
edition = "2021"
8+
edition = "2024"
99

1010
[[bin]]
1111
name = "cargo-miri"

cargo-miri/src/main.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,37 @@ fn main() {
6363
return;
6464
}
6565

66+
let Some(first) = args.next() else {
67+
show_error!(
68+
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
69+
)
70+
};
71+
6672
// The way rustdoc invokes rustc is indistinguishable from the way cargo invokes rustdoc by the
6773
// arguments alone. `phase_cargo_rustdoc` sets this environment variable to let us disambiguate.
6874
if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() {
6975
// ...however, we then also see this variable when rustdoc invokes us as the testrunner!
70-
// The runner is invoked as `$runtool ($runtool-arg)* output_file`;
71-
// since we don't specify any runtool-args, and rustdoc supplies multiple arguments to
72-
// the test-builder unconditionally, we can just check the number of remaining arguments:
73-
if args.len() == 1 {
74-
phase_runner(args, RunnerPhase::Rustdoc);
75-
} else {
76-
phase_rustc(args, RustcPhase::Rustdoc);
76+
// In that case the first argument is `runner` and there are no more arguments.
77+
match first.as_str() {
78+
"runner" => phase_runner(args, RunnerPhase::Rustdoc),
79+
flag if flag.starts_with("--") || flag.starts_with("@") => {
80+
// This is probably rustdoc invoking us to build the test. But we need to get `first`
81+
// "back onto the iterator", it is some part of the rustc invocation.
82+
phase_rustc(iter::once(first).chain(args), RustcPhase::Rustdoc);
83+
}
84+
_ => {
85+
show_error!(
86+
"`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\n\
87+
We are inside MIRI_CALLED_FROM_RUSTDOC.\n\
88+
The command-line arguments were: {:#?}",
89+
Vec::from_iter(env::args()),
90+
);
91+
}
7792
}
7893

7994
return;
8095
}
8196

82-
let Some(first) = args.next() else {
83-
show_error!(
84-
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
85-
)
86-
};
8797
match first.as_str() {
8898
"miri" => phase_cargo_miri(args),
8999
"runner" => phase_runner(args, RunnerPhase::Cargo),

cargo-miri/src/phases.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
176176
// Set `--target-dir` to `miri` inside the original target directory.
177177
let target_dir = get_target_dir(&metadata);
178178
cmd.arg("--target-dir").arg(target_dir);
179+
// Only when running in x.py (where we are running with beta cargo): set `RUSTC_STAGE`.
180+
// Will have to be removed on next bootstrap bump. tag: cfg(bootstrap).
181+
if env::var_os("RUSTC_STAGE").is_some() {
182+
cmd.arg("-Zdoctest-xcompile");
183+
}
179184

180185
// *After* we set all the flags that need setting, forward everything else. Make sure to skip
181186
// `--target-dir` (which would otherwise be set twice).
@@ -666,11 +671,6 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
666671
if arg == "--extern" {
667672
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
668673
forward_patched_extern_arg(&mut args, &mut cmd);
669-
} else if arg == "--test-runtool" {
670-
// An existing --test-runtool flag indicates cargo is running in cross-target mode, which we don't support.
671-
// Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag;
672-
// otherwise, we won't be called as rustdoc at all.
673-
show_error!("cross-interpreting doctests is not currently supported by Miri.");
674674
} else {
675675
cmd.arg(arg);
676676
}
@@ -702,10 +702,10 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
702702
// make sure the 'miri' flag is set for rustdoc
703703
cmd.arg("--cfg").arg("miri");
704704

705-
// Make rustdoc call us back.
705+
// Make rustdoc call us back for the build.
706+
// (cargo already sets `--test-runtool` to us since we are the cargo test runner.)
706707
let cargo_miri_path = env::current_exe().expect("current executable path invalid");
707708
cmd.arg("--test-builder").arg(&cargo_miri_path); // invoked by forwarding most arguments
708-
cmd.arg("--test-runtool").arg(&cargo_miri_path); // invoked with just a single path argument
709709

710710
debug_cmd("[cargo-miri rustdoc]", verbose, &cmd);
711711
exec(cmd)

cargo-miri/src/setup.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ pub fn setup(
2424
let ask_user = !only_setup;
2525
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
2626
let show_setup = only_setup && !print_sysroot;
27-
if !only_setup {
28-
if let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
29-
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
30-
return sysroot.into();
31-
}
27+
if !only_setup && let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
28+
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
29+
return sysroot.into();
3230
}
3331

3432
// Determine where the rust sources are located. The env var trumps auto-detection.

miri-script/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "miri-script"
66
repository = "https://github.com/rust-lang/miri"
77
version = "0.1.0"
88
default-run = "miri-script"
9-
edition = "2021"
9+
edition = "2024"
1010

1111
[workspace]
1212
# We make this a workspace root so that cargo does not go looking in ../Cargo.toml for the workspace root.

miri-script/src/commands.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,9 @@ impl Command {
675675
let mut early_flags = Vec::<OsString>::new();
676676

677677
// In `dep` mode, the target is already passed via `MIRI_TEST_TARGET`
678-
if !dep {
679-
if let Some(target) = &target {
680-
early_flags.push("--target".into());
681-
early_flags.push(target.into());
682-
}
678+
if !dep && let Some(target) = &target {
679+
early_flags.push("--target".into());
680+
early_flags.push(target.into());
683681
}
684682
early_flags.push("--edition".into());
685683
early_flags.push(edition.as_deref().unwrap_or("2021").into());
@@ -707,10 +705,8 @@ impl Command {
707705
// Add Miri flags
708706
let mut cmd = cmd.args(&miri_flags).args(&early_flags).args(&flags);
709707
// For `--dep` we also need to set the target in the env var.
710-
if dep {
711-
if let Some(target) = &target {
712-
cmd = cmd.env("MIRI_TEST_TARGET", target);
713-
}
708+
if dep && let Some(target) = &target {
709+
cmd = cmd.env("MIRI_TEST_TARGET", target);
714710
}
715711
// Finally, run the thing.
716712
Ok(cmd.run()?)

miri-script/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl MiriEnv {
213213
let toolchain = &self.toolchain;
214214
let mut cmd = cmd!(
215215
self.sh,
216-
"rustfmt +{toolchain} --edition=2021 --config-path {config_path} --unstable-features --skip-children {flags...}"
216+
"rustfmt +{toolchain} --edition=2024 --config-path {config_path} --unstable-features --skip-children {flags...}"
217217
);
218218
if first {
219219
// Log an abbreviating command, and only once.

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2ad5f8607d0e192b60b130e5cc416b477b351c18
1+
ac17c3486c6fdfbb0c3c18b99f3d8dfbff625d29

src/bin/miri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ fn jemalloc_magic() {
459459
// linking, so we need to explicitly depend on the function.
460460
#[cfg(target_os = "macos")]
461461
{
462-
extern "C" {
462+
unsafe extern "C" {
463463
fn _rjem_je_zone_register();
464464
}
465465

src/borrow_tracker/tree_borrows/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl NodeDebugInfo {
179179
/// Add a name to the tag. If a same tag is associated to several pointers,
180180
/// it can have several names which will be separated by commas.
181181
pub fn add_name(&mut self, name: &str) {
182-
if let Some(ref mut prev_name) = &mut self.name {
182+
if let Some(prev_name) = &mut self.name {
183183
prev_name.push_str(", ");
184184
prev_name.push_str(name);
185185
} else {

src/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,7 @@ impl<'tcx> MiriMachine<'tcx> {
648648
AccessedAlloc(AllocId(id), access_kind) =>
649649
format!("{access_kind} to allocation with id {id}"),
650650
FreedAlloc(AllocId(id)) => format!("freed allocation with id {id}"),
651-
RejectedIsolatedOp(ref op) =>
652-
format!("{op} was made to return an error due to isolation"),
651+
RejectedIsolatedOp(op) => format!("{op} was made to return an error due to isolation"),
653652
ProgressReport { .. } =>
654653
format!("progress report: current operation being executed is here"),
655654
Int2Ptr { .. } => format!("integer-to-pointer cast"),

src/helpers.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -932,12 +932,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
932932
self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi)
933933
}
934934

935-
/// Check that the ABI is what we expect.
936-
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
935+
/// Check that the calling convention is what we expect.
936+
fn check_callconv<'a>(
937+
&self,
938+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
939+
exp_abi: Conv,
940+
) -> InterpResult<'a, ()> {
937941
if fn_abi.conv != exp_abi {
938942
throw_ub_format!(
939-
"calling a function with ABI {:?} using caller ABI {:?}",
940-
exp_abi,
943+
"calling a function with calling convention {exp_abi} using caller calling convention {}",
941944
fn_abi.conv
942945
);
943946
}
@@ -973,7 +976,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
973976
exp_abi: Conv,
974977
link_name: Symbol,
975978
) -> InterpResult<'tcx, ()> {
976-
self.check_abi(abi, exp_abi)?;
979+
self.check_callconv(abi, exp_abi)?;
977980
if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
978981
// If compiler-builtins is providing the symbol, then don't treat it as a clash.
979982
// We'll use our built-in implementation in `emulate_foreign_item_inner` for increased

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#![feature(variant_count)]
1010
#![feature(yeet_expr)]
1111
#![feature(nonzero_ops)]
12-
#![feature(let_chains)]
1312
#![feature(strict_overflow_ops)]
1413
#![feature(pointer_is_aligned_to)]
1514
#![feature(unqualified_local_imports)]

src/shims/native_lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
117117
let mut info = std::mem::MaybeUninit::<libc::Dl_info>::uninit();
118118
unsafe {
119119
if libc::dladdr(*func.deref() as *const _, info.as_mut_ptr()) != 0 {
120-
if std::ffi::CStr::from_ptr(info.assume_init().dli_fname).to_str().unwrap()
120+
let info = info.assume_init();
121+
#[cfg(target_os = "cygwin")]
122+
let fname_ptr = info.dli_fname.as_ptr();
123+
#[cfg(not(target_os = "cygwin"))]
124+
let fname_ptr = info.dli_fname;
125+
if std::ffi::CStr::from_ptr(fname_ptr).to_str().unwrap()
121126
!= _lib_path.to_str().unwrap()
122127
{
123128
return None;

src/shims/panic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8585
// Now we make a function call, and pass `data` as first and only argument.
8686
let f_instance = this.get_ptr_fn(try_fn)?.as_instance()?;
8787
trace!("try_fn: {:?}", f_instance);
88+
#[allow(clippy::cloned_ref_to_slice_refs)] // the code is clearer as-is
8889
this.call_function(
8990
f_instance,
9091
ExternAbi::Rust,

test-cargo-miri/run-test.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,19 @@ def test_cargo_miri_run():
142142
)
143143

144144
def test_cargo_miri_test():
145-
# rustdoc is not run on foreign targets
146-
is_foreign = ARGS.target is not None
147-
default_ref = "test.cross-target.stdout.ref" if is_foreign else "test.default.stdout.ref"
148-
filter_ref = "test.filter.cross-target.stdout.ref" if is_foreign else "test.filter.stdout.ref"
149-
150145
test("`cargo miri test`",
151146
cargo_miri("test"),
152-
default_ref, "test.empty.ref",
147+
"test.default.stdout.ref", "test.empty.ref",
153148
env={'MIRIFLAGS': "-Zmiri-seed=4242"},
154149
)
155150
test("`cargo miri test` (no isolation, no doctests)",
156151
cargo_miri("test") + ["--bins", "--tests"], # no `--lib`, we disabled that in `Cargo.toml`
157-
"test.cross-target.stdout.ref", "test.empty.ref",
152+
"test.no-doc.stdout.ref", "test.empty.ref",
158153
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
159154
)
160155
test("`cargo miri test` (with filter)",
161156
cargo_miri("test") + ["--", "--format=pretty", "pl"],
162-
filter_ref, "test.empty.ref",
157+
"test.filter.stdout.ref", "test.empty.ref",
163158
)
164159
test("`cargo miri test` (test target)",
165160
cargo_miri("test") + ["--test", "test", "--", "--format=pretty"],
@@ -171,7 +166,7 @@ def test_cargo_miri_test():
171166
)
172167
test("`cargo miri t` (subcrate, no isolation)",
173168
cargo_miri("t") + ["-p", "subcrate"],
174-
"test.subcrate.cross-target.stdout.ref" if is_foreign else "test.subcrate.stdout.ref",
169+
"test.subcrate.stdout.ref",
175170
"test.empty.ref",
176171
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
177172
)
@@ -181,12 +176,12 @@ def test_cargo_miri_test():
181176
)
182177
test("`cargo miri test` (custom target dir)",
183178
cargo_miri("test") + ["--target-dir=custom-test"],
184-
default_ref, "test.empty.ref",
179+
"test.default.stdout.ref", "test.empty.ref",
185180
)
186181
del os.environ["CARGO_TARGET_DIR"] # this overrides `build.target-dir` passed by `--config`, so unset it
187182
test("`cargo miri test` (config-cli)",
188183
cargo_miri("test") + ["--config=build.target-dir=\"config-cli\""],
189-
default_ref, "test.empty.ref",
184+
"test.default.stdout.ref", "test.empty.ref",
190185
)
191186
if ARGS.multi_target:
192187
test_cargo_miri_multi_target()

test-cargo-miri/test.filter.cross-target.stdout.ref

Lines changed: 0 additions & 12 deletions
This file was deleted.

test-cargo-miri/test.multiple_targets.stdout.ref

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ running 6 tests
2020
...i..
2121
test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME
2222

23+
24+
running 5 tests
25+
.....
26+
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
27+
28+
29+
running 5 tests
30+
.....
31+
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
32+

test-cargo-miri/test.subcrate.cross-target.stdout.ref

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/fail/alloc/alloc_error_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@error-in-other-file: aborted
2-
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\);" -> "ABORT();"
2+
//@normalize-stderr-test: "\|.*::abort\(\).*" -> "| ABORT()"
33
//@normalize-stderr-test: "\| +\^+" -> "| ^"
44
#![feature(allocator_api)]
55

tests/fail/alloc/alloc_error_handler.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ memory allocation of 4 bytes failed
22
error: abnormal termination: the program aborted execution
33
--> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
44
|
5-
LL | ABORT();
5+
LL | ABORT()
66
| ^ the program aborted execution
77
|
88
= note: BACKTRACE:

tests/fail/function_calls/check_arg_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ fn main() {
44
}
55

66
unsafe {
7-
let _ = malloc(0); //~ ERROR: calling a function with ABI C using caller ABI Rust
7+
let _ = malloc(0); //~ ERROR: calling a function with calling convention "C" using caller calling convention "Rust"
88
};
99
}

tests/fail/function_calls/check_arg_abi.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: calling a function with ABI C using caller ABI Rust
1+
error: Undefined Behavior: calling a function with calling convention "C" using caller calling convention "Rust"
22
--> tests/fail/function_calls/check_arg_abi.rs:LL:CC
33
|
44
LL | let _ = malloc(0);
5-
| ^^^^^^^^^ calling a function with ABI C using caller ABI Rust
5+
| ^^^^^^^^^ calling a function with calling convention "C" using caller calling convention "Rust"
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/fail/function_calls/check_callback_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
// Make sure we check the ABI when Miri itself invokes a function
1010
// as part of a shim implementation.
1111
std::intrinsics::catch_unwind(
12-
//~^ ERROR: calling a function with calling convention C using calling convention Rust
12+
//~^ ERROR: calling a function with calling convention "C" using calling convention "Rust"
1313
std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
1414
std::ptr::null_mut(),
1515
|_, _| unreachable!(),

0 commit comments

Comments
 (0)