Skip to content

Commit 7f317b7

Browse files
committed
Run fmt
1 parent 404ae5b commit 7f317b7

File tree

1 file changed

+110
-112
lines changed

1 file changed

+110
-112
lines changed

src/driver.rs

Lines changed: 110 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -295,121 +295,119 @@ fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<Pat
295295
pub fn main() {
296296
rustc_driver::init_rustc_env_logger();
297297
lazy_static::initialize(&ICE_HOOK);
298-
exit(
299-
rustc_driver::catch_with_exit_code(move || {
300-
let mut orig_args: Vec<String> = env::args().collect();
301-
302-
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
303-
let version_info = rustc_tools_util::get_version_info!();
304-
println!("{}", version_info);
305-
exit(0);
306-
}
298+
exit(rustc_driver::catch_with_exit_code(move || {
299+
let mut orig_args: Vec<String> = env::args().collect();
307300

308-
// Get the sysroot, looking from most specific to this invocation to the least:
309-
// - command line
310-
// - runtime environment
311-
// - SYSROOT
312-
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
313-
// - sysroot from rustc in the path
314-
// - compile-time environment
315-
// - SYSROOT
316-
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
317-
let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true);
318-
let have_sys_root_arg = sys_root_arg.is_some();
319-
let sys_root = sys_root_arg
320-
.map(PathBuf::from)
321-
.or_else(|| std::env::var("SYSROOT").ok().map(PathBuf::from))
322-
.or_else(|| {
323-
let home = std::env::var("RUSTUP_HOME")
324-
.or_else(|_| std::env::var("MULTIRUST_HOME"))
325-
.ok();
326-
let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
327-
.or_else(|_| std::env::var("MULTIRUST_TOOLCHAIN"))
328-
.ok();
329-
toolchain_path(home, toolchain)
330-
})
331-
.or_else(|| {
332-
Command::new("rustc")
333-
.arg("--print")
334-
.arg("sysroot")
335-
.output()
336-
.ok()
337-
.and_then(|out| String::from_utf8(out.stdout).ok())
338-
.map(|s| PathBuf::from(s.trim()))
339-
})
340-
.or_else(|| option_env!("SYSROOT").map(PathBuf::from))
341-
.or_else(|| {
342-
let home = option_env!("RUSTUP_HOME")
343-
.or(option_env!("MULTIRUST_HOME"))
344-
.map(ToString::to_string);
345-
let toolchain = option_env!("RUSTUP_TOOLCHAIN")
346-
.or(option_env!("MULTIRUST_TOOLCHAIN"))
347-
.map(ToString::to_string);
348-
toolchain_path(home, toolchain)
349-
})
350-
.map(|pb| pb.to_string_lossy().to_string())
351-
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
352-
353-
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
354-
// We're invoking the compiler programmatically, so we ignore this/
355-
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
356-
357-
if wrapper_mode {
358-
// we still want to be able to invoke it normally though
359-
orig_args.remove(1);
360-
}
301+
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
302+
let version_info = rustc_tools_util::get_version_info!();
303+
println!("{}", version_info);
304+
exit(0);
305+
}
361306

362-
if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
363-
display_help();
364-
exit(0);
365-
}
307+
// Get the sysroot, looking from most specific to this invocation to the least:
308+
// - command line
309+
// - runtime environment
310+
// - SYSROOT
311+
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
312+
// - sysroot from rustc in the path
313+
// - compile-time environment
314+
// - SYSROOT
315+
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
316+
let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true);
317+
let have_sys_root_arg = sys_root_arg.is_some();
318+
let sys_root = sys_root_arg
319+
.map(PathBuf::from)
320+
.or_else(|| std::env::var("SYSROOT").ok().map(PathBuf::from))
321+
.or_else(|| {
322+
let home = std::env::var("RUSTUP_HOME")
323+
.or_else(|_| std::env::var("MULTIRUST_HOME"))
324+
.ok();
325+
let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
326+
.or_else(|_| std::env::var("MULTIRUST_TOOLCHAIN"))
327+
.ok();
328+
toolchain_path(home, toolchain)
329+
})
330+
.or_else(|| {
331+
Command::new("rustc")
332+
.arg("--print")
333+
.arg("sysroot")
334+
.output()
335+
.ok()
336+
.and_then(|out| String::from_utf8(out.stdout).ok())
337+
.map(|s| PathBuf::from(s.trim()))
338+
})
339+
.or_else(|| option_env!("SYSROOT").map(PathBuf::from))
340+
.or_else(|| {
341+
let home = option_env!("RUSTUP_HOME")
342+
.or(option_env!("MULTIRUST_HOME"))
343+
.map(ToString::to_string);
344+
let toolchain = option_env!("RUSTUP_TOOLCHAIN")
345+
.or(option_env!("MULTIRUST_TOOLCHAIN"))
346+
.map(ToString::to_string);
347+
toolchain_path(home, toolchain)
348+
})
349+
.map(|pb| pb.to_string_lossy().to_string())
350+
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
366351

367-
let should_describe_lints = || {
368-
let args: Vec<_> = env::args().collect();
369-
args.windows(2).any(|args| {
370-
args[1] == "help"
371-
&& match args[0].as_str() {
372-
"-W" | "-A" | "-D" | "-F" => true,
373-
_ => false,
374-
}
375-
})
376-
};
377-
378-
if !wrapper_mode && should_describe_lints() {
379-
describe_lints();
380-
exit(0);
381-
}
352+
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
353+
// We're invoking the compiler programmatically, so we ignore this/
354+
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
355+
356+
if wrapper_mode {
357+
// we still want to be able to invoke it normally though
358+
orig_args.remove(1);
359+
}
360+
361+
if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
362+
display_help();
363+
exit(0);
364+
}
365+
366+
let should_describe_lints = || {
367+
let args: Vec<_> = env::args().collect();
368+
args.windows(2).any(|args| {
369+
args[1] == "help"
370+
&& match args[0].as_str() {
371+
"-W" | "-A" | "-D" | "-F" => true,
372+
_ => false,
373+
}
374+
})
375+
};
382376

383-
// this conditional check for the --sysroot flag is there so users can call
384-
// `clippy_driver` directly
385-
// without having to pass --sysroot or anything
386-
let mut args: Vec<String> = orig_args.clone();
387-
if !have_sys_root_arg {
388-
args.extend(vec!["--sysroot".into(), sys_root]);
389-
};
390-
391-
// this check ensures that dependencies are built but not linted and the final
392-
// crate is linted but not built
393-
let clippy_enabled = env::var("CLIPPY_TESTS").map_or(false, |val| val == "true")
394-
|| arg_value(&orig_args, "--cap-lints", |val| val == "allow").is_none();
395-
396-
if clippy_enabled {
397-
args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
398-
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
399-
args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
400-
if s.is_empty() {
401-
None
402-
} else {
403-
Some(s.to_string())
404-
}
405-
}));
406-
}
377+
if !wrapper_mode && should_describe_lints() {
378+
describe_lints();
379+
exit(0);
380+
}
381+
382+
// this conditional check for the --sysroot flag is there so users can call
383+
// `clippy_driver` directly
384+
// without having to pass --sysroot or anything
385+
let mut args: Vec<String> = orig_args.clone();
386+
if !have_sys_root_arg {
387+
args.extend(vec!["--sysroot".into(), sys_root]);
388+
};
389+
390+
// this check ensures that dependencies are built but not linted and the final
391+
// crate is linted but not built
392+
let clippy_enabled = env::var("CLIPPY_TESTS").map_or(false, |val| val == "true")
393+
|| arg_value(&orig_args, "--cap-lints", |val| val == "allow").is_none();
394+
395+
if clippy_enabled {
396+
args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
397+
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
398+
args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
399+
if s.is_empty() {
400+
None
401+
} else {
402+
Some(s.to_string())
403+
}
404+
}));
407405
}
408-
let mut clippy = ClippyCallbacks;
409-
let mut default = DefaultCallbacks;
410-
let callbacks: &mut (dyn rustc_driver::Callbacks + Send) =
411-
if clippy_enabled { &mut clippy } else { &mut default };
412-
rustc_driver::run_compiler(&args, callbacks, None, None)
413-
})
414-
)
406+
}
407+
let mut clippy = ClippyCallbacks;
408+
let mut default = DefaultCallbacks;
409+
let callbacks: &mut (dyn rustc_driver::Callbacks + Send) =
410+
if clippy_enabled { &mut clippy } else { &mut default };
411+
rustc_driver::run_compiler(&args, callbacks, None, None)
412+
}))
415413
}

0 commit comments

Comments
 (0)