@@ -207,6 +207,7 @@ Usage:
207207
208208Common options:
209209 -h, --help Print this message
210+ --rustc Pass all args to rustc
210211 -V, --version Print version info and exit
211212
212213Other options are the same as `cargo check`.
@@ -297,12 +298,6 @@ pub fn main() {
297298 exit ( rustc_driver:: catch_with_exit_code ( move || {
298299 let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
299300
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-
306301 // Get the sysroot, looking from most specific to this invocation to the least:
307302 // - command line
308303 // - runtime environment
@@ -348,6 +343,28 @@ pub fn main() {
348343 . map ( |pb| pb. to_string_lossy ( ) . to_string ( ) )
349344 . expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" ) ;
350345
346+ // make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc"
347+ // for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver
348+ // uses
349+ if let Some ( pos) = orig_args. iter ( ) . position ( |arg| arg == "--rustc" ) {
350+ orig_args. remove ( pos) ;
351+ orig_args[ 0 ] = "rustc" . to_string ( ) ;
352+
353+ // if we call "rustc", we need to pass --sysroot here as well
354+ let mut args: Vec < String > = orig_args. clone ( ) ;
355+ if !have_sys_root_arg {
356+ args. extend ( vec ! [ "--sysroot" . into( ) , sys_root] ) ;
357+ } ;
358+
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