Skip to content

Commit 941d435

Browse files
committed
Auto merge of #69926 - RoccoDev:master, r=estebank,varkor
rustc: Add a warning count upon completion This adds a `build completed with one warning/x warnings` message, similar to the already present `aborted due to previous error` message.
2 parents 378901d + b85c64c commit 941d435

File tree

308 files changed

+515
-132
lines changed

Some content is hidden

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

308 files changed

+515
-132
lines changed

src/librustc_errors/lib.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ struct HandlerInner {
312312
/// The stashed diagnostics count towards the total error count.
313313
/// When `.abort_if_errors()` is called, these are also emitted.
314314
stashed_diagnostics: FxIndexMap<(Span, StashKey), Diagnostic>,
315+
316+
/// The warning count, used for a recap upon finishing
317+
deduplicated_warn_count: usize,
315318
}
316319

317320
/// A key denoting where from a diagnostic was stashed.
@@ -414,6 +417,7 @@ impl Handler {
414417
flags,
415418
err_count: 0,
416419
deduplicated_err_count: 0,
420+
deduplicated_warn_count: 0,
417421
emitter,
418422
delayed_span_bugs: Vec::new(),
419423
taught_diagnostics: Default::default(),
@@ -439,6 +443,7 @@ impl Handler {
439443
let mut inner = self.inner.borrow_mut();
440444
inner.err_count = 0;
441445
inner.deduplicated_err_count = 0;
446+
inner.deduplicated_warn_count = 0;
442447

443448
// actually free the underlying memory (which `clear` would not do)
444449
inner.delayed_span_bugs = Default::default();
@@ -745,6 +750,8 @@ impl HandlerInner {
745750
self.emitter.emit_diagnostic(diagnostic);
746751
if diagnostic.is_error() {
747752
self.deduplicated_err_count += 1;
753+
} else if diagnostic.level == Warning {
754+
self.deduplicated_warn_count += 1;
748755
}
749756
}
750757
if diagnostic.is_error() {
@@ -763,16 +770,30 @@ impl HandlerInner {
763770
fn print_error_count(&mut self, registry: &Registry) {
764771
self.emit_stashed_diagnostics();
765772

766-
let s = match self.deduplicated_err_count {
767-
0 => return,
773+
let warnings = match self.deduplicated_warn_count {
774+
0 => String::new(),
775+
1 => "1 warning emitted".to_string(),
776+
count => format!("{} warnings emitted", count),
777+
};
778+
let errors = match self.deduplicated_err_count {
779+
0 => String::new(),
768780
1 => "aborting due to previous error".to_string(),
769781
count => format!("aborting due to {} previous errors", count),
770782
};
771783
if self.treat_err_as_bug() {
772784
return;
773785
}
774786

775-
let _ = self.fatal(&s);
787+
match (errors.len(), warnings.len()) {
788+
(0, 0) => return,
789+
(0, _) => self.emit_diagnostic(&Diagnostic::new(Level::Warning, &warnings)),
790+
(_, 0) => {
791+
let _ = self.fatal(&errors);
792+
}
793+
(_, _) => {
794+
let _ = self.fatal(&format!("{}; {}", &errors, &warnings));
795+
}
796+
}
776797

777798
let can_show_explain = self.emitter.should_show_explain();
778799
let are_there_diagnostics = !self.emitted_diagnostic_codes.is_empty();

src/test/rustdoc-ui/deprecated-attrs.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ warning: the `#![doc(passes = "...")]` attribute is considered deprecated
77
|
88
= warning: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
99

10+
warning: 2 warnings emitted
11+

src/test/rustdoc-ui/intra-links-warning-crlf.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ LL | * It also has an [error].
3131
|
3232
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
3333

34+
warning: 4 warnings emitted
35+

src/test/rustdoc-ui/intra-links-warning.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,5 @@ LL | f!("Foo\nbar [BarF] bar\nbaz");
177177
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
178178
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
179179

180+
warning: 19 warnings emitted
181+

src/test/rustdoc-ui/invalid-syntax.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,5 @@ help: mark blocks that do not contain Rust code as text
147147
LL | /// ```text
148148
| ^^^^^^^
149149

150+
warning: 12 warnings emitted
151+

src/test/ui-fulldeps/feature-gate-plugin.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ LL | #![plugin(empty_plugin)]
1515
|
1616
= note: `#[warn(deprecated)]` on by default
1717

18-
error: aborting due to previous error
18+
error: aborting due to previous error; 1 warning emitted
1919

2020
For more information about this error, try `rustc --explain E0658`.

src/test/ui-fulldeps/gated-plugin.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ LL | #![plugin(empty_plugin)]
1515
|
1616
= note: `#[warn(deprecated)]` on by default
1717

18-
error: aborting due to previous error
18+
error: aborting due to previous error; 1 warning emitted
1919

2020
For more information about this error, try `rustc --explain E0658`.

src/test/ui-fulldeps/issue-15778-fail.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ LL | | pub fn main() { }
1818
|
1919
= note: requested on the command line with `-D crate-not-okay`
2020

21-
error: aborting due to previous error
21+
error: aborting due to previous error; 1 warning emitted
2222

src/test/ui-fulldeps/issue-15778-pass.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ LL | #![plugin(lint_for_crate_rpass)]
66
|
77
= note: `#[warn(deprecated)]` on by default
88

9+
warning: 1 warning emitted
10+

src/test/ui-fulldeps/issue-40001.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ LL | #![plugin(issue_40001_plugin)]
66
|
77
= note: `#[warn(deprecated)]` on by default
88

9+
warning: 1 warning emitted
10+

0 commit comments

Comments
 (0)