Skip to content

Commit 84b1d92

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]: #75516 [2]: #80210 [3]: #128006
1 parent d13a431 commit 84b1d92

20 files changed

+64
-309
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ expand_meta_var_expr_unrecognized_var =
112112
variable `{$key}` is not recognized in meta-variable expression
113113
114114
expand_missing_fragment_specifier = missing fragment specifier
115-
.note = fragment specifiers must be specified in the 2024 edition
115+
.note = fragment specifiers must be provided
116116
.suggestion_add_fragspec = try adding a specifier here
117117
.valid = {$valid}
118118

compiler/rustc_expand/src/mbe/macro_check.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ use rustc_ast::{DUMMY_NODE_ID, NodeId};
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::{ErrorGuaranteed, MacroRulesNormalizedIdent, Span, kw};
119118
use smallvec::SmallVec;
120119

@@ -266,23 +265,11 @@ fn check_binders(
266265
// Similarly, this can only happen when checking a toplevel macro.
267266
TokenTree::MetaVarDecl(span, name, kind) => {
268267
if kind.is_none() && node_id != DUMMY_NODE_ID {
269-
// FIXME: Report this as a hard error eventually and remove equivalent errors from
270-
// `parse_tt_inner` and `nameize`. Until then the error may be reported twice, once
271-
// as a hard error and then once as a buffered lint.
272-
if span.edition() >= Edition::Edition2024 {
273-
psess.dcx().emit_err(errors::MissingFragmentSpecifier {
274-
span,
275-
add_span: span.shrink_to_hi(),
276-
valid: VALID_FRAGMENT_NAMES_MSG,
277-
});
278-
} else {
279-
psess.buffer_lint(
280-
MISSING_FRAGMENT_SPECIFIER,
281-
span,
282-
node_id,
283-
BuiltinLintDiag::MissingFragmentSpecifier,
284-
);
285-
}
268+
psess.dcx().emit_err(errors::MissingFragmentSpecifier {
269+
span,
270+
add_span: span.shrink_to_hi(),
271+
valid: VALID_FRAGMENT_NAMES_MSG,
272+
});
286273
}
287274
if !macros.is_empty() {
288275
psess.dcx().span_bug(span, "unexpected MetaVarDecl in nested lhs");

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,6 @@ lint_mismatched_lifetime_syntaxes_suggestion_implicit =
533533
lint_mismatched_lifetime_syntaxes_suggestion_mixed =
534534
one option is to remove the lifetime for references and use the anonymous lifetime for paths
535535
536-
lint_missing_fragment_specifier = missing fragment specifier
537-
538536
lint_missing_unsafe_on_extern = extern blocks should be unsafe
539537
.suggestion = needs `unsafe` before the extern keyword
540538

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,6 @@ pub fn decorate_builtin_lint(
432432
BuiltinLintDiag::CfgAttrNoAttributes => {
433433
lints::CfgAttrNoAttributes.decorate_lint(diag);
434434
}
435-
BuiltinLintDiag::MissingFragmentSpecifier => {
436-
lints::MissingFragmentSpecifier.decorate_lint(diag);
437-
}
438435
BuiltinLintDiag::MetaVariableStillRepeating(name) => {
439436
lints::MetaVariableStillRepeating { name }.decorate_lint(diag);
440437
}

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,10 +2616,6 @@ pub(crate) struct DuplicateMacroAttribute;
26162616
#[diag(lint_cfg_attr_no_attributes)]
26172617
pub(crate) struct CfgAttrNoAttributes;
26182618

2619-
#[derive(LintDiagnostic)]
2620-
#[diag(lint_missing_fragment_specifier)]
2621-
pub(crate) struct MissingFragmentSpecifier;
2622-
26232619
#[derive(LintDiagnostic)]
26242620
#[diag(lint_metavariable_still_repeating)]
26252621
pub(crate) struct MetaVariableStillRepeating {

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ declare_lint_pass! {
6565
MACRO_USE_EXTERN_CRATE,
6666
META_VARIABLE_MISUSE,
6767
MISSING_ABI,
68-
MISSING_FRAGMENT_SPECIFIER,
6968
MISSING_UNSAFE_ON_EXTERN,
7069
MUST_NOT_SUSPEND,
7170
NAMED_ARGUMENTS_USED_POSITIONALLY,
@@ -1417,51 +1416,6 @@ declare_lint! {
14171416
};
14181417
}
14191418

1420-
declare_lint! {
1421-
/// The `missing_fragment_specifier` lint is issued when an unused pattern in a
1422-
/// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
1423-
/// followed by a fragment specifier (e.g. `:expr`).
1424-
///
1425-
/// This warning can always be fixed by removing the unused pattern in the
1426-
/// `macro_rules!` macro definition.
1427-
///
1428-
/// ### Example
1429-
///
1430-
/// ```rust,compile_fail,edition2021
1431-
/// macro_rules! foo {
1432-
/// () => {};
1433-
/// ($name) => { };
1434-
/// }
1435-
///
1436-
/// fn main() {
1437-
/// foo!();
1438-
/// }
1439-
/// ```
1440-
///
1441-
/// {{produces}}
1442-
///
1443-
/// ### Explanation
1444-
///
1445-
/// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
1446-
///
1447-
/// ```rust
1448-
/// macro_rules! foo {
1449-
/// () => {};
1450-
/// }
1451-
/// fn main() {
1452-
/// foo!();
1453-
/// }
1454-
/// ```
1455-
pub MISSING_FRAGMENT_SPECIFIER,
1456-
Deny,
1457-
"detects missing fragment specifiers in unused `macro_rules!` patterns",
1458-
@future_incompatible = FutureIncompatibleInfo {
1459-
reason: FutureIncompatibilityReason::FutureReleaseError,
1460-
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
1461-
report_in_deps: true,
1462-
};
1463-
}
1464-
14651419
declare_lint! {
14661420
/// The `late_bound_lifetime_arguments` lint detects generic lifetime
14671421
/// arguments in path segments with late bound lifetime parameters.

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ pub enum BuiltinLintDiag {
778778
UnnameableTestItems,
779779
DuplicateMacroAttribute,
780780
CfgAttrNoAttributes,
781-
MissingFragmentSpecifier,
782781
MetaVariableStillRepeating(MacroRulesNormalizedIdent),
783782
MetaVariableWrongOperator,
784783
DuplicateMatcherBinding,

tests/ui/lint/expansion-time.rs

Lines changed: 0 additions & 4 deletions
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
#[deprecated = "reason"]
139
macro_rules! deprecated {
1410
() => {}

tests/ui/lint/expansion-time.stderr

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,17 @@ 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: include macro expected single expression in source
3016
--> $DIR/expansion-time-include.rs:4:1
3117
|
3218
LL | 2
3319
| ^
3420
|
3521
note: the lint level is defined here
36-
--> $DIR/expansion-time.rs:22:8
22+
--> $DIR/expansion-time.rs:18:8
3723
|
3824
LL | #[warn(incomplete_include)]
3925
| ^^^^^^^^^^^^^^^^^^
4026

41-
warning: 3 warnings emitted
42-
43-
Future incompatibility report: Future breakage diagnostic:
44-
warning: missing fragment specifier
45-
--> $DIR/expansion-time.rs:9:19
46-
|
47-
LL | macro_rules! m { ($i) => {} }
48-
| ^^
49-
|
50-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
51-
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
52-
note: the lint level is defined here
53-
--> $DIR/expansion-time.rs:8:8
54-
|
55-
LL | #[warn(missing_fragment_specifier)]
56-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
27+
warning: 2 warnings emitted
5728

tests/ui/macros/issue-39404.rs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 9 additions & 17 deletions
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 provided
8+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`, along with `expr_2021` and `pat_param` for edition compatibility
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 12 additions & 27 deletions
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:6
96
|
10-
LL | ($a, $b) => {
11-
| ^^
7+
= note: fragment specifiers must be provided
8+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`, along with `expr_2021` and `pat_param` for edition compatibility
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 provided
21+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`, along with `expr_2021` and `pat_param` for edition compatibility
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:6
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

Lines changed: 2 additions & 4 deletions
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() {
Lines changed: 9 additions & 17 deletions
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 provided
8+
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`, along with `expr_2021` and `pat_param` for edition compatibility
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)