Skip to content

Commit 95dec9c

Browse files
committed
Auto merge of #1401 - RalfJung:cargo-miri-help, r=RalfJung
fix cargo-miri intercepting --help/--version arguments With this, `cargo miri test -- -- --help` should behave as expected and pass `--help` to the test runner. Thanks to @brson for the report.
2 parents 7f33662 + 914e483 commit 95dec9c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/bin/cargo-miri.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -401,31 +401,6 @@ path = "lib.rs"
401401
}
402402
}
403403

404-
fn main() {
405-
// Check for version and help flags even when invoked as `cargo-miri`.
406-
if std::env::args().any(|a| a == "--help" || a == "-h") {
407-
show_help();
408-
return;
409-
}
410-
if std::env::args().any(|a| a == "--version" || a == "-V") {
411-
show_version();
412-
return;
413-
}
414-
415-
if let Some("miri") = std::env::args().nth(1).as_deref() {
416-
// This arm is for when `cargo miri` is called. We call `cargo check` for each applicable target,
417-
// but with the `RUSTC` env var set to the `cargo-miri` binary so that we come back in the other branch,
418-
// and dispatch the invocations to `rustc` and `miri`, respectively.
419-
in_cargo_miri();
420-
} else if let Some("rustc") = std::env::args().nth(1).as_deref() {
421-
// This arm is executed when `cargo-miri` runs `cargo check` with the `RUSTC_WRAPPER` env var set to itself:
422-
// dependencies get dispatched to `rustc`, the final test/binary to `miri`.
423-
inside_cargo_rustc();
424-
} else {
425-
show_error(format!("must be called with either `miri` or `rustc` as first argument."))
426-
}
427-
}
428-
429404
fn in_cargo_miri() {
430405
let (subcommand, skip) = match std::env::args().nth(2).as_deref() {
431406
Some("test") => (MiriCommand::Test, 3),
@@ -593,3 +568,28 @@ fn inside_cargo_rustc() {
593568
Err(e) => panic!("error running {:?}:\n{:?}", command, e),
594569
}
595570
}
571+
572+
fn main() {
573+
// Check for version and help flags even when invoked as `cargo-miri`.
574+
if has_arg_flag("--help") || has_arg_flag("-h") {
575+
show_help();
576+
return;
577+
}
578+
if has_arg_flag("--version") || has_arg_flag("-V") {
579+
show_version();
580+
return;
581+
}
582+
583+
if let Some("miri") = std::env::args().nth(1).as_deref() {
584+
// This arm is for when `cargo miri` is called. We call `cargo check` for each applicable target,
585+
// but with the `RUSTC` env var set to the `cargo-miri` binary so that we come back in the other branch,
586+
// and dispatch the invocations to `rustc` and `miri`, respectively.
587+
in_cargo_miri();
588+
} else if let Some("rustc") = std::env::args().nth(1).as_deref() {
589+
// This arm is executed when `cargo-miri` runs `cargo check` with the `RUSTC_WRAPPER` env var set to itself:
590+
// dependencies get dispatched to `rustc`, the final test/binary to `miri`.
591+
inside_cargo_rustc();
592+
} else {
593+
show_error(format!("must be called with either `miri` or `rustc` as first argument."))
594+
}
595+
}

0 commit comments

Comments
 (0)