about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-01-21 21:19:37 -0800
committerEsteban Küber <esteban@kuber.com.ar>2018-01-22 15:46:51 -0800
commit864f6d180baf76365619a7fe76b6c8b87e5ead8f (patch)
tree2f6a9c23802f4edf74a969da38b8341a932fe354 /src/librustc_errors
parente76d3f62cc34a77496305639f22a7da168ebc301 (diff)
downloadrust-864f6d180baf76365619a7fe76b6c8b87e5ead8f.tar.gz
rust-864f6d180baf76365619a7fe76b6c8b87e5ead8f.zip
Only emit expanded diagnostic information once
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/diagnostic.rs6
-rw-r--r--src/librustc_errors/lib.rs10
2 files changed, 15 insertions, 1 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs
index 8da4321fa5b..2e654fe9929 100644
--- a/src/librustc_errors/diagnostic.rs
+++ b/src/librustc_errors/diagnostic.rs
@@ -27,7 +27,7 @@ pub struct Diagnostic {
     pub suggestions: Vec<CodeSuggestion>,
 }
 
-#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
+#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
 pub enum DiagnosticId {
     Error(String),
     Lint(String),
@@ -281,6 +281,10 @@ impl Diagnostic {
         self
     }
 
+    pub fn get_code(&self) -> Option<DiagnosticId> {
+        self.code.clone()
+    }
+
     pub fn message(&self) -> String {
         self.message.iter().map(|i| i.0.to_owned()).collect::<String>()
     }
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 1fb673815ee..cabafa052a3 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -244,6 +244,7 @@ pub struct Handler {
     continue_after_error: Cell<bool>,
     delayed_span_bug: RefCell<Option<Diagnostic>>,
     tracked_diagnostics: RefCell<Option<Vec<Diagnostic>>>,
+    tracked_diagnostic_codes: RefCell<FxHashSet<DiagnosticId>>,
 
     // This set contains a hash of every diagnostic that has been emitted by
     // this handler. These hashes is used to avoid emitting the same error
@@ -303,6 +304,7 @@ impl Handler {
             continue_after_error: Cell::new(true),
             delayed_span_bug: RefCell::new(None),
             tracked_diagnostics: RefCell::new(None),
+            tracked_diagnostic_codes: RefCell::new(FxHashSet()),
             emitted_diagnostics: RefCell::new(FxHashSet()),
         }
     }
@@ -575,6 +577,10 @@ impl Handler {
         (ret, diagnostics)
     }
 
+    pub fn code_emitted(&self, code: &DiagnosticId) -> bool {
+        self.tracked_diagnostic_codes.borrow().contains(code)
+    }
+
     fn emit_db(&self, db: &DiagnosticBuilder) {
         let diagnostic = &**db;
 
@@ -582,6 +588,10 @@ impl Handler {
             list.push(diagnostic.clone());
         }
 
+        if let Some(ref code) = diagnostic.code {
+            self.tracked_diagnostic_codes.borrow_mut().insert(code.clone());
+        }
+
         let diagnostic_hash = {
             use std::hash::Hash;
             let mut hasher = StableHasher::new();