@@ -11,10 +11,18 @@ use std::{env, iter};
11
11
12
12
use crate :: phases:: * ;
13
13
14
+ /// Returns `true` if our flags look like they may be for rustdoc, i.e., this is cargo calling us to
15
+ /// be rustdoc. It's hard to be sure as cargo does not have a RUSTDOC_WRAPPER or an env var that
16
+ /// would let us get a clear signal.
17
+ fn looks_like_rustdoc ( ) -> bool {
18
+ // The `--test-run-directory` flag only exists for rustdoc and cargo always passes it. Perfect!
19
+ env:: args ( ) . any ( |arg| arg == "--test-run-directory" )
20
+ }
21
+
14
22
fn main ( ) {
15
23
// Rustc does not support non-UTF-8 arguments so we make no attempt either.
16
24
// (We do support non-UTF-8 environment variables though.)
17
- let mut args = std :: env:: args ( ) ;
25
+ let mut args = env:: args ( ) ;
18
26
// Skip binary name.
19
27
args. next ( ) . unwrap ( ) ;
20
28
@@ -91,10 +99,16 @@ fn main() {
91
99
// (see https://github.com/rust-lang/cargo/issues/10886).
92
100
phase_rustc ( args, RustcPhase :: Build )
93
101
}
94
- _ => {
95
- // Everything else must be rustdoc. But we need to get `first` "back onto the iterator",
102
+ _ if looks_like_rustdoc ( ) => {
103
+ // This is probably rustdoc. But we need to get `first` "back onto the iterator",
96
104
// it is some part of the rustdoc invocation.
97
105
phase_rustdoc ( iter:: once ( first) . chain ( args) ) ;
98
106
}
107
+ _ => {
108
+ show_error ! (
109
+ "`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\n The command-line arguments were: {:#?}" ,
110
+ Vec :: from_iter( env:: args( ) ) ,
111
+ ) ;
112
+ }
99
113
}
100
114
}
0 commit comments