From 88115028590e0769a02d3c2e447deddb18ba736f Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 3 Aug 2019 16:35:46 +0200 Subject: [PATCH] missing_fragment_specifier -> hard error --- src/doc/rustc/src/lints/listing/deny-by-default.md | 10 ---------- src/librustc/lint/builtin.rs | 7 ------- src/librustc_interface/passes.rs | 13 ------------- src/librustc_lint/lib.rs | 7 ++----- src/libsyntax/ext/tt/macro_parser.rs | 11 ++--------- src/libsyntax/ext/tt/quoted.rs | 4 +++- src/libsyntax/parse/lexer/tests.rs | 3 +-- src/libsyntax/parse/mod.rs | 2 -- src/test/ui/issues/issue-39404.rs | 3 --- src/test/ui/issues/issue-39404.stderr | 6 +----- src/test/ui/macros/macro-match-nonterminal.rs | 5 ++++- src/test/ui/macros/macro-match-nonterminal.stderr | 14 +++++++++++++- src/test/ui/macros/macro-missing-fragment.rs | 4 +++- src/test/ui/macros/macro-missing-fragment.stderr | 8 +++++++- src/test/ui/parser/macro/issue-33569.rs | 1 + src/test/ui/parser/macro/issue-33569.stderr | 10 ++++++++-- 16 files changed, 45 insertions(+), 63 deletions(-) diff --git a/src/doc/rustc/src/lints/listing/deny-by-default.md b/src/doc/rustc/src/lints/listing/deny-by-default.md index 6574267f18511..794c773424ca1 100644 --- a/src/doc/rustc/src/lints/listing/deny-by-default.md +++ b/src/doc/rustc/src/lints/listing/deny-by-default.md @@ -91,16 +91,6 @@ The legacy_directory_ownership warning is issued when The warning can be fixed by renaming the parent module to "mod.rs" and moving it into its own directory if appropriate. - -## missing-fragment-specifier - -The missing_fragment_specifier warning is issued when an unused pattern in a -`macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not -followed by a fragment specifier (e.g. `:expr`). - -This warning can always be fixed by removing the unused pattern in the -`macro_rules!` macro definition. - ## mutable-transmutes This lint catches transmuting from `&T` to `&mut T` because it is undefined diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 6d9a6bb77dd55..faa4b58777d03 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -182,12 +182,6 @@ declare_lint! { "detects use of struct constructors that would be invisible with new visibility rules" } -declare_lint! { - pub MISSING_FRAGMENT_SPECIFIER, - Deny, - "detects missing fragment specifiers in unused `macro_rules!` patterns" -} - declare_lint! { pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, Deny, @@ -428,7 +422,6 @@ declare_lint_pass! { PATTERNS_IN_FNS_WITHOUT_BODY, LEGACY_DIRECTORY_OWNERSHIP, LEGACY_CONSTRUCTOR_VISIBILITY, - MISSING_FRAGMENT_SPECIFIER, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, LATE_BOUND_LIFETIME_ARGUMENTS, ORDER_DEPENDENT_TRAIT_OBJECTS, diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index b91c5e403841d..1d3dc8350bffd 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -432,19 +432,6 @@ fn configure_and_expand_inner<'a>( ecx.check_unused_macros(); }); - let mut missing_fragment_specifiers: Vec<_> = ecx.parse_sess - .missing_fragment_specifiers - .borrow() - .iter() - .cloned() - .collect(); - missing_fragment_specifiers.sort(); - - for span in missing_fragment_specifiers { - let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER; - let msg = "missing fragment specifier"; - sess.buffer_lint(lint, ast::CRATE_NODE_ID, span, msg); - } if cfg!(windows) { env::set_var("PATH", &old_path); } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 78bc164ba1a0f..1d62b43c4b212 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -341,11 +341,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { reference: "issue #39207 ", edition: None, }, - FutureIncompatibleInfo { - id: LintId::of(MISSING_FRAGMENT_SPECIFIER), - reference: "issue #40107 ", - edition: None, - }, FutureIncompatibleInfo { id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN), reference: "issue #41620 ", @@ -488,6 +483,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { "converted into hard error, see https://github.com/rust-lang/rust/issues/57742"); store.register_removed("incoherent_fundamental_impls", "converted into hard error, see https://github.com/rust-lang/rust/issues/46205"); + store.register_removed("missing_fragment_specifier", + "converted into hard error, see https://github.com/rust-lang/rust/issues/40107"); } pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index dbf14daa30e75..c1ece22256a7f 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -382,9 +382,7 @@ fn nameize>( n_rec(sess, next_m, res.by_ref(), ret_val)?; }, TokenTree::MetaVarDecl(span, _, id) if id.name == kw::Invalid => { - if sess.missing_fragment_specifiers.borrow_mut().remove(&span) { - return Err((span, "missing fragment specifier".to_string())); - } + return Err((span, "missing fragment specifier".to_string())); } TokenTree::MetaVarDecl(sp, bind_name, _) => { match ret_val.entry(bind_name) { @@ -444,7 +442,6 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool { /// /// # Parameters /// -/// - `sess`: the parsing session into which errors are emitted. /// - `cur_items`: the set of current items to be processed. This should be empty by the end of a /// successful execution of this function. /// - `next_items`: the set of newly generated items. These are used to replenish `cur_items` in @@ -459,7 +456,6 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool { /// /// A `ParseResult`. Note that matches are kept track of through the items generated. fn inner_parse_loop<'root, 'tt>( - sess: &ParseSess, cur_items: &mut SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>, next_items: &mut Vec>, eof_items: &mut SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>, @@ -585,9 +581,7 @@ fn inner_parse_loop<'root, 'tt>( // We need to match a metavar (but the identifier is invalid)... this is an error TokenTree::MetaVarDecl(span, _, id) if id.name == kw::Invalid => { - if sess.missing_fragment_specifiers.borrow_mut().remove(&span) { - return Error(span, "missing fragment specifier".to_string()); - } + return Error(span, "missing fragment specifier".to_string()); } // We need to match a metavar with a valid ident... call out to the black-box @@ -689,7 +683,6 @@ pub fn parse( // parsing from the black-box parser done. The result is that `next_items` will contain a // bunch of possible next matcher positions in `next_items`. match inner_parse_loop( - sess, &mut cur_items, &mut next_items, &mut eof_items, diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index f67e4d368cc8f..f8712a72f4e33 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -241,7 +241,9 @@ pub fn parse( } tree => tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(start_sp), }; - sess.missing_fragment_specifiers.borrow_mut().insert(span); + + sess.span_diagnostic.span_err(span, "missing fragment specifier"); + result.push(TokenTree::MetaVarDecl(span, ident, ast::Ident::invalid())); } diff --git a/src/libsyntax/parse/lexer/tests.rs b/src/libsyntax/parse/lexer/tests.rs index fc47e4f0b185a..2aa101e09de01 100644 --- a/src/libsyntax/parse/lexer/tests.rs +++ b/src/libsyntax/parse/lexer/tests.rs @@ -10,7 +10,7 @@ use crate::with_default_globals; use std::io; use std::path::PathBuf; use syntax_pos::{BytePos, Span, NO_EXPANSION, edition::Edition}; -use rustc_data_structures::fx::{FxHashSet, FxHashMap}; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::{Lock, Once}; fn mk_sess(sm: Lrc) -> ParseSess { @@ -25,7 +25,6 @@ fn mk_sess(sm: Lrc) -> ParseSess { config: CrateConfig::default(), included_mod_stack: Lock::new(Vec::new()), source_map: sm, - missing_fragment_specifiers: Lock::new(FxHashSet::default()), raw_identifier_spans: Lock::new(Vec::new()), registered_diagnostics: Lock::new(ErrorMap::new()), buffered_lints: Lock::new(vec![]), diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 80aa7a35266eb..6cc309b6887ee 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -44,7 +44,6 @@ pub struct ParseSess { pub unstable_features: UnstableFeatures, pub config: CrateConfig, pub edition: Edition, - pub missing_fragment_specifiers: Lock>, /// Places where raw identifiers were used. This is used for feature-gating raw identifiers. pub raw_identifier_spans: Lock>, /// The registered diagnostics codes. @@ -80,7 +79,6 @@ impl ParseSess { span_diagnostic: handler, unstable_features: UnstableFeatures::from_environment(), config: FxHashSet::default(), - missing_fragment_specifiers: Lock::new(FxHashSet::default()), raw_identifier_spans: Lock::new(Vec::new()), registered_diagnostics: Lock::new(ErrorMap::new()), included_mod_stack: Lock::new(vec![]), diff --git a/src/test/ui/issues/issue-39404.rs b/src/test/ui/issues/issue-39404.rs index 2229f2c3900c3..095590daec573 100644 --- a/src/test/ui/issues/issue-39404.rs +++ b/src/test/ui/issues/issue-39404.rs @@ -1,7 +1,4 @@ -#![allow(unused)] - macro_rules! m { ($i) => {} } //~^ ERROR missing fragment specifier -//~| WARN previously accepted fn main() {} diff --git a/src/test/ui/issues/issue-39404.stderr b/src/test/ui/issues/issue-39404.stderr index d2f2a823c2a6b..e95474f3405d2 100644 --- a/src/test/ui/issues/issue-39404.stderr +++ b/src/test/ui/issues/issue-39404.stderr @@ -1,12 +1,8 @@ error: missing fragment specifier - --> $DIR/issue-39404.rs:3:19 + --> $DIR/issue-39404.rs:1:19 | LL | macro_rules! m { ($i) => {} } | ^^ - | - = note: `#[deny(missing_fragment_specifier)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #40107 error: aborting due to previous error diff --git a/src/test/ui/macros/macro-match-nonterminal.rs b/src/test/ui/macros/macro-match-nonterminal.rs index 6d4b32c9bc9a0..36640a6c70057 100644 --- a/src/test/ui/macros/macro-match-nonterminal.rs +++ b/src/test/ui/macros/macro-match-nonterminal.rs @@ -1,4 +1,7 @@ -macro_rules! test { ($a, $b) => (()); } //~ ERROR missing fragment +macro_rules! test { ($a, $b) => (()); } +//~^ ERROR missing fragment +//~| ERROR missing fragment +//~| ERROR missing fragment fn main() { test!() diff --git a/src/test/ui/macros/macro-match-nonterminal.stderr b/src/test/ui/macros/macro-match-nonterminal.stderr index 1de8c5bd4b472..815471a79d6a3 100644 --- a/src/test/ui/macros/macro-match-nonterminal.stderr +++ b/src/test/ui/macros/macro-match-nonterminal.stderr @@ -4,5 +4,17 @@ error: missing fragment specifier LL | macro_rules! test { ($a, $b) => (()); } | ^ -error: aborting due to previous error +error: missing fragment specifier + --> $DIR/macro-match-nonterminal.rs:1:26 + | +LL | macro_rules! test { ($a, $b) => (()); } + | ^^ + +error: missing fragment specifier + --> $DIR/macro-match-nonterminal.rs:1:24 + | +LL | macro_rules! test { ($a, $b) => (()); } + | ^ + +error: aborting due to 3 previous errors diff --git a/src/test/ui/macros/macro-missing-fragment.rs b/src/test/ui/macros/macro-missing-fragment.rs index 1d0b0889b4cef..846dbe35cbc8c 100644 --- a/src/test/ui/macros/macro-missing-fragment.rs +++ b/src/test/ui/macros/macro-missing-fragment.rs @@ -1,5 +1,7 @@ macro_rules! m { - ( $( any_token $field_rust_type )* ) => {}; //~ ERROR missing fragment + ( $( any_token $field_rust_type )* ) => {}; + //~^ ERROR missing fragment + //~| ERROR missing fragment } fn main() { diff --git a/src/test/ui/macros/macro-missing-fragment.stderr b/src/test/ui/macros/macro-missing-fragment.stderr index b7871c0ec3a6f..b0459e21f1148 100644 --- a/src/test/ui/macros/macro-missing-fragment.stderr +++ b/src/test/ui/macros/macro-missing-fragment.stderr @@ -4,5 +4,11 @@ error: missing fragment specifier LL | ( $( any_token $field_rust_type )* ) => {}; | ^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: missing fragment specifier + --> $DIR/macro-missing-fragment.rs:2:20 + | +LL | ( $( any_token $field_rust_type )* ) => {}; + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors diff --git a/src/test/ui/parser/macro/issue-33569.rs b/src/test/ui/parser/macro/issue-33569.rs index 9ed53519ceb31..d2581398f4403 100644 --- a/src/test/ui/parser/macro/issue-33569.rs +++ b/src/test/ui/parser/macro/issue-33569.rs @@ -1,6 +1,7 @@ macro_rules! foo { { $+ } => { //~ ERROR expected identifier, found `+` //~^ ERROR missing fragment specifier + //~| ERROR missing fragment specifier $(x)(y) //~ ERROR expected one of: `*`, `+`, or `?` } } diff --git a/src/test/ui/parser/macro/issue-33569.stderr b/src/test/ui/parser/macro/issue-33569.stderr index b4d38d3ce4806..e0e84fee4ea3f 100644 --- a/src/test/ui/parser/macro/issue-33569.stderr +++ b/src/test/ui/parser/macro/issue-33569.stderr @@ -4,8 +4,14 @@ error: expected identifier, found `+` LL | { $+ } => { | ^ +error: missing fragment specifier + --> $DIR/issue-33569.rs:2:8 + | +LL | { $+ } => { + | ^ + error: expected one of: `*`, `+`, or `?` - --> $DIR/issue-33569.rs:4:13 + --> $DIR/issue-33569.rs:5:13 | LL | $(x)(y) | ^^^ @@ -16,5 +22,5 @@ error: missing fragment specifier LL | { $+ } => { | ^ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors