Skip to content

Commit 037f568

Browse files
authored
Rollup merge of rust-lang#62438 - petrochenkov:buildwarn, r=Mark-Simulacrum
rustbuild: Cleanup global lint settings Lint settings do not depend on `if let Some(target) = target` in any way, so they are moved out of that clause. Internal lints now respect `RUSTC_DENY_WARNINGS`. Crate name treatment is cleaned up a bit. cc rust-lang#61545 @flip1995 r? @Mark-Simulacrum
2 parents c512829 + 36a5aa8 commit 037f568

File tree

1 file changed

+31
-37
lines changed

1 file changed

+31
-37
lines changed

src/bootstrap/bin/rustc.rs

+31-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,19 @@ 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+
// cfg(not(bootstrap)): Remove this during the next stage 0 compiler update.
132+
// `-Drustc::internal` is a new feature and `rustc_version` mis-reports the `stage`.
133+
let cfg_not_bootstrap = stage != "0" && crate_name != Some("rustc_version");
134+
if cfg_not_bootstrap && use_internal_lints(crate_name) {
135+
cmd.arg("-Zunstable-options");
136+
cmd.arg("-Drustc::internal");
137+
}
138+
}
139+
128140
if let Some(target) = target {
129141
// The stage0 compiler has a special sysroot distinct from what we
130142
// actually downloaded, so we just always pass the `--sysroot` option.
@@ -167,9 +179,6 @@ fn main() {
167179
cmd.arg(format!("-Clinker={}", target_linker));
168180
}
169181

170-
let crate_name = maybe_crate_name.unwrap();
171-
maybe_crate = Some(crate_name);
172-
173182
// If we're compiling specifically the `panic_abort` crate then we pass
174183
// the `-C panic=abort` option. Note that we do not do this for any
175184
// other crate intentionally as this is the only crate for now that we
@@ -182,8 +191,8 @@ fn main() {
182191
// `compiler_builtins` are unconditionally compiled with panic=abort to
183192
// workaround undefined references to `rust_eh_unwind_resume` generated
184193
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
185-
if crate_name == "panic_abort" ||
186-
crate_name == "compiler_builtins" && stage != "0" {
194+
if crate_name == Some("panic_abort") ||
195+
crate_name == Some("compiler_builtins") && stage != "0" {
187196
cmd.arg("-C").arg("panic=abort");
188197
}
189198

@@ -196,7 +205,7 @@ fn main() {
196205

197206
// The compiler builtins are pretty sensitive to symbols referenced in
198207
// libcore and such, so we never compile them with debug assertions.
199-
if crate_name == "compiler_builtins" {
208+
if crate_name == Some("compiler_builtins") {
200209
cmd.arg("-C").arg("debug-assertions=no");
201210
} else {
202211
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
@@ -305,22 +314,6 @@ fn main() {
305314
}
306315
}
307316

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-
324317
// Force all crates compiled by this compiler to (a) be unstable and (b)
325318
// allow the `rustc_private` feature to link to other unstable crates
326319
// also in the sysroot. We also do this for host crates, since those
@@ -333,13 +326,6 @@ fn main() {
333326
cmd.arg("--cfg").arg("parallel_compiler");
334327
}
335328

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-
343329
if verbose > 1 {
344330
eprintln!(
345331
"rustc command: {:?}={:?} {:?}",
@@ -362,7 +348,7 @@ fn main() {
362348
}
363349

364350
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() {
365-
if let Some(krate) = maybe_crate {
351+
if let Some(crate_name) = crate_name {
366352
let start = Instant::now();
367353
let status = cmd
368354
.status()
@@ -371,7 +357,7 @@ fn main() {
371357

372358
let is_test = args.iter().any(|a| a == "--test");
373359
eprintln!("[RUSTC-TIMING] {} test:{} {}.{:03}",
374-
krate.to_string_lossy(),
360+
crate_name,
375361
is_test,
376362
dur.as_secs(),
377363
dur.subsec_nanos() / 1_000_000);
@@ -390,6 +376,14 @@ fn main() {
390376
std::process::exit(code);
391377
}
392378

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

0 commit comments

Comments
 (0)