about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-23 19:29:02 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-09-23 19:29:02 +0200
commit62fc4d36dfeedbf0795f36a8d08c39e0f4e41632 (patch)
treeb03e95cdade4124544818cc1cae3178dc8a9390e /src/librustc_errors
parent62d85849d0a9a828dc58a1820469daf80a2b5b52 (diff)
downloadrust-62fc4d36dfeedbf0795f36a8d08c39e0f4e41632.tar.gz
rust-62fc4d36dfeedbf0795f36a8d08c39e0f4e41632.zip
stash_diagnostic: ICE in a different way
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/lib.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 40f63ae1eee..cdaa528e8e4 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -466,10 +466,15 @@ impl Handler {
     /// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
     /// If the diagnostic with this `(span, key)` already exists, this will result in an ICE.
     pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
-        if let Some(old) = self.inner.borrow_mut().stashed_diagnostics.insert((span, key), diag) {
+        let mut inner = self.inner.borrow_mut();
+        if let Some(mut old_diag) = inner.stashed_diagnostics.insert((span, key), diag) {
             // We are removing a previously stashed diagnostic which should not happen.
-            // Create a builder and drop it on the floor to get an ICE.
-            drop(DiagnosticBuilder::new_diagnostic(self, old));
+            old_diag.level = Bug;
+            old_diag.note(&format!(
+                "{}:{}: already existing stashed diagnostic with (span = {:?}, key = {:?})",
+                file!(), line!(), span, key
+            ));
+            inner.emit_explicit_bug(&old_diag);
         }
     }
 
@@ -676,6 +681,11 @@ impl Handler {
         self.inner.borrow_mut().abort_if_errors_and_should_abort()
     }
 
+    /// `true` if we haven't taught a diagnostic with this code already.
+    /// The caller must then teach the user about such a diagnostic.
+    ///
+    /// Used to suppress emitting the same error multiple times with extended explanation when
+    /// calling `-Zteach`.
     pub fn must_teach(&self, code: &DiagnosticId) -> bool {
         self.inner.borrow_mut().must_teach(code)
     }
@@ -698,11 +708,6 @@ impl Handler {
 }
 
 impl HandlerInner {
-    /// `true` if we haven't taught a diagnostic with this code already.
-    /// The caller must then teach the user about such a diagnostic.
-    ///
-    /// Used to suppress emitting the same error multiple times with extended explanation when
-    /// calling `-Zteach`.
     fn must_teach(&mut self, code: &DiagnosticId) -> bool {
         self.taught_diagnostics.insert(code.clone())
     }
@@ -833,7 +838,11 @@ impl HandlerInner {
     }
 
     fn span_bug<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> ! {
-        self.emit_diagnostic(Diagnostic::new(Bug, msg).set_span(sp));
+        self.emit_explicit_bug(Diagnostic::new(Bug, msg).set_span(sp));
+    }
+
+    fn emit_explicit_bug(&mut self, diag: &Diagnostic) -> ! {
+        self.emit_diagnostic(diag);
         self.abort_if_errors_and_should_abort();
         panic!(ExplicitBug);
     }