about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/early_buffered_lints.rs29
-rw-r--r--src/libsyntax/lib.rs2
-rw-r--r--src/libsyntax/parse/mod.rs23
3 files changed, 52 insertions, 2 deletions
diff --git a/src/libsyntax/early_buffered_lints.rs b/src/libsyntax/early_buffered_lints.rs
new file mode 100644
index 00000000000..204e07625ad
--- /dev/null
+++ b/src/libsyntax/early_buffered_lints.rs
@@ -0,0 +1,29 @@
+//! Allows the buffering of lints for later.
+//!
+//! Since we cannot have a dependency on `librustc`, we implement some types here that are somewhat
+//! redundant. Later, these types can be converted to types for use by the rest of the compiler.
+
+use syntax::ast::NodeId;
+use syntax_pos::MultiSpan;
+
+/// Since we cannot import `LintId`s from `rustc::lint`, we define some Ids here which can later be
+/// passed to `rustc::lint::Lint::from_parser_lint_id` to get a `rustc::lint::Lint`.
+pub enum BufferedEarlyLintId {
+    /// Usage of `?` as a macro separator is deprecated.
+    QuestionMarkMacroSep,
+}
+
+/// Stores buffered lint info which can later be passed to `librustc`.
+pub struct BufferedEarlyLint {
+    /// The span of code that we are linting on.
+   pub span: MultiSpan,
+
+   /// The lint message.
+   pub msg: String,
+
+   /// The `NodeId` of the AST node that generated the lint.
+   pub id: NodeId,
+
+   /// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`.
+   pub lint_id: BufferedEarlyLintId,
+}
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index ffaad9bf94c..d241ae1d442 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -181,6 +181,8 @@ pub mod ext {
     }
 }
 
+pub mod early_buffered_lints;
+
 #[cfg(test)]
 mod test_snippet;
 
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 1754e5f1b9a..5dbf569766e 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -11,9 +11,10 @@
 //! The main parser interface
 
 use rustc_data_structures::sync::{Lrc, Lock};
-use ast::{self, CrateConfig};
+use ast::{self, CrateConfig, NodeId};
+use early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId};
 use codemap::{CodeMap, FilePathMapping};
-use syntax_pos::{Span, FileMap, FileName};
+use syntax_pos::{Span, FileMap, FileName, MultiSpan};
 use errors::{Handler, ColorConfig, DiagnosticBuilder};
 use feature_gate::UnstableFeatures;
 use parse::parser::Parser;
@@ -57,6 +58,7 @@ pub struct ParseSess {
     /// Used to determine and report recursive mod inclusions
     included_mod_stack: Lock<Vec<PathBuf>>,
     code_map: Lrc<CodeMap>,
+    pub buffered_lints: Lock<Vec<BufferedEarlyLint>>,
 }
 
 impl ParseSess {
@@ -80,12 +82,29 @@ impl ParseSess {
             included_mod_stack: Lock::new(vec![]),
             code_map,
             non_modrs_mods: Lock::new(vec![]),
+            buffered_lints: Lock::new(vec![]),
         }
     }
 
     pub fn codemap(&self) -> &CodeMap {
         &self.code_map
     }
+
+    pub fn buffer_lint<S: Into<MultiSpan>>(&self,
+        lint_id: BufferedEarlyLintId,
+        span: S,
+        id: NodeId,
+        msg: &str,
+    ) {
+        self.buffered_lints
+            .borrow_mut()
+            .push(BufferedEarlyLint{
+                span: span.into(),
+                id,
+                msg: msg.into(),
+                lint_id,
+            });
+    }
 }
 
 #[derive(Clone)]