Skip to content

Commit 1928f93

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 208cb5d commit 1928f93

23 files changed

+141
-316
lines changed

compiler/rustc_expand/messages.ftl

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

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/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

0 commit comments

Comments
 (0)