summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-01-26 06:50:31 -0800
committerAlex Crichton <alex@alexcrichton.com>2018-01-26 06:50:31 -0800
commit6da912e2a1f8ef5df8e0669713d15258a039325f (patch)
tree6c7b5669eeac5041bdfa6a0dc3246d90b73368d3 /src/librustc_errors
parent95942155da62e80f59b425a290a6eff502787ded (diff)
parent2b737334961916daee73ea018eea877f389ad0dc (diff)
downloadrust-6da912e2a1f8ef5df8e0669713d15258a039325f.tar.gz
rust-6da912e2a1f8ef5df8e0669713d15258a039325f.zip
Merge branch 'explain' of https://github.com/estebank/rust into rollup
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/diagnostic.rs6
-rw-r--r--src/librustc_errors/lib.rs18
2 files changed, 23 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 33948ea92b9..3d50c95d3f4 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -259,6 +259,11 @@ pub struct Handler {
     delayed_span_bug: RefCell<Option<Diagnostic>>,
     tracked_diagnostics: RefCell<Option<Vec<Diagnostic>>>,
 
+    // This set contains the `DiagnosticId` of all emitted diagnostics to avoid
+    // emitting the same diagnostic with extended help (`--teach`) twice, which
+    // would be uneccessary repetition.
+    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
     // twice.
@@ -317,6 +322,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()),
         }
     }
@@ -589,6 +595,14 @@ impl Handler {
         (ret, diagnostics)
     }
 
+    /// `true` if a diagnostic with this code has already been emitted in this handler.
+    ///
+    /// Used to suppress emitting the same error multiple times with extended explanation when
+    /// calling `-Zteach`.
+    pub fn code_emitted(&self, code: &DiagnosticId) -> bool {
+        self.tracked_diagnostic_codes.borrow().contains(code)
+    }
+
     fn emit_db(&self, db: &DiagnosticBuilder) {
         let diagnostic = &**db;
 
@@ -596,6 +610,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();