Skip to content

Commit 857ae23

Browse files
committed
clippy-driver: pass all args after "--rustc" to rustc.
1 parent 9f9877c commit 857ae23

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/driver.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ pub fn main() {
297297
exit(rustc_driver::catch_with_exit_code(move || {
298298
let mut orig_args: Vec<String> = env::args().collect();
299299

300-
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
301-
let version_info = rustc_tools_util::get_version_info!();
302-
println!("{}", version_info);
303-
exit(0);
304-
}
305-
306300
// Get the sysroot, looking from most specific to this invocation to the least:
307301
// - command line
308302
// - runtime environment
@@ -348,6 +342,29 @@ pub fn main() {
348342
.map(|pb| pb.to_string_lossy().to_string())
349343
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
350344

345+
// make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc"
346+
// for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver
347+
// uses
348+
if let Some(pos) = orig_args.iter().position(|arg| arg == "--rustc") {
349+
orig_args.remove(pos);
350+
orig_args[0] = "rustc".to_string();
351+
352+
// if we call "rustc", we need to pass --sysroot here as well
353+
let mut args: Vec<String> = orig_args.clone();
354+
if !have_sys_root_arg {
355+
args.extend(vec!["--sysroot".into(), sys_root]);
356+
};
357+
358+
println!("args: {:?}", args);
359+
return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None);
360+
}
361+
362+
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
363+
let version_info = rustc_tools_util::get_version_info!();
364+
println!("{}", version_info);
365+
exit(0);
366+
}
367+
351368
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
352369
// We're invoking the compiler programmatically, so we ignore this/
353370
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());

0 commit comments

Comments
 (0)