@@ -63,27 +63,37 @@ fn main() {
63
63
return ;
64
64
}
65
65
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
+
66
72
// The way rustdoc invokes rustc is indistinguishable from the way cargo invokes rustdoc by the
67
73
// arguments alone. `phase_cargo_rustdoc` sets this environment variable to let us disambiguate.
68
74
if env:: var_os ( "MIRI_CALLED_FROM_RUSTDOC" ) . is_some ( ) {
69
75
// ...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
+ }
77
92
}
78
93
79
94
return ;
80
95
}
81
96
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
- } ;
87
97
match first. as_str ( ) {
88
98
"miri" => phase_cargo_miri ( args) ,
89
99
"runner" => phase_runner ( args, RunnerPhase :: Cargo ) ,
0 commit comments