Skip to content

Commit 8811502

Browse files
committed
missing_fragment_specifier -> hard error
1 parent 8e917f4 commit 8811502

File tree

16 files changed

+45
-63
lines changed

16 files changed

+45
-63
lines changed

src/doc/rustc/src/lints/listing/deny-by-default.md

-10
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,6 @@ The legacy_directory_ownership warning is issued when
9191
The warning can be fixed by renaming the parent module to "mod.rs" and moving
9292
it into its own directory if appropriate.
9393

94-
95-
## missing-fragment-specifier
96-
97-
The missing_fragment_specifier warning is issued when an unused pattern in a
98-
`macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
99-
followed by a fragment specifier (e.g. `:expr`).
100-
101-
This warning can always be fixed by removing the unused pattern in the
102-
`macro_rules!` macro definition.
103-
10494
## mutable-transmutes
10595

10696
This lint catches transmuting from `&T` to `&mut T` because it is undefined

src/librustc/lint/builtin.rs

-7
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,6 @@ declare_lint! {
182182
"detects use of struct constructors that would be invisible with new visibility rules"
183183
}
184184

185-
declare_lint! {
186-
pub MISSING_FRAGMENT_SPECIFIER,
187-
Deny,
188-
"detects missing fragment specifiers in unused `macro_rules!` patterns"
189-
}
190-
191185
declare_lint! {
192186
pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
193187
Deny,
@@ -428,7 +422,6 @@ declare_lint_pass! {
428422
PATTERNS_IN_FNS_WITHOUT_BODY,
429423
LEGACY_DIRECTORY_OWNERSHIP,
430424
LEGACY_CONSTRUCTOR_VISIBILITY,
431-
MISSING_FRAGMENT_SPECIFIER,
432425
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
433426
LATE_BOUND_LIFETIME_ARGUMENTS,
434427
ORDER_DEPENDENT_TRAIT_OBJECTS,

src/librustc_interface/passes.rs

-13
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,6 @@ fn configure_and_expand_inner<'a>(
432432
ecx.check_unused_macros();
433433
});
434434

435-
let mut missing_fragment_specifiers: Vec<_> = ecx.parse_sess
436-
.missing_fragment_specifiers
437-
.borrow()
438-
.iter()
439-
.cloned()
440-
.collect();
441-
missing_fragment_specifiers.sort();
442-
443-
for span in missing_fragment_specifiers {
444-
let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
445-
let msg = "missing fragment specifier";
446-
sess.buffer_lint(lint, ast::CRATE_NODE_ID, span, msg);
447-
}
448435
if cfg!(windows) {
449436
env::set_var("PATH", &old_path);
450437
}

src/librustc_lint/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
341341
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
342342
edition: None,
343343
},
344-
FutureIncompatibleInfo {
345-
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
346-
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
347-
edition: None,
348-
},
349344
FutureIncompatibleInfo {
350345
id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN),
351346
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>) {
488483
"converted into hard error, see https://github.com/rust-lang/rust/issues/57742");
489484
store.register_removed("incoherent_fundamental_impls",
490485
"converted into hard error, see https://github.com/rust-lang/rust/issues/46205");
486+
store.register_removed("missing_fragment_specifier",
487+
"converted into hard error, see https://github.com/rust-lang/rust/issues/40107");
491488
}
492489

493490
pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) {

src/libsyntax/ext/tt/macro_parser.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,7 @@ fn nameize<I: Iterator<Item = NamedMatch>>(
382382
n_rec(sess, next_m, res.by_ref(), ret_val)?;
383383
},
384384
TokenTree::MetaVarDecl(span, _, id) if id.name == kw::Invalid => {
385-
if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
386-
return Err((span, "missing fragment specifier".to_string()));
387-
}
385+
return Err((span, "missing fragment specifier".to_string()));
388386
}
389387
TokenTree::MetaVarDecl(sp, bind_name, _) => {
390388
match ret_val.entry(bind_name) {
@@ -444,7 +442,6 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
444442
///
445443
/// # Parameters
446444
///
447-
/// - `sess`: the parsing session into which errors are emitted.
448445
/// - `cur_items`: the set of current items to be processed. This should be empty by the end of a
449446
/// successful execution of this function.
450447
/// - `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 {
459456
///
460457
/// A `ParseResult`. Note that matches are kept track of through the items generated.
461458
fn inner_parse_loop<'root, 'tt>(
462-
sess: &ParseSess,
463459
cur_items: &mut SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>,
464460
next_items: &mut Vec<MatcherPosHandle<'root, 'tt>>,
465461
eof_items: &mut SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>,
@@ -585,9 +581,7 @@ fn inner_parse_loop<'root, 'tt>(
585581

586582
// We need to match a metavar (but the identifier is invalid)... this is an error
587583
TokenTree::MetaVarDecl(span, _, id) if id.name == kw::Invalid => {
588-
if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
589-
return Error(span, "missing fragment specifier".to_string());
590-
}
584+
return Error(span, "missing fragment specifier".to_string());
591585
}
592586

593587
// We need to match a metavar with a valid ident... call out to the black-box
@@ -689,7 +683,6 @@ pub fn parse(
689683
// parsing from the black-box parser done. The result is that `next_items` will contain a
690684
// bunch of possible next matcher positions in `next_items`.
691685
match inner_parse_loop(
692-
sess,
693686
&mut cur_items,
694687
&mut next_items,
695688
&mut eof_items,

src/libsyntax/ext/tt/quoted.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ pub fn parse(
241241
}
242242
tree => tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(start_sp),
243243
};
244-
sess.missing_fragment_specifiers.borrow_mut().insert(span);
244+
245+
sess.span_diagnostic.span_err(span, "missing fragment specifier");
246+
245247
result.push(TokenTree::MetaVarDecl(span, ident, ast::Ident::invalid()));
246248
}
247249

src/libsyntax/parse/lexer/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::with_default_globals;
1010
use std::io;
1111
use std::path::PathBuf;
1212
use syntax_pos::{BytePos, Span, NO_EXPANSION, edition::Edition};
13-
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
13+
use rustc_data_structures::fx::FxHashMap;
1414
use rustc_data_structures::sync::{Lock, Once};
1515

1616
fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
@@ -25,7 +25,6 @@ fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
2525
config: CrateConfig::default(),
2626
included_mod_stack: Lock::new(Vec::new()),
2727
source_map: sm,
28-
missing_fragment_specifiers: Lock::new(FxHashSet::default()),
2928
raw_identifier_spans: Lock::new(Vec::new()),
3029
registered_diagnostics: Lock::new(ErrorMap::new()),
3130
buffered_lints: Lock::new(vec![]),

src/libsyntax/parse/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub struct ParseSess {
4444
pub unstable_features: UnstableFeatures,
4545
pub config: CrateConfig,
4646
pub edition: Edition,
47-
pub missing_fragment_specifiers: Lock<FxHashSet<Span>>,
4847
/// Places where raw identifiers were used. This is used for feature-gating raw identifiers.
4948
pub raw_identifier_spans: Lock<Vec<Span>>,
5049
/// The registered diagnostics codes.
@@ -80,7 +79,6 @@ impl ParseSess {
8079
span_diagnostic: handler,
8180
unstable_features: UnstableFeatures::from_environment(),
8281
config: FxHashSet::default(),
83-
missing_fragment_specifiers: Lock::new(FxHashSet::default()),
8482
raw_identifier_spans: Lock::new(Vec::new()),
8583
registered_diagnostics: Lock::new(ErrorMap::new()),
8684
included_mod_stack: Lock::new(vec![]),

src/test/ui/issues/issue-39404.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![allow(unused)]
2-
31
macro_rules! m { ($i) => {} }
42
//~^ ERROR missing fragment specifier
5-
//~| WARN previously accepted
63

74
fn main() {}

src/test/ui/issues/issue-39404.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
error: missing fragment specifier
2-
--> $DIR/issue-39404.rs:3:19
2+
--> $DIR/issue-39404.rs:1:19
33
|
44
LL | macro_rules! m { ($i) => {} }
55
| ^^
6-
|
7-
= note: `#[deny(missing_fragment_specifier)]` on by default
8-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
106

117
error: aborting due to previous error
128

src/test/ui/macros/macro-match-nonterminal.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
macro_rules! test { ($a, $b) => (()); } //~ ERROR missing fragment
1+
macro_rules! test { ($a, $b) => (()); }
2+
//~^ ERROR missing fragment
3+
//~| ERROR missing fragment
4+
//~| ERROR missing fragment
25

36
fn main() {
47
test!()

src/test/ui/macros/macro-match-nonterminal.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,17 @@ error: missing fragment specifier
44
LL | macro_rules! test { ($a, $b) => (()); }
55
| ^
66

7-
error: aborting due to previous error
7+
error: missing fragment specifier
8+
--> $DIR/macro-match-nonterminal.rs:1:26
9+
|
10+
LL | macro_rules! test { ($a, $b) => (()); }
11+
| ^^
12+
13+
error: missing fragment specifier
14+
--> $DIR/macro-match-nonterminal.rs:1:24
15+
|
16+
LL | macro_rules! test { ($a, $b) => (()); }
17+
| ^
18+
19+
error: aborting due to 3 previous errors
820

src/test/ui/macros/macro-missing-fragment.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
macro_rules! m {
2-
( $( any_token $field_rust_type )* ) => {}; //~ ERROR missing fragment
2+
( $( any_token $field_rust_type )* ) => {};
3+
//~^ ERROR missing fragment
4+
//~| ERROR missing fragment
35
}
46

57
fn main() {

src/test/ui/macros/macro-missing-fragment.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ error: missing fragment specifier
44
LL | ( $( any_token $field_rust_type )* ) => {};
55
| ^^^^^^^^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error: missing fragment specifier
8+
--> $DIR/macro-missing-fragment.rs:2:20
9+
|
10+
LL | ( $( any_token $field_rust_type )* ) => {};
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
814

src/test/ui/parser/macro/issue-33569.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
macro_rules! foo {
22
{ $+ } => { //~ ERROR expected identifier, found `+`
33
//~^ ERROR missing fragment specifier
4+
//~| ERROR missing fragment specifier
45
$(x)(y) //~ ERROR expected one of: `*`, `+`, or `?`
56
}
67
}

src/test/ui/parser/macro/issue-33569.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ error: expected identifier, found `+`
44
LL | { $+ } => {
55
| ^
66

7+
error: missing fragment specifier
8+
--> $DIR/issue-33569.rs:2:8
9+
|
10+
LL | { $+ } => {
11+
| ^
12+
713
error: expected one of: `*`, `+`, or `?`
8-
--> $DIR/issue-33569.rs:4:13
14+
--> $DIR/issue-33569.rs:5:13
915
|
1016
LL | $(x)(y)
1117
| ^^^
@@ -16,5 +22,5 @@ error: missing fragment specifier
1622
LL | { $+ } => {
1723
| ^
1824

19-
error: aborting due to 3 previous errors
25+
error: aborting due to 4 previous errors
2026

0 commit comments

Comments
 (0)