@@ -23,8 +23,8 @@ use std::borrow::Cow;
23
23
use std:: env;
24
24
use std:: ops:: Deref ;
25
25
use std:: panic;
26
- use std:: path:: { Path , PathBuf } ;
27
- use std:: process:: { exit, Command } ;
26
+ use std:: path:: Path ;
27
+ use std:: process:: exit;
28
28
use std:: sync:: LazyLock ;
29
29
30
30
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
@@ -209,83 +209,21 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
209
209
interface:: try_print_query_stack ( & handler, num_frames) ;
210
210
}
211
211
212
- fn toolchain_path ( home : Option < String > , toolchain : Option < String > ) -> Option < PathBuf > {
213
- home. and_then ( |home| {
214
- toolchain. map ( |toolchain| {
215
- let mut path = PathBuf :: from ( home) ;
216
- path. push ( "toolchains" ) ;
217
- path. push ( toolchain) ;
218
- path
219
- } )
220
- } )
221
- }
222
-
223
212
#[ allow( clippy:: too_many_lines) ]
224
213
pub fn main ( ) {
225
214
rustc_driver:: init_rustc_env_logger ( ) ;
226
215
LazyLock :: force ( & ICE_HOOK ) ;
227
216
exit ( rustc_driver:: catch_with_exit_code ( move || {
228
217
let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
229
218
230
- // Get the sysroot, looking from most specific to this invocation to the least:
231
- // - command line
232
- // - runtime environment
233
- // - SYSROOT
234
- // - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
235
- // - sysroot from rustc in the path
236
- // - compile-time environment
237
- // - SYSROOT
238
- // - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
239
- let sys_root_arg = arg_value ( & orig_args, "--sysroot" , |_| true ) ;
240
- let have_sys_root_arg = sys_root_arg. is_some ( ) ;
241
- let sys_root = sys_root_arg
242
- . map ( PathBuf :: from)
243
- . or_else ( || std:: env:: var ( "SYSROOT" ) . ok ( ) . map ( PathBuf :: from) )
244
- . or_else ( || {
245
- let home = std:: env:: var ( "RUSTUP_HOME" )
246
- . or_else ( |_| std:: env:: var ( "MULTIRUST_HOME" ) )
247
- . ok ( ) ;
248
- let toolchain = std:: env:: var ( "RUSTUP_TOOLCHAIN" )
249
- . or_else ( |_| std:: env:: var ( "MULTIRUST_TOOLCHAIN" ) )
250
- . ok ( ) ;
251
- toolchain_path ( home, toolchain)
252
- } )
253
- . or_else ( || {
254
- Command :: new ( "rustc" )
255
- . arg ( "--print" )
256
- . arg ( "sysroot" )
257
- . output ( )
258
- . ok ( )
259
- . and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
260
- . map ( |s| PathBuf :: from ( s. trim ( ) ) )
261
- } )
262
- . or_else ( || option_env ! ( "SYSROOT" ) . map ( PathBuf :: from) )
263
- . or_else ( || {
264
- let home = option_env ! ( "RUSTUP_HOME" )
265
- . or ( option_env ! ( "MULTIRUST_HOME" ) )
266
- . map ( ToString :: to_string) ;
267
- let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" )
268
- . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) )
269
- . map ( ToString :: to_string) ;
270
- toolchain_path ( home, toolchain)
271
- } )
272
- . map ( |pb| pb. to_string_lossy ( ) . to_string ( ) )
273
- . expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" ) ;
274
-
275
219
// make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc"
276
220
// for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver
277
221
// uses
278
222
if let Some ( pos) = orig_args. iter ( ) . position ( |arg| arg == "--rustc" ) {
279
223
orig_args. remove ( pos) ;
280
224
orig_args[ 0 ] = "rustc" . to_string ( ) ;
281
225
282
- // if we call "rustc", we need to pass --sysroot here as well
283
- let mut args: Vec < String > = orig_args. clone ( ) ;
284
- if !have_sys_root_arg {
285
- args. extend ( vec ! [ "--sysroot" . into( ) , sys_root] ) ;
286
- } ;
287
-
288
- return rustc_driver:: RunCompiler :: new ( & args, & mut DefaultCallbacks ) . run ( ) ;
226
+ return rustc_driver:: RunCompiler :: new ( & orig_args, & mut DefaultCallbacks ) . run ( ) ;
289
227
}
290
228
291
229
if orig_args. iter ( ) . any ( |a| a == "--version" || a == "-V" ) {
@@ -308,14 +246,6 @@ pub fn main() {
308
246
exit ( 0 ) ;
309
247
}
310
248
311
- // this conditional check for the --sysroot flag is there so users can call
312
- // `clippy_driver` directly
313
- // without having to pass --sysroot or anything
314
- let mut args: Vec < String > = orig_args. clone ( ) ;
315
- if !have_sys_root_arg {
316
- args. extend ( vec ! [ "--sysroot" . into( ) , sys_root] ) ;
317
- } ;
318
-
319
249
let mut no_deps = false ;
320
250
let clippy_args_var = env:: var ( "CLIPPY_ARGS" ) . ok ( ) ;
321
251
let clippy_args = clippy_args_var
@@ -344,10 +274,11 @@ pub fn main() {
344
274
345
275
let clippy_enabled = !cap_lints_allow && ( !no_deps || in_primary_package) ;
346
276
if clippy_enabled {
277
+ let mut args: Vec < String > = orig_args. clone ( ) ;
347
278
args. extend ( clippy_args) ;
348
279
rustc_driver:: RunCompiler :: new ( & args, & mut ClippyCallbacks { clippy_args_var } ) . run ( )
349
280
} else {
350
- rustc_driver:: RunCompiler :: new ( & args , & mut RustcCallbacks { clippy_args_var } ) . run ( )
281
+ rustc_driver:: RunCompiler :: new ( & orig_args , & mut RustcCallbacks { clippy_args_var } ) . run ( )
351
282
}
352
283
} ) )
353
284
}
0 commit comments