@@ -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 ) ,
0 commit comments