@@ -442,6 +442,9 @@ fn phase_cargo_miri(mut args: env::Args) {
442
442
let runner_env_name = format ! ( "CARGO_TARGET_{}_RUNNER" , target. to_uppercase( ) . replace( '-' , "_" ) ) ;
443
443
cmd. env ( runner_env_name, & miri_path) ;
444
444
445
+ // Set rustdoc to us as well, so we can make it do nothing (see issue #584).
446
+ cmd. env ( "RUSTDOC" , & miri_path) ;
447
+
445
448
// Run cargo.
446
449
if verbose {
447
450
cmd. env ( "MIRI_VERBOSE" , "" ) ; // This makes the other phases verbose.
@@ -571,7 +574,7 @@ fn phase_cargo_rustc(args: env::Args) {
571
574
}
572
575
}
573
576
574
- fn phase_cargo_runner ( binary : & str , binary_args : env:: Args ) {
577
+ fn phase_cargo_runner ( binary : & Path , binary_args : env:: Args ) {
575
578
let verbose = std:: env:: var_os ( "MIRI_VERBOSE" ) . is_some ( ) ;
576
579
577
580
let file = File :: open ( & binary)
@@ -659,10 +662,25 @@ fn main() {
659
662
// binary crates for later interpretation.
660
663
// - When we are executed due to CARGO_TARGET_RUNNER, we start interpretation based on the
661
664
// flags that were stored earlier.
665
+ // On top of that, we are also called as RUSTDOC, but that is just a stub currently.
662
666
match args. next ( ) . as_deref ( ) {
663
667
Some ( "miri" ) => phase_cargo_miri ( args) ,
664
668
Some ( "rustc" ) => phase_cargo_rustc ( args) ,
665
- Some ( binary) => phase_cargo_runner ( binary, args) ,
669
+ Some ( arg) => {
670
+ // We have to distinguish the "runner" and "rustfmt" cases.
671
+ // As runner, the first argument is the binary (a file that should exist, with an absolute path);
672
+ // as rustfmt, the first argument is a flag (`--something`).
673
+ let binary = Path :: new ( arg) ;
674
+ if binary. exists ( ) {
675
+ assert ! ( !arg. starts_with( "--" ) ) ; // not a flag
676
+ phase_cargo_runner ( binary, args) ;
677
+ } else if arg. starts_with ( "--" ) {
678
+ // We are rustdoc.
679
+ eprintln ! ( "Running doctests is not currently supported by Miri." )
680
+ } else {
681
+ show_error ( format ! ( "`cargo-miri` called with unexpected first argument `{}`; please only invoke this binary through `cargo miri`" , arg) ) ;
682
+ }
683
+ }
666
684
_ => show_error ( format ! ( "`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`" ) ) ,
667
685
}
668
686
}
0 commit comments