Skip to content

Commit f4ac724

Browse files
authored
Merge pull request #4324 from RalfJung/rustup
Rustup
2 parents 3919c4b + 77dcd26 commit f4ac724

12 files changed

+54
-72
lines changed

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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,6 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
666666
if arg == "--extern" {
667667
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
668668
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.");
674669
} else {
675670
cmd.arg(arg);
676671
}
@@ -702,10 +697,10 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
702697
// make sure the 'miri' flag is set for rustdoc
703698
cmd.arg("--cfg").arg("miri");
704699

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

710705
debug_cmd("[cargo-miri rustdoc]", verbose, &cmd);
711706
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/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()?)

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
718ddf660e6a1802c39b4962cf7eaa4db57025ef
1+
a69bc17fb8026bdc0d24bb1896ff95f0eba1da4e

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/ui.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ fn main() -> Result<()> {
318318
let mut args = std::env::args_os();
319319

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

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

0 commit comments

Comments
 (0)