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