Skip to content

missing_fragment_specifier -> hard error #63239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/doc/rustc/src/lints/listing/deny-by-default.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
@@ -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,
13 changes: 0 additions & 13 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 2 additions & 5 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
@@ -341,11 +341,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
edition: None,
},
FutureIncompatibleInfo {
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
edition: None,
},
FutureIncompatibleInfo {
id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN),
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/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>) {
11 changes: 2 additions & 9 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
@@ -382,9 +382,7 @@ fn nameize<I: Iterator<Item = NamedMatch>>(
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<MatcherPosHandle<'root, 'tt>>,
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,
4 changes: 3 additions & 1 deletion src/libsyntax/ext/tt/quoted.rs
Original file line number Diff line number Diff line change
@@ -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()));
}

3 changes: 1 addition & 2 deletions src/libsyntax/parse/lexer/tests.rs
Original file line number Diff line number Diff line change
@@ -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<SourceMap>) -> ParseSess {
@@ -25,7 +25,6 @@ fn mk_sess(sm: Lrc<SourceMap>) -> 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![]),
2 changes: 0 additions & 2 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ pub struct ParseSess {
pub unstable_features: UnstableFeatures,
pub config: CrateConfig,
pub edition: Edition,
pub missing_fragment_specifiers: Lock<FxHashSet<Span>>,
/// Places where raw identifiers were used. This is used for feature-gating raw identifiers.
pub raw_identifier_spans: Lock<Vec<Span>>,
/// 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![]),
3 changes: 0 additions & 3 deletions src/test/ui/issues/issue-39404.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#![allow(unused)]

macro_rules! m { ($i) => {} }
//~^ ERROR missing fragment specifier
//~| WARN previously accepted

fn main() {}
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-39404.stderr
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/40107>

error: aborting due to previous error

5 changes: 4 additions & 1 deletion src/test/ui/macros/macro-match-nonterminal.rs
Original file line number Diff line number Diff line change
@@ -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!()
14 changes: 13 additions & 1 deletion src/test/ui/macros/macro-match-nonterminal.stderr
Original file line number Diff line number Diff line change
@@ -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

4 changes: 3 additions & 1 deletion src/test/ui/macros/macro-missing-fragment.rs
Original file line number Diff line number Diff line change
@@ -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() {
8 changes: 7 additions & 1 deletion src/test/ui/macros/macro-missing-fragment.stderr
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions src/test/ui/parser/macro/issue-33569.rs
Original file line number Diff line number Diff line change
@@ -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 `?`
}
}
10 changes: 8 additions & 2 deletions src/test/ui/parser/macro/issue-33569.stderr
Original file line number Diff line number Diff line change
@@ -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