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