@@ -297,12 +297,6 @@ pub fn main() {
297
297
exit ( rustc_driver:: catch_with_exit_code ( move || {
298
298
let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
299
299
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
-
306
300
// Get the sysroot, looking from most specific to this invocation to the least:
307
301
// - command line
308
302
// - runtime environment
@@ -348,6 +342,29 @@ pub fn main() {
348
342
. map ( |pb| pb. to_string_lossy ( ) . to_string ( ) )
349
343
. expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" ) ;
350
344
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
+
351
368
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
352
369
// We're invoking the compiler programmatically, so we ignore this/
353
370
let wrapper_mode = orig_args. get ( 1 ) . map ( Path :: new) . and_then ( Path :: file_stem) == Some ( "rustc" . as_ref ( ) ) ;
0 commit comments