Skip to content

Commit f2d1d82

Browse files
committed
Make missing_fragment_specifier an unconditional error
This was attempted in [1] then reverted in [2] because of fallout. Recently, this was made an edition-dependent error in [3]. Make missing fragment specifiers an unconditional error again. [1]: rust-lang#75516 [2]: rust-lang#80210 [3]: rust-lang#128006
1 parent 249cf71 commit f2d1d82

19 files changed

+63
-310
lines changed

compiler/rustc_expand/src/mbe/macro_check.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ use rustc_ast::{NodeId, DUMMY_NODE_ID};
112112
use rustc_data_structures::fx::FxHashMap;
113113
use rustc_errors::MultiSpan;
114114
use rustc_lint_defs::BuiltinLintDiag;
115-
use rustc_session::lint::builtin::{META_VARIABLE_MISUSE, MISSING_FRAGMENT_SPECIFIER};
115+
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
116116
use rustc_session::parse::ParseSess;
117-
use rustc_span::edition::Edition;
118117
use rustc_span::symbol::{kw, MacroRulesNormalizedIdent};
119118
use rustc_span::{ErrorGuaranteed, Span};
120119
use smallvec::SmallVec;
@@ -267,23 +266,11 @@ fn check_binders(
267266
// Similarly, this can only happen when checking a toplevel macro.
268267
TokenTree::MetaVarDecl(span, name, kind) => {
269268
if kind.is_none() && node_id != DUMMY_NODE_ID {
270-
// FIXME: Report this as a hard error eventually and remove equivalent errors from
271-
// `parse_tt_inner` and `nameize`. Until then the error may be reported twice, once
272-
// as a hard error and then once as a buffered lint.
273-
if span.edition() >= Edition::Edition2024 {
274-
psess.dcx().emit_err(errors::MissingFragmentSpecifier {
275-
span,
276-
add_span: span.shrink_to_hi(),
277-
valid: VALID_FRAGMENT_NAMES_MSG_2021,
278-
});
279-
} else {
280-
psess.buffer_lint(
281-
MISSING_FRAGMENT_SPECIFIER,
282-
span,
283-
node_id,
284-
BuiltinLintDiag::MissingFragmentSpecifier,
285-
);
286-
}
269+
psess.dcx().emit_err(errors::MissingFragmentSpecifier {
270+
span,
271+
add_span: span.shrink_to_hi(),
272+
valid: VALID_FRAGMENT_NAMES_MSG_2021,
273+
});
287274
}
288275
if !macros.is_empty() {
289276
psess.dcx().span_bug(span, "unexpected MetaVarDecl in nested lhs");

compiler/rustc_lint/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,6 @@ lint_metavariable_still_repeating = variable `{$name}` is still repeating at thi
489489
490490
lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
491491
492-
lint_missing_fragment_specifier = missing fragment specifier
493-
494492
lint_missing_unsafe_on_extern = extern blocks should be unsafe
495493
.suggestion = needs `unsafe` before the extern keyword
496494

compiler/rustc_lint/src/context/diagnostics.rs

-3
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,6 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
401401
BuiltinLintDiag::CrateNameInCfgAttr => {
402402
lints::CrateNameInCfgAttr.decorate_lint(diag);
403403
}
404-
BuiltinLintDiag::MissingFragmentSpecifier => {
405-
lints::MissingFragmentSpecifier.decorate_lint(diag);
406-
}
407404
BuiltinLintDiag::MetaVariableStillRepeating(name) => {
408405
lints::MetaVariableStillRepeating { name }.decorate_lint(diag);
409406
}

compiler/rustc_lint/src/lints.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2459,10 +2459,6 @@ pub struct CrateTypeInCfgAttr;
24592459
#[diag(lint_crate_name_in_cfg_attr_deprecated)]
24602460
pub struct CrateNameInCfgAttr;
24612461

2462-
#[derive(LintDiagnostic)]
2463-
#[diag(lint_missing_fragment_specifier)]
2464-
pub struct MissingFragmentSpecifier;
2465-
24662462
#[derive(LintDiagnostic)]
24672463
#[diag(lint_metavariable_still_repeating)]
24682464
pub struct MetaVariableStillRepeating {

compiler/rustc_lint_defs/src/builtin.rs

-45
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ declare_lint_pass! {
6666
MACRO_USE_EXTERN_CRATE,
6767
META_VARIABLE_MISUSE,
6868
MISSING_ABI,
69-
MISSING_FRAGMENT_SPECIFIER,
7069
MISSING_UNSAFE_ON_EXTERN,
7170
MUST_NOT_SUSPEND,
7271
NAMED_ARGUMENTS_USED_POSITIONALLY,
@@ -1385,50 +1384,6 @@ declare_lint! {
13851384
};
13861385
}
13871386

1388-
declare_lint! {
1389-
/// The `missing_fragment_specifier` lint is issued when an unused pattern in a
1390-
/// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
1391-
/// followed by a fragment specifier (e.g. `:expr`).
1392-
///
1393-
/// This warning can always be fixed by removing the unused pattern in the
1394-
/// `macro_rules!` macro definition.
1395-
///
1396-
/// ### Example
1397-
///
1398-
/// ```rust,compile_fail
1399-
/// macro_rules! foo {
1400-
/// () => {};
1401-
/// ($name) => { };
1402-
/// }
1403-
///
1404-
/// fn main() {
1405-
/// foo!();
1406-
/// }
1407-
/// ```
1408-
///
1409-
/// {{produces}}
1410-
///
1411-
/// ### Explanation
1412-
///
1413-
/// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
1414-
///
1415-
/// ```rust
1416-
/// macro_rules! foo {
1417-
/// () => {};
1418-
/// }
1419-
/// fn main() {
1420-
/// foo!();
1421-
/// }
1422-
/// ```
1423-
pub MISSING_FRAGMENT_SPECIFIER,
1424-
Deny,
1425-
"detects missing fragment specifiers in unused `macro_rules!` patterns",
1426-
@future_incompatible = FutureIncompatibleInfo {
1427-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
1428-
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
1429-
};
1430-
}
1431-
14321387
declare_lint! {
14331388
/// The `late_bound_lifetime_arguments` lint detects generic lifetime
14341389
/// arguments in path segments with late bound lifetime parameters.

compiler/rustc_lint_defs/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ pub enum BuiltinLintDiag {
727727
CfgAttrNoAttributes,
728728
CrateTypeInCfgAttr,
729729
CrateNameInCfgAttr,
730-
MissingFragmentSpecifier,
731730
MetaVariableStillRepeating(MacroRulesNormalizedIdent),
732731
MetaVariableWrongOperator,
733732
DuplicateMatcherBinding,

tests/ui/lint/expansion-time.rs

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ macro_rules! foo {
55
( $($i:ident)* ) => { $($i)+ }; //~ WARN meta-variable repeats with different Kleene operator
66
}
77

8-
#[warn(missing_fragment_specifier)]
9-
macro_rules! m { ($i) => {} } //~ WARN missing fragment specifier
10-
//~| WARN this was previously accepted
11-
128
#[warn(soft_unstable)]
139
mod benches {
1410
#[bench] //~ WARN use of unstable library feature 'test'

tests/ui/lint/expansion-time.stderr

+6-35
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,16 @@ note: the lint level is defined here
1212
LL | #[warn(meta_variable_misuse)]
1313
| ^^^^^^^^^^^^^^^^^^^^
1414

15-
warning: missing fragment specifier
16-
--> $DIR/expansion-time.rs:9:19
17-
|
18-
LL | macro_rules! m { ($i) => {} }
19-
| ^^
20-
|
21-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
23-
note: the lint level is defined here
24-
--> $DIR/expansion-time.rs:8:8
25-
|
26-
LL | #[warn(missing_fragment_specifier)]
27-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
28-
2915
warning: use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable
30-
--> $DIR/expansion-time.rs:14:7
16+
--> $DIR/expansion-time.rs:10:7
3117
|
3218
LL | #[bench]
3319
| ^^^^^
3420
|
3521
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3622
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
3723
note: the lint level is defined here
38-
--> $DIR/expansion-time.rs:12:8
24+
--> $DIR/expansion-time.rs:8:8
3925
|
4026
LL | #[warn(soft_unstable)]
4127
| ^^^^^^^^^^^^^
@@ -47,39 +33,24 @@ LL | 2
4733
| ^
4834
|
4935
note: the lint level is defined here
50-
--> $DIR/expansion-time.rs:29:8
36+
--> $DIR/expansion-time.rs:25:8
5137
|
5238
LL | #[warn(incomplete_include)]
5339
| ^^^^^^^^^^^^^^^^^^
5440

55-
warning: 4 warnings emitted
41+
warning: 3 warnings emitted
5642

5743
Future incompatibility report: Future breakage diagnostic:
58-
warning: missing fragment specifier
59-
--> $DIR/expansion-time.rs:9:19
60-
|
61-
LL | macro_rules! m { ($i) => {} }
62-
| ^^
63-
|
64-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
65-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
66-
note: the lint level is defined here
67-
--> $DIR/expansion-time.rs:8:8
68-
|
69-
LL | #[warn(missing_fragment_specifier)]
70-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
71-
72-
Future breakage diagnostic:
7344
warning: use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable
74-
--> $DIR/expansion-time.rs:14:7
45+
--> $DIR/expansion-time.rs:10:7
7546
|
7647
LL | #[bench]
7748
| ^^^^^
7849
|
7950
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8051
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
8152
note: the lint level is defined here
82-
--> $DIR/expansion-time.rs:12:8
53+
--> $DIR/expansion-time.rs:8:8
8354
|
8455
LL | #[warn(soft_unstable)]
8556
| ^^^^^^^^^^^^^

tests/ui/macros/issue-39404.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused)]
22

3-
macro_rules! m { ($i) => {} }
4-
//~^ ERROR missing fragment specifier
5-
//~| WARN previously accepted
3+
macro_rules! m {
4+
($i) => {}; //~ ERROR missing fragment specifier
5+
}
66

77
fn main() {}

tests/ui/macros/issue-39404.stderr

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
error: missing fragment specifier
2-
--> $DIR/issue-39404.rs:3:19
2+
--> $DIR/issue-39404.rs:4:6
33
|
4-
LL | macro_rules! m { ($i) => {} }
5-
| ^^
4+
LL | ($i) => {};
5+
| ^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
9-
= note: `#[deny(missing_fragment_specifier)]` on by default
7+
= note: fragment specifiers must be specified in the 2024 edition
8+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
9+
help: try adding a specifier here
10+
|
11+
LL | ($i:spec) => {};
12+
| +++++
1013

1114
error: aborting due to 1 previous error
1215

13-
Future incompatibility report: Future breakage diagnostic:
14-
error: missing fragment specifier
15-
--> $DIR/issue-39404.rs:3:19
16-
|
17-
LL | macro_rules! m { ($i) => {} }
18-
| ^^
19-
|
20-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
21-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
22-
= note: `#[deny(missing_fragment_specifier)]` on by default
23-

tests/ui/macros/macro-match-nonterminal.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ macro_rules! test {
33
//~^ ERROR missing fragment
44
//~| ERROR missing fragment
55
//~| ERROR missing fragment
6-
//~| WARN this was previously accepted
7-
//~| WARN this was previously accepted
86
()
97
};
108
}

tests/ui/macros/macro-match-nonterminal.stderr

+12-27
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,32 @@ error: missing fragment specifier
33
|
44
LL | ($a, $b) => {
55
| ^
6-
7-
error: missing fragment specifier
8-
--> $DIR/macro-match-nonterminal.rs:2:8
96
|
10-
LL | ($a, $b) => {
11-
| ^
7+
= note: fragment specifiers must be specified in the 2024 edition
8+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
9+
help: try adding a specifier here
1210
|
13-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
15-
= note: `#[deny(missing_fragment_specifier)]` on by default
11+
LL | ($a,:spec $b) => {
12+
| +++++
1613

1714
error: missing fragment specifier
1815
--> $DIR/macro-match-nonterminal.rs:2:10
1916
|
2017
LL | ($a, $b) => {
2118
| ^^
2219
|
23-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
25-
26-
error: aborting due to 3 previous errors
20+
= note: fragment specifiers must be specified in the 2024 edition
21+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
22+
help: try adding a specifier here
23+
|
24+
LL | ($a, $b:spec) => {
25+
| +++++
2726

28-
Future incompatibility report: Future breakage diagnostic:
2927
error: missing fragment specifier
3028
--> $DIR/macro-match-nonterminal.rs:2:8
3129
|
3230
LL | ($a, $b) => {
3331
| ^
34-
|
35-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
37-
= note: `#[deny(missing_fragment_specifier)]` on by default
3832

39-
Future breakage diagnostic:
40-
error: missing fragment specifier
41-
--> $DIR/macro-match-nonterminal.rs:2:10
42-
|
43-
LL | ($a, $b) => {
44-
| ^^
45-
|
46-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
47-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
48-
= note: `#[deny(missing_fragment_specifier)]` on by default
33+
error: aborting due to 3 previous errors
4934

tests/ui/macros/macro-missing-fragment-deduplication.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
//@ compile-flags: -Zdeduplicate-diagnostics=yes
22

33
macro_rules! m {
4-
($name) => {}
5-
//~^ ERROR missing fragment
6-
//~| ERROR missing fragment
7-
//~| WARN this was previously accepted
4+
($name) => {}; //~ ERROR missing fragment
5+
//~| ERROR missing fragment
86
}
97

108
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
error: missing fragment specifier
22
--> $DIR/macro-missing-fragment-deduplication.rs:4:6
33
|
4-
LL | ($name) => {}
4+
LL | ($name) => {};
55
| ^^^^^
6-
7-
error: missing fragment specifier
8-
--> $DIR/macro-missing-fragment-deduplication.rs:4:6
96
|
10-
LL | ($name) => {}
11-
| ^^^^^
7+
= note: fragment specifiers must be specified in the 2024 edition
8+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
9+
help: try adding a specifier here
1210
|
13-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
15-
= note: `#[deny(missing_fragment_specifier)]` on by default
11+
LL | ($name:spec) => {};
12+
| +++++
1613

17-
error: aborting due to 2 previous errors
18-
19-
Future incompatibility report: Future breakage diagnostic:
2014
error: missing fragment specifier
2115
--> $DIR/macro-missing-fragment-deduplication.rs:4:6
2216
|
23-
LL | ($name) => {}
17+
LL | ($name) => {};
2418
| ^^^^^
25-
|
26-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
28-
= note: `#[deny(missing_fragment_specifier)]` on by default
19+
20+
error: aborting due to 2 previous errors
2921

0 commit comments

Comments
 (0)