Skip to content

Commit 96c3129

Browse files
committed
fix(compile): Stop on denying warnings without --keep-going
This had been discussed a little bit on [zulip](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/Environment.20variable.20for.20.5Blints.5D.20table.3F/near/553969201). This then came up in usability feedback from a T-compiler member with rust-lang/rust's x.py having adopted `build.warnings`. The output from all of the other build targets causes the warnings to disappear off the screen which doesn't happen with errors because the build ends immediately. So we're making warnings act more like errors.
1 parent dcfd695 commit 96c3129

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/cargo/core/compiler/job_queue/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl<'gctx> DrainState<'gctx> {
668668
Message::FixDiagnostic(msg) => {
669669
self.print.print(&msg)?;
670670
}
671-
Message::Finish(id, artifact, result) => {
671+
Message::Finish(id, artifact, mut result) => {
672672
let unit = match artifact {
673673
// If `id` has completely finished we remove it
674674
// from the `active` map ...
@@ -692,6 +692,14 @@ impl<'gctx> DrainState<'gctx> {
692692
&build_runner.bcx.rustc().workspace_wrapper,
693693
warning_handling,
694694
);
695+
let stop_on_warnings = warning_handling == WarningHandling::Deny
696+
&& 0 < count.lints
697+
&& !build_runner.bcx.build_config.keep_going;
698+
if stop_on_warnings {
699+
result = Err(anyhow::format_err!(
700+
"warnings are denied by `build.warnings` configuration"
701+
))
702+
}
695703
}
696704
unit
697705
}

src/doc/src/reference/unstable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ in the future.
18591859
Controls how Cargo handles warnings. Allowed values are:
18601860
* `warn`: warnings are emitted as warnings (default).
18611861
* `allow`: warnings are hidden.
1862-
* `deny`: if warnings are emitted, an error will be raised at the end of the operation and the process will exit with a failure exit code.
1862+
* `deny`: if warnings are emitted, an error will be raised at the end of the current crate and the process. Use `--keep-going` to see all warnings.
18631863

18641864
## feature unification
18651865

tests/testsuite/warning_override.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ fn rustc_caching_allow_first() {
5151
= [NOTE] `#[warn(unused_variables)]` [..]on by default
5252
5353
[ERROR] `foo` (bin "foo") generated 1 warning[..]
54-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
5554
[ERROR] warnings are denied by `build.warnings` configuration
5655
5756
"#]])
@@ -78,7 +77,6 @@ fn rustc_caching_deny_first() {
7877
= [NOTE] `#[warn(unused_variables)]` [..]on by default
7978
8079
[ERROR] `foo` (bin "foo") generated 1 warning[..]
81-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
8280
[ERROR] warnings are denied by `build.warnings` configuration
8381
8482
"#]])
@@ -115,7 +113,6 @@ fn config() {
115113
= [NOTE] `#[warn(unused_variables)]` [..]on by default
116114
117115
[ERROR] `foo` (bin "foo") generated 1 warning[..]
118-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
119116
[ERROR] warnings are denied by `build.warnings` configuration
120117
121118
"#]])
@@ -195,7 +192,6 @@ fn clippy() {
195192
[WARNING] unused import: `std::io`
196193
...
197194
[ERROR] `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)
198-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
199195
[ERROR] warnings are denied by `build.warnings` configuration
200196
201197
"#]])
@@ -318,10 +314,6 @@ fn keep_going() {
318314
[WARNING] unused variable: `x`
319315
...
320316
[ERROR] `foo` (build script) generated 1 warning
321-
[WARNING] unused variable: `y`
322-
...
323-
[ERROR] `foo` (bin "foo") generated 1 warning (run `cargo fix --bin "foo" -p foo` to apply 1 suggestion)
324-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
325317
[ERROR] warnings are denied by `build.warnings` configuration
326318
327319
"#]])
@@ -337,7 +329,7 @@ fn keep_going() {
337329
[WARNING] unused variable: `x`
338330
...
339331
[ERROR] `foo` (build script) generated 1 warning
340-
[WARNING] unused variable: `y`
332+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
341333
...
342334
[ERROR] `foo` (bin "foo") generated 1 warning (run `cargo fix --bin "foo" -p foo` to apply 1 suggestion)
343335
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

0 commit comments

Comments
 (0)