]> git.lizzy.rs Git - rust.git/commitdiff
Only bump error count when we are sure that the diagnostic is not a repetition.
authorRafael Fernández López <ereslibre@ereslibre.es>
Tue, 2 Jan 2018 19:00:12 +0000 (20:00 +0100)
committerRafael Fernández López <ereslibre@ereslibre.es>
Tue, 2 Jan 2018 23:42:12 +0000 (00:42 +0100)
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
src/librustc_errors/diagnostic_builder.rs
src/librustc_errors/lib.rs
src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr
src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr
src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr
src/test/ui/issue-42106.stderr
src/test/ui/span/macro-ty-params.stderr

index 221c75186e9c8b5c86df793e7a0069e4de418f5a..8da4321fa5b71018db4a2240996b93d7d0a08d76 100644 (file)
@@ -100,9 +100,6 @@ pub fn new_with_code(level: Level, code: Option<DiagnosticId>, message: &str) ->
 
     /// 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;
     }
index 27e895164e7645d56a193a585a7ae3919628b086..61674ada6fa63c1bc37a7ff3e7b09d92a57801e7 100644 (file)
@@ -83,7 +83,12 @@ pub fn emit(&mut self) {
             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 @@ pub fn emit(&mut self) {
             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
index 2ac49958d3c5317990ed5d95c4174be91e6746de..c4db39fae86197965db25448d8211e2a6642bfbf 100644 (file)
@@ -588,6 +588,9 @@ fn emit_db(&self, db: &DiagnosticBuilder) {
         // one:
         if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) {
             self.emitter.borrow_mut().emit(db);
+            if db.is_error() {
+                self.bump_err_count();
+            }
         }
     }
 }
index 6f6f587cb535286caa181865a89e71aa1cd8dafc..5de3204f931826b3d426ab37eb4cb372d43abe95 100644 (file)
@@ -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
 
index 59f0431c708da2df9fc6ac3380c5c63c2b7a0d8a..eace1dc413a6b74a9325e3b7af88e3a29b1c77e4 100644 (file)
@@ -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
 
index 00cbc62ab479f1120dd60d9eeeb9fab5f3f904e4..59068279fde193ddbfd39569ffcd7250de8a73f0 100644 (file)
@@ -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
 
index 0f96377c062a8323004e48f7f3d9049c3025a297..138f7693ebee1e17b414816cc3efd8895fdb3494 100644 (file)
@@ -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
 
index e3e9334d9fbb70058a3c6cd7d10bd6411b5c0559..2ac132f708c0f5bbd147fd74e305411e80e6209c 100644 (file)
@@ -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