Skip to content

Commit 43e994c

Browse files
committed
Auto merge of #49715 - Mark-Simulacrum:deny-warnings, r=alexcrichton
Move deny(warnings) into rustbuild This permits easier iteration without having to worry about warnings being denied. Fixes #49517
2 parents 88ebd97 + 53718d2 commit 43e994c

File tree

58 files changed

+29
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+29
-63
lines changed

config.toml.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@
339339
# rustc to execute.
340340
#lld = false
341341

342+
# Whether to deny warnings in crates
343+
#deny-warnings = true
344+
342345
# =============================================================================
343346
# Options for specific targets
344347
#

src/bootstrap/bin/rustc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ fn main() {
279279
cmd.arg("--color=always");
280280
}
281281

282+
if env::var_os("RUSTC_DENY_WARNINGS").is_some() {
283+
cmd.arg("-Dwarnings");
284+
}
285+
282286
if verbose > 1 {
283287
eprintln!("rustc command: {:?}", cmd);
284288
eprintln!("sysroot: {:?}", sysroot);

src/bootstrap/builder.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ impl<'a> Builder<'a> {
698698

699699
cargo.env("RUSTC_VERBOSE", format!("{}", self.verbosity));
700700

701+
// in std, we want to avoid denying warnings for stage 0 as that makes cfg's painful.
702+
if self.config.deny_warnings && !(mode == Mode::Libstd && stage == 0) {
703+
cargo.env("RUSTC_DENY_WARNINGS", "1");
704+
}
705+
701706
// Throughout the build Cargo can execute a number of build scripts
702707
// compiling C/C++ code and we need to pass compilers, archivers, flags, etc
703708
// obtained previously to those build scripts.

src/bootstrap/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ pub struct Config {
7171
pub incremental: bool,
7272
pub dry_run: bool,
7373

74+
pub deny_warnings: bool,
75+
7476
// llvm codegen options
7577
pub llvm_enabled: bool,
7678
pub llvm_assertions: bool,
@@ -301,6 +303,7 @@ struct Rust {
301303
codegen_backends_dir: Option<String>,
302304
wasm_syscall: Option<bool>,
303305
lld: Option<bool>,
306+
deny_warnings: Option<bool>,
304307
}
305308

306309
/// TOML representation of how each build target is configured.
@@ -340,6 +343,7 @@ impl Config {
340343
config.test_miri = false;
341344
config.rust_codegen_backends = vec![INTERNER.intern_str("llvm")];
342345
config.rust_codegen_backends_dir = "codegen-backends".to_owned();
346+
config.deny_warnings = true;
343347

344348
// set by bootstrap.py
345349
config.src = env::var_os("SRC").map(PathBuf::from).expect("'SRC' to be set");
@@ -366,6 +370,9 @@ impl Config {
366370
config.incremental = flags.incremental;
367371
config.dry_run = flags.dry_run;
368372
config.keep_stage = flags.keep_stage;
373+
if let Some(value) = flags.warnings {
374+
config.deny_warnings = value;
375+
}
369376

370377
if config.dry_run {
371378
let dir = config.out.join("tmp-dry-run");
@@ -511,6 +518,7 @@ impl Config {
511518
config.rustc_default_linker = rust.default_linker.clone();
512519
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
513520
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
521+
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
514522

515523
if let Some(ref backends) = rust.codegen_backends {
516524
config.rust_codegen_backends = backends.iter()

src/bootstrap/flags.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub struct Flags {
4242
pub exclude: Vec<PathBuf>,
4343
pub rustc_error_format: Option<String>,
4444
pub dry_run: bool,
45+
46+
// true => deny
47+
pub warnings: Option<bool>,
4548
}
4649

4750
pub enum Subcommand {
@@ -118,6 +121,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
118121
opts.optopt("", "src", "path to the root of the rust checkout", "DIR");
119122
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
120123
opts.optflag("h", "help", "print this help message");
124+
opts.optopt("", "warnings", "if value is deny, will deny warnings, otherwise use default",
125+
"VALUE");
121126
opts.optopt("", "error-format", "rustc error format", "FORMAT");
122127

123128
// fn usage()
@@ -374,6 +379,7 @@ Arguments:
374379
incremental: matches.opt_present("incremental"),
375380
exclude: split(matches.opt_strs("exclude"))
376381
.into_iter().map(|p| p.into()).collect::<Vec<_>>(),
382+
warnings: matches.opt_str("warnings").map(|v| v == "deny"),
377383
}
378384
}
379385
}

src/build_helper/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![deny(warnings)]
1211

1312
use std::fs::File;
1413
use std::path::{Path, PathBuf};

src/liballoc/benches/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![deny(warnings)]
12-
1311
#![feature(rand)]
1412
#![feature(repr_simd)]
1513
#![feature(slice_sort_by_cached_key)]

src/liballoc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
7373
#![no_std]
7474
#![needs_allocator]
75-
#![deny(warnings)]
7675
#![deny(missing_debug_implementations)]
7776

7877
#![cfg_attr(test, allow(deprecated))] // rand

src/liballoc/tests/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![deny(warnings)]
12-
1311
#![feature(allocator_api)]
1412
#![feature(alloc_system)]
1513
#![feature(attr_literals)]

src/liballoc_jemalloc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
reason = "this library is unlikely to be stabilized in its current \
1515
form or name",
1616
issue = "27783")]
17-
#![deny(warnings)]
1817
#![feature(alloc_system)]
1918
#![feature(libc)]
2019
#![feature(linkage)]

0 commit comments

Comments
 (0)