@@ -181,7 +181,7 @@ pub fn main() {
181
181
return ;
182
182
}
183
183
184
- if let Some ( "clippy" ) = std:: env:: args ( ) . nth ( 1 ) . as_ref ( ) . map ( AsRef :: as_ref ) {
184
+ if "clippy" == std:: env:: args ( ) . nth ( 1 ) . as_ref ( ) . expect ( "cargo-clippy should be called with at least one argument!" ) {
185
185
// this arm is executed on the initial call to `cargo clippy`
186
186
187
187
let manifest_path_arg = std:: env:: args ( )
@@ -285,7 +285,7 @@ pub fn main() {
285
285
}
286
286
}
287
287
} else {
288
- // this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC `
288
+ // this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC_WRAPPER `
289
289
// env var set to itself
290
290
291
291
let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
@@ -310,13 +310,17 @@ pub fn main() {
310
310
} ;
311
311
312
312
rustc_driver:: in_rustc_thread ( || {
313
+ // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
314
+ // We're invoking the compiler programatically, so we ignore this/
315
+ let orig_args: Vec < String > = env:: args ( ) . skip ( 1 ) . collect ( ) ;
316
+
313
317
// this conditional check for the --sysroot flag is there so users can call
314
318
// `cargo-clippy` directly
315
319
// without having to pass --sysroot or anything
316
- let mut args: Vec < String > = if env :: args ( ) . any ( |s| s == "--sysroot" ) {
317
- env :: args ( ) . collect ( )
320
+ let mut args: Vec < String > = if orig_args . iter ( ) . any ( |s| s == "--sysroot" ) {
321
+ orig_args . clone ( )
318
322
} else {
319
- env :: args ( )
323
+ orig_args . clone ( ) . into_iter ( )
320
324
. chain ( Some ( "--sysroot" . to_owned ( ) ) )
321
325
. chain ( Some ( sys_root) )
322
326
. collect ( )
@@ -325,7 +329,7 @@ pub fn main() {
325
329
// this check ensures that dependencies are built but not linted and the final
326
330
// crate is
327
331
// linted but not built
328
- let clippy_enabled = env :: args ( ) . any ( |s| s == "--emit=metadata" ) ;
332
+ let clippy_enabled = orig_args . iter ( ) . any ( |s| s == "--emit=metadata" ) ;
329
333
330
334
if clippy_enabled {
331
335
args. extend_from_slice ( & [ "--cfg" . to_owned ( ) , r#"feature="cargo-clippy""# . to_owned ( ) ] ) ;
@@ -361,7 +365,7 @@ where
361
365
let path = std:: env:: current_exe ( ) . expect ( "current executable path invalid" ) ;
362
366
let exit_status = std:: process:: Command :: new ( "cargo" )
363
367
. args ( & args)
364
- . env ( "RUSTC " , path)
368
+ . env ( "RUSTC_WRAPPER " , path)
365
369
. spawn ( )
366
370
. expect ( "could not run cargo" )
367
371
. wait ( )
0 commit comments