Skip to content

Commit 2c12b4a

Browse files
committed
Auto merge of #141116 - RalfJung:miri-sync, r=RalfJung
Miri subtree update r? `@ghost`
2 parents a43b8d1 + bd9f1fd commit 2c12b4a

23 files changed

+69
-111
lines changed

src/tools/miri/Cargo.toml

+1-1
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

src/tools/miri/cargo-miri/Cargo.toml

+1-1
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"

src/tools/miri/cargo-miri/src/main.rs

+22-12
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),

src/tools/miri/cargo-miri/src/phases.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ 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+
// Enable cross-target doctests (for consistency between different cargo versions).
180+
cmd.arg("-Zdoctest-xcompile");
179181

180182
// *After* we set all the flags that need setting, forward everything else. Make sure to skip
181183
// `--target-dir` (which would otherwise be set twice).
@@ -666,11 +668,6 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
666668
if arg == "--extern" {
667669
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
668670
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.");
674671
} else {
675672
cmd.arg(arg);
676673
}
@@ -702,10 +699,10 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
702699
// make sure the 'miri' flag is set for rustdoc
703700
cmd.arg("--cfg").arg("miri");
704701

705-
// Make rustdoc call us back.
702+
// Make rustdoc call us back for the build.
703+
// (cargo already sets `--test-runtool` to us since we are the cargo test runner.)
706704
let cargo_miri_path = env::current_exe().expect("current executable path invalid");
707705
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
709706

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

src/tools/miri/cargo-miri/src/setup.rs

+3-5
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.

src/tools/miri/miri-script/Cargo.toml

+1-1
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.

src/tools/miri/miri-script/src/commands.rs

+5-9
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()?)

src/tools/miri/miri-script/src/util.rs

+1-1
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.

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2ad5f8607d0e192b60b130e5cc416b477b351c18
1+
a69bc17fb8026bdc0d24bb1896ff95f0eba1da4e

src/tools/miri/src/bin/miri.rs

+1-1
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/tools/miri/src/borrow_tracker/tree_borrows/diagnostics.rs

+1-1
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/tools/miri/src/diagnostics.rs

+1-2
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/tools/miri/src/lib.rs

-1
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/tools/miri/src/shims/panic.rs

+1
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,

src/tools/miri/test-cargo-miri/run-test.py

+6-11
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()

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

-12
This file was deleted.

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

+10
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+

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

-11
This file was deleted.

src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr

-22
This file was deleted.

src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fn main() {
1212
mut_raw_mut();
1313
partially_invalidate_mut();
1414
drop_after_sharing();
15-
// direct_mut_to_const_raw();
1615
two_raw();
1716
shr_and_raw();
1817
disjoint_mutable_subborrows();

src/tools/miri/tests/pass/coroutine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,18 @@ fn basic() {
183183

184184
fn smoke_resume_arg() {
185185
fn drain<G: Coroutine<R, Yield = Y> + Unpin, R, Y>(
186-
gen: &mut G,
186+
gen_: &mut G,
187187
inout: Vec<(R, CoroutineState<Y, G::Return>)>,
188188
) where
189189
Y: Debug + PartialEq,
190190
G::Return: Debug + PartialEq,
191191
{
192-
let mut gen = Pin::new(gen);
192+
let mut gen_ = Pin::new(gen_);
193193

194194
for (input, out) in inout {
195-
assert_eq!(gen.as_mut().resume(input), out);
195+
assert_eq!(gen_.as_mut().resume(input), out);
196196
// Test if the coroutine is valid (according to type invariants).
197-
let _ = unsafe { ManuallyDrop::new(ptr::read(gen.as_mut().get_unchecked_mut())) };
197+
let _ = unsafe { ManuallyDrop::new(ptr::read(gen_.as_mut().get_unchecked_mut())) };
198198
}
199199
}
200200

src/tools/miri/tests/ui.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ pub fn flagsplit(flags: &str) -> Vec<String> {
4444
fn build_native_lib() -> PathBuf {
4545
let cc = env::var("CC").unwrap_or_else(|_| "cc".into());
4646
// Target directory that we can write to.
47-
let so_target_dir =
48-
Path::new(&env::var_os("CARGO_TARGET_DIR").unwrap()).join("miri-native-lib");
47+
let so_target_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("miri-native-lib");
4948
// Create the directory if it does not already exist.
5049
std::fs::create_dir_all(&so_target_dir)
5150
.expect("Failed to create directory for shared object file");
@@ -101,7 +100,7 @@ fn miri_config(
101100
let mut config = Config {
102101
target: Some(target.to_owned()),
103102
program,
104-
out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap()).join("miri_ui"),
103+
out_dir: PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("miri_ui"),
105104
threads: std::env::var("MIRI_TEST_THREADS")
106105
.ok()
107106
.map(|threads| NonZero::new(threads.parse().unwrap()).unwrap()),
@@ -319,10 +318,10 @@ fn main() -> Result<()> {
319318
let mut args = std::env::args_os();
320319

321320
// Skip the program name and check whether this is a `./miri run-dep` invocation
322-
if let Some(first) = args.nth(1) {
323-
if first == "--miri-run-dep-mode" {
324-
return run_dep_mode(target, args);
325-
}
321+
if let Some(first) = args.nth(1)
322+
&& first == "--miri-run-dep-mode"
323+
{
324+
return run_dep_mode(target, args);
326325
}
327326

328327
ui(Mode::Pass, "tests/pass", &target, WithoutDependencies, tmpdir.path())?;

0 commit comments

Comments
 (0)