about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-10-11 14:02:06 -0400
committerNiko Matsakis <niko@alum.mit.edu>2016-11-01 14:07:45 -0400
commitf6526512751bfe29a0bf9535bc41db2076ff57ba (patch)
treebb03dcf1be6a9997ac28ecd1c46b772c2459a9ff /src
parent888a92cef37342c7878028eda967c85eb15afe43 (diff)
downloadrust-f6526512751bfe29a0bf9535bc41db2076ff57ba.tar.gz
rust-f6526512751bfe29a0bf9535bc41db2076ff57ba.zip
retool EarlyLint to track a Diagnostic
Diffstat (limited to 'src')
-rw-r--r--src/librustc/lint/context.rs25
-rw-r--r--src/librustc_errors/diagnostic.rs8
-rw-r--r--src/libsyntax_pos/lib.rs2
3 files changed, 26 insertions, 9 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs
index bcc8384dd0e..848f8b86639 100644
--- a/src/librustc/lint/context.rs
+++ b/src/librustc/lint/context.rs
@@ -43,7 +43,7 @@ use syntax::attr;
 use syntax::parse::token::InternedString;
 use syntax::ast;
 use syntax_pos::Span;
-use errors::DiagnosticBuilder;
+use errors::{self, Diagnostic, DiagnosticBuilder};
 use hir;
 use hir::intravisit as hir_visit;
 use syntax::visit as ast_visit;
@@ -87,30 +87,36 @@ pub struct EarlyLint {
     /// what lint is this? (e.g., `dead_code`)
     pub id: LintId,
 
-    /// the span where the lint will be reported at
+    /// what span was it attached to (this is used for Eq comparisons;
+    /// it duplicates to some extent the information in
+    /// `diagnostic.span`)
     pub span: Span,
 
     /// the main message
-    pub msg: String,
+    pub diagnostic: Diagnostic,
 }
 
 impl fmt::Debug for EarlyLint {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.debug_struct("EarlyLint")
             .field("id", &self.id)
-            .field("span", &self.span)
-            .field("msg", &self.msg)
+            .field("span", &self.diagnostic.span)
+            .field("diagnostic", &self.diagnostic)
             .finish()
     }
 }
 
 impl EarlyLint {
     pub fn new(id: LintId, span: Span, msg: String) -> Self {
-        EarlyLint { id: id, span: span, msg: msg }
+        let mut diagnostic = Diagnostic::new(errors::Level::Warning, &msg);
+        diagnostic.set_span(span);
+        EarlyLint { id: id, span: span, diagnostic: diagnostic }
     }
 
     pub fn matches(&self, other: &EarlyLint) -> bool {
-        self.id == other.id && self.span == other.span && self.msg == other.msg
+        self.id == other.id &&
+            self.span == other.span &&
+            self.diagnostic.message == other.diagnostic.message
     }
 }
 
@@ -551,7 +557,10 @@ pub trait LintContext: Sized {
     }
 
     fn early_lint(&self, early_lint: EarlyLint) {
-        let mut err = self.struct_span_lint(early_lint.id.lint, early_lint.span, &early_lint.msg);
+        let mut err = self.struct_span_lint(early_lint.id.lint,
+                                            early_lint.span,
+                                            &early_lint.diagnostic.message);
+        err.copy_details_not_message(&early_lint.diagnostic);
         err.emit();
     }
 
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs
index dab8fb665ac..cb03257a5ee 100644
--- a/src/librustc_errors/diagnostic.rs
+++ b/src/librustc_errors/diagnostic.rs
@@ -166,6 +166,14 @@ impl Diagnostic {
         self.level
     }
 
+    /// Used by a lint. Copies over all details *but* the "main
+    /// message".
+    pub fn copy_details_not_message(&mut self, from: &Diagnostic) {
+        self.span = from.span.clone();
+        self.code = from.code.clone();
+        self.children.extend(from.children.iter().cloned())
+    }
+
     /// Convenience function for internal use, clients should use one of the
     /// public methods above.
     fn sub(&mut self,
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index d83d3a6c5cf..d99850332c3 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -67,7 +67,7 @@ pub struct Span {
 ///   the error, and would be rendered with `^^^`.
 /// - they can have a *label*. In this case, the label is written next
 ///   to the mark in the snippet when we render.
-#[derive(Clone)]
+#[derive(Clone, Debug, PartialEq, Eq)]
 pub struct MultiSpan {
     primary_spans: Vec<Span>,
     span_labels: Vec<(Span, String)>,