From 063607eecbbdff53ee0cbc4b3f9a8ff49448f741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Fern=C3=A1ndez=20L=C3=B3pez?= Date: Tue, 2 Jan 2018 20:00:12 +0100 Subject: [PATCH] Only bump error count when we are sure that the diagnostic is not a repetition. This ensures that if we emit the same diagnostic twice, the error count will match the real number of errors shown to the user. Fixes #42106 --- src/librustc_errors/diagnostic.rs | 3 --- src/librustc_errors/diagnostic_builder.rs | 18 ++++++------------ src/librustc_errors/lib.rs | 3 +++ ...sue-43106-gating-of-rustc_deprecated.stderr | 2 +- .../issue-43106-gating-of-stable.stderr | 2 +- .../issue-43106-gating-of-unstable.stderr | 2 +- src/test/ui/issue-42106.stderr | 2 +- src/test/ui/span/macro-ty-params.stderr | 2 +- 8 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 221c75186e9..8da4321fa5b 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -100,9 +100,6 @@ impl Diagnostic { /// Cancel the diagnostic (a structured diagnostic must either be emitted or /// canceled or it will panic when dropped). - /// BEWARE: if this DiagnosticBuilder is an error, then creating it will - /// bump the error count on the Handler and canceling it won't undo that. - /// If you want to decrement the error count you should use `Handler::cancel`. pub fn cancel(&mut self) { self.level = Level::Cancelled; } diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 27e895164e7..61674ada6fa 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -83,7 +83,12 @@ impl<'a> DiagnosticBuilder<'a> { return; } - let is_error = match self.level { + self.handler.emit_db(&self); + self.cancel(); + } + + pub fn is_error(&self) -> bool { + match self.level { Level::Bug | Level::Fatal | Level::PhaseFatal | @@ -97,18 +102,7 @@ impl<'a> DiagnosticBuilder<'a> { Level::Cancelled => { false } - }; - - self.handler.emit_db(&self); - self.cancel(); - - if is_error { - self.handler.bump_err_count(); } - - // if self.is_fatal() { - // panic!(FatalError); - // } } /// Convenience function for internal use, clients should use one of the diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 2ac49958d3c..c4db39fae86 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -588,6 +588,9 @@ impl Handler { // one: if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) { self.emitter.borrow_mut().emit(db); + if db.is_error() { + self.bump_err_count(); + } } } } diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr index 6f6f587cb53..5de3204f931 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr @@ -42,5 +42,5 @@ error: stability attributes may not be used outside of the standard library 35 | #[rustc_deprecated = "1500"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr index 59f0431c708..eace1dc413a 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr @@ -42,5 +42,5 @@ error: stability attributes may not be used outside of the standard library 35 | #[stable = "1300"] impl S { } | ^^^^^^^^^^^^^^^^^^ -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr index 00cbc62ab47..59068279fde 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr @@ -42,5 +42,5 @@ error: stability attributes may not be used outside of the standard library 35 | #[unstable = "1200"] impl S { } | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors diff --git a/src/test/ui/issue-42106.stderr b/src/test/ui/issue-42106.stderr index 0f96377c062..138f7693ebe 100644 --- a/src/test/ui/issue-42106.stderr +++ b/src/test/ui/issue-42106.stderr @@ -8,5 +8,5 @@ error[E0502]: cannot borrow `*collection` as mutable because `collection` is als 14 | } | - immutable borrow ends here -error: aborting due to 2 previous errors +error: aborting due to previous error diff --git a/src/test/ui/span/macro-ty-params.stderr b/src/test/ui/span/macro-ty-params.stderr index e3e9334d9fb..2ac132f708c 100644 --- a/src/test/ui/span/macro-ty-params.stderr +++ b/src/test/ui/span/macro-ty-params.stderr @@ -22,5 +22,5 @@ error: generic arguments in macro path 20 | m!(MyTrait<>); //~ ERROR generic arguments in macro path | ^^ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors