From 2a7ae04a6872edd8a1bffa620fde53a2eb2964e1 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 11 Jul 2018 20:54:12 -0500 Subject: Extend ParseSess to support buffering lints --- src/libsyntax/parse/mod.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/libsyntax/parse') 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>, code_map: Lrc, + pub buffered_lints: Lock>, } 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>(&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)] -- cgit 1.4.1-3-g733a5 From 6cb09ccf9f524590d7cc9f8c97732742446ae2b2 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 13 Jul 2018 23:40:29 -0500 Subject: dump lints _after_ parsing macros --- src/librustc_driver/driver.rs | 16 +++++++++------- src/libsyntax/parse/mod.rs | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 3e14ec6f8d4..91392ab013d 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -697,13 +697,6 @@ pub fn phase_1_parse_input<'a>( hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS"); } - // Add all buffered lints from the `ParseSess` to the `Session`. - let mut parse_sess_buffered = sess.parse_sess.buffered_lints.borrow_mut(); - for BufferedEarlyLint{id, span, msg, lint_id} in parse_sess_buffered.drain(..) { - let lint = lint::Lint::from_parser_lint_id(lint_id); - sess.buffer_lint(lint, id, span, &msg); - } - Ok(krate) } @@ -1074,6 +1067,15 @@ where ) }); + // Add all buffered lints from the `ParseSess` to the `Session`. + sess.parse_sess.buffered_lints.with_lock(|buffered_lints| { + info!("{} parse sess buffered_lints", buffered_lints.len()); + for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) { + let lint = lint::Lint::from_parser_lint_id(lint_id); + sess.buffer_lint(lint, id, span, &msg); + } + }); + // Done with macro expansion! after_expand(&krate)?; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 5dbf569766e..d029509f0c1 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -96,14 +96,14 @@ impl ParseSess { id: NodeId, msg: &str, ) { - self.buffered_lints - .borrow_mut() - .push(BufferedEarlyLint{ + self.buffered_lints.with_lock(|buffered_lints| { + buffered_lints.push(BufferedEarlyLint{ span: span.into(), id, msg: msg.into(), lint_id, }); + }); } } -- cgit 1.4.1-3-g733a5 From 10ee0f68a6815fafa69f58daf347f0c2a8339f32 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 13 Jul 2018 23:48:15 -0500 Subject: Allow by default, fix tests --- src/librustc/lint/builtin.rs | 2 +- src/libsyntax/parse/lexer/mod.rs | 1 + .../auxiliary/procedural_mbe_matching.rs | 6 ++++-- src/test/ui/issue-39388.stderr | 4 ++-- .../ui/macros/macro-at-most-once-rep-2015-ques-sep.rs | 4 ++++ .../macros/macro-at-most-once-rep-2015-ques-sep.stderr | 16 ++++++++++++++-- 6 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 495b4d32e06..4184cba7db3 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -335,7 +335,7 @@ declare_lint! { pub mod parser { declare_lint! { pub QUESTION_MARK_MACRO_SEP, - Warn, + Allow, "detects the use of `?` as a macro separator" } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 9748e2947ee..4b077aa8dd4 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1807,6 +1807,7 @@ mod tests { raw_identifier_spans: Lock::new(Vec::new()), registered_diagnostics: Lock::new(ErrorMap::new()), non_modrs_mods: Lock::new(vec![]), + buffered_lints: Lock::new(vec![]), } } diff --git a/src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs b/src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs index 664e9eeb3e0..f1777745e06 100644 --- a/src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs +++ b/src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs @@ -20,7 +20,7 @@ extern crate rustc_plugin; use syntax::feature_gate::Features; use syntax::parse::token::{NtExpr, NtPat}; -use syntax::ast::{Ident, Pat}; +use syntax::ast::{Ident, Pat, NodeId}; use syntax::tokenstream::{TokenTree}; use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; use syntax::ext::build::AstBuilder; @@ -41,7 +41,9 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, _: Span, args: &[TokenTree]) cx.parse_sess, &Features::new(), &[], - Edition::Edition2015); + Edition::Edition2015, + // not used... + NodeId::new(0)); let map = match TokenTree::parse(cx, &mbe_matcher, args.iter().cloned().collect()) { Success(map) => map, Failure(_, tok) => { diff --git a/src/test/ui/issue-39388.stderr b/src/test/ui/issue-39388.stderr index a38d38a51ad..dc19487f3af 100644 --- a/src/test/ui/issue-39388.stderr +++ b/src/test/ui/issue-39388.stderr @@ -1,7 +1,7 @@ -error: expected one of: `*`, `+`, or `?` +error: expected `*` or `+` --> $DIR/issue-39388.rs:14:22 | -LL | (($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected one of: `*`, `+`, or `?` +LL | (($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected `*` or `+` | ^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs index 4b3dfbdc2e8..2e06b4bd5c2 100644 --- a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs +++ b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs @@ -14,12 +14,16 @@ // compile-flags: --edition=2015 // compile-pass +#![warn(rust_2018_compatibility)] + macro_rules! bar { ($(a)?*) => {} //~WARN using `?` as a separator + //~^WARN this was previously accepted } macro_rules! baz { ($(a)?+) => {} //~WARN using `?` as a separator + //~^WARN this was previously accepted } fn main() { diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr index 0ab4138864e..db1872c2413 100644 --- a/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr +++ b/src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr @@ -1,12 +1,24 @@ warning: using `?` as a separator is deprecated and will be a hard error in an upcoming edition - --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:18:10 + --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:20:10 | LL | ($(a)?*) => {} //~WARN using `?` as a separator | ^ + | +note: lint level defined here + --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:17:9 + | +LL | #![warn(rust_2018_compatibility)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + = note: #[warn(question_mark_macro_sep)] implied by #[warn(rust_2018_compatibility)] + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #48075 warning: using `?` as a separator is deprecated and will be a hard error in an upcoming edition - --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:22:10 + --> $DIR/macro-at-most-once-rep-2015-ques-sep.rs:25:10 | LL | ($(a)?+) => {} //~WARN using `?` as a separator | ^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #48075 -- cgit 1.4.1-3-g733a5