Skip to content

Commit 1dc388b

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 d8f053b commit 1dc388b

23 files changed

+104
-338
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/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ fn register_builtins(store: &mut LintStore) {
619619
"converted into hard error, \
620620
see <https://github.com/rust-lang/rust/issues/116558> for more information",
621621
);
622+
store.register_removed(
623+
"missing_fragment_specifier",
624+
"converted into hard error, \
625+
see <https://github.com/rust-lang/rust/issues/40107> for more information",
626+
);
622627
}
623628

624629
fn register_internals(store: &mut LintStore) {

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/future-incompatible-lint-group.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
// lints for changes that are not tied to an edition
33
#![deny(future_incompatible)]
44

5-
// Error since this is a `future_incompatible` lint
6-
macro_rules! m { ($i) => {} } //~ ERROR missing fragment specifier
7-
//~| WARN this was previously accepted
5+
enum E { V }
86

9-
trait Tr {
7+
trait Tr1 {
8+
type V;
9+
fn foo() -> Self::V;
10+
}
11+
12+
impl Tr1 for E {
13+
type V = u8;
14+
15+
// Error since this is a `future_incompatible` lint
16+
fn foo() -> Self::V { 0 }
17+
//~^ ERROR ambiguous associated item
18+
//~| WARN this was previously accepted
19+
}
20+
21+
trait Tr2 {
1022
// Warn only since this is not a `future_incompatible` lint
1123
fn f(u8) {} //~ WARN anonymous parameters are deprecated
1224
//~| WARN this is accepted in the current edition
Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
error: missing fragment specifier
2-
--> $DIR/future-incompatible-lint-group.rs:6:19
3-
|
4-
LL | macro_rules! m { ($i) => {} }
5-
| ^^
6-
|
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: the lint level is defined here
10-
--> $DIR/future-incompatible-lint-group.rs:3:9
11-
|
12-
LL | #![deny(future_incompatible)]
13-
| ^^^^^^^^^^^^^^^^^^^
14-
= note: `#[deny(missing_fragment_specifier)]` implied by `#[deny(future_incompatible)]`
15-
161
warning: anonymous parameters are deprecated and will be removed in the next edition
17-
--> $DIR/future-incompatible-lint-group.rs:11:10
2+
--> $DIR/future-incompatible-lint-group.rs:23:10
183
|
194
LL | fn f(u8) {}
205
| ^^ help: try naming the parameter or explicitly ignoring it: `_: u8`
@@ -23,21 +8,30 @@ LL | fn f(u8) {}
238
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
249
= note: `#[warn(anonymous_parameters)]` on by default
2510

26-
error: aborting due to 1 previous error; 1 warning emitted
27-
28-
Future incompatibility report: Future breakage diagnostic:
29-
error: missing fragment specifier
30-
--> $DIR/future-incompatible-lint-group.rs:6:19
11+
error: ambiguous associated item
12+
--> $DIR/future-incompatible-lint-group.rs:16:17
3113
|
32-
LL | macro_rules! m { ($i) => {} }
33-
| ^^
14+
LL | fn foo() -> Self::V { 0 }
15+
| ^^^^^^^ help: use fully-qualified syntax: `<E as Tr1>::V`
3416
|
3517
= 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>
18+
= note: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
19+
note: `V` could refer to the variant defined here
20+
--> $DIR/future-incompatible-lint-group.rs:5:10
21+
|
22+
LL | enum E { V }
23+
| ^
24+
note: `V` could also refer to the associated type defined here
25+
--> $DIR/future-incompatible-lint-group.rs:8:5
26+
|
27+
LL | type V;
28+
| ^^^^^^
3729
note: the lint level is defined here
3830
--> $DIR/future-incompatible-lint-group.rs:3:9
3931
|
4032
LL | #![deny(future_incompatible)]
4133
| ^^^^^^^^^^^^^^^^^^^
42-
= note: `#[deny(missing_fragment_specifier)]` implied by `#[deny(future_incompatible)]`
34+
= note: `#[deny(ambiguous_associated_items)]` implied by `#[deny(future_incompatible)]`
35+
36+
error: aborting due to 1 previous error; 1 warning emitted
4337

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
}

0 commit comments

Comments
 (0)