Skip to content

Commit b11757e

Browse files
committed
rustbuild: Cleanup global lint settings
1 parent 254f201 commit b11757e

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

src/bootstrap/bin/rustc.rs

+29-37
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,16 @@ fn main() {
9191
cmd.args(&args)
9292
.env(bootstrap::util::dylib_path_var(),
9393
env::join_paths(&dylib_path).unwrap());
94-
let mut maybe_crate = None;
9594

9695
// Get the name of the crate we're compiling, if any.
97-
let maybe_crate_name = args.windows(2)
98-
.find(|a| &*a[0] == "--crate-name")
99-
.map(|crate_name| &*crate_name[1]);
96+
let crate_name = args.windows(2)
97+
.find(|args| args[0] == "--crate-name")
98+
.and_then(|args| args[1].to_str());
10099

101-
if let Some(current_crate) = maybe_crate_name {
100+
if let Some(crate_name) = crate_name {
102101
if let Some(target) = env::var_os("RUSTC_TIME") {
103102
if target == "all" ||
104-
target.into_string().unwrap().split(",").any(|c| c.trim() == current_crate)
103+
target.into_string().unwrap().split(",").any(|c| c.trim() == crate_name)
105104
{
106105
cmd.arg("-Ztime");
107106
}
@@ -125,6 +124,17 @@ fn main() {
125124
cmd.arg(format!("-Cdebuginfo={}", debuginfo_level));
126125
}
127126

127+
if env::var_os("RUSTC_DENY_WARNINGS").is_some() &&
128+
env::var_os("RUSTC_EXTERNAL_TOOL").is_none() {
129+
cmd.arg("-Dwarnings");
130+
cmd.arg("-Drust_2018_idioms");
131+
if stage != "0" && crate_name != Some("rustc_version") && // cfg(not(bootstrap))
132+
use_internal_lints(crate_name) {
133+
cmd.arg("-Zunstable-options");
134+
cmd.arg("-Drustc::internal");
135+
}
136+
}
137+
128138
if let Some(target) = target {
129139
// The stage0 compiler has a special sysroot distinct from what we
130140
// actually downloaded, so we just always pass the `--sysroot` option.
@@ -167,9 +177,6 @@ fn main() {
167177
cmd.arg(format!("-Clinker={}", target_linker));
168178
}
169179

170-
let crate_name = maybe_crate_name.unwrap();
171-
maybe_crate = Some(crate_name);
172-
173180
// If we're compiling specifically the `panic_abort` crate then we pass
174181
// the `-C panic=abort` option. Note that we do not do this for any
175182
// other crate intentionally as this is the only crate for now that we
@@ -182,8 +189,8 @@ fn main() {
182189
// `compiler_builtins` are unconditionally compiled with panic=abort to
183190
// workaround undefined references to `rust_eh_unwind_resume` generated
184191
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
185-
if crate_name == "panic_abort" ||
186-
crate_name == "compiler_builtins" && stage != "0" {
192+
if crate_name == Some("panic_abort") ||
193+
crate_name == Some("compiler_builtins") && stage != "0" {
187194
cmd.arg("-C").arg("panic=abort");
188195
}
189196

@@ -196,7 +203,7 @@ fn main() {
196203

197204
// The compiler builtins are pretty sensitive to symbols referenced in
198205
// libcore and such, so we never compile them with debug assertions.
199-
if crate_name == "compiler_builtins" {
206+
if crate_name == Some("compiler_builtins") {
200207
cmd.arg("-C").arg("debug-assertions=no");
201208
} else {
202209
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
@@ -305,22 +312,6 @@ fn main() {
305312
}
306313
}
307314

308-
// This is required for internal lints.
309-
if let Some(crate_name) = args.windows(2).find(|a| &*a[0] == "--crate-name") {
310-
let crate_name = crate_name[1].to_string_lossy();
311-
if crate_name != "rustc_version"
312-
&& (crate_name.starts_with("rustc")
313-
|| crate_name.starts_with("syntax")
314-
|| crate_name == "arena"
315-
|| crate_name == "fmt_macros")
316-
{
317-
cmd.arg("-Zunstable-options");
318-
if stage != "0" {
319-
cmd.arg("-Wrustc::internal");
320-
}
321-
}
322-
}
323-
324315
// Force all crates compiled by this compiler to (a) be unstable and (b)
325316
// allow the `rustc_private` feature to link to other unstable crates
326317
// also in the sysroot. We also do this for host crates, since those
@@ -333,13 +324,6 @@ fn main() {
333324
cmd.arg("--cfg").arg("parallel_compiler");
334325
}
335326

336-
if env::var_os("RUSTC_DENY_WARNINGS").is_some() && env::var_os("RUSTC_EXTERNAL_TOOL").is_none()
337-
{
338-
cmd.arg("-Dwarnings");
339-
cmd.arg("-Dbare_trait_objects");
340-
cmd.arg("-Drust_2018_idioms");
341-
}
342-
343327
if verbose > 1 {
344328
eprintln!(
345329
"rustc command: {:?}={:?} {:?}",
@@ -362,7 +346,7 @@ fn main() {
362346
}
363347

364348
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() {
365-
if let Some(krate) = maybe_crate {
349+
if let Some(crate_name) = crate_name {
366350
let start = Instant::now();
367351
let status = cmd
368352
.status()
@@ -371,7 +355,7 @@ fn main() {
371355

372356
let is_test = args.iter().any(|a| a == "--test");
373357
eprintln!("[RUSTC-TIMING] {} test:{} {}.{:03}",
374-
krate.to_string_lossy(),
358+
crate_name,
375359
is_test,
376360
dur.as_secs(),
377361
dur.subsec_nanos() / 1_000_000);
@@ -390,6 +374,14 @@ fn main() {
390374
std::process::exit(code);
391375
}
392376

377+
// Rustc crates for which internal lints are in effect.
378+
fn use_internal_lints(crate_name: Option<&str>) -> bool {
379+
crate_name.map_or(false, |crate_name| {
380+
crate_name.starts_with("rustc") || crate_name.starts_with("syntax") ||
381+
["arena", "fmt_macros"].contains(&crate_name)
382+
})
383+
}
384+
393385
#[cfg(unix)]
394386
fn exec_cmd(cmd: &mut Command) -> io::Result<i32> {
395387
use std::os::unix::process::CommandExt;

0 commit comments

Comments
 (0)