Skip to content

Commit 8002683

Browse files
authored
Rollup merge of rust-lang#128425 - tgross35:missing-fragment-specifier-unconditional, r=petrochenkov,traviscross
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, across all editions. More context: rust-lang#128006 Most recent crater: rust-lang#128425 (comment) Fixes: rust-lang#40107 [1]: rust-lang#75516 [2]: rust-lang#80210 [3]: rust-lang#128006
2 parents bb3a3c5 + 841f7ce commit 8002683

25 files changed

+105
-342
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/rustdoc/macro/macro-generated-macro.macro_morestuff_pre.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
macro_rules! morestuff {
22
(
3-
<= "space between most kinds of tokens" : 1 $x + @ :: >>= 'static
4-
"no space inside paren or bracket" : (2 a) [2 a] $(2 $a:tt)*
3+
<= "space between most kinds of tokens" : 1 $x:ident + @ :: >>=
4+
'static "no space inside paren or bracket" : (2 a) [2 a] $(2 $a:tt)*
55
"space inside curly brace" : { 2 a }
66
"no space inside empty delimiters" : () [] {}
77
"no space before comma or semicolon" : a, (a), { a }, a; [T; 0];

tests/rustdoc/macro/macro-generated-macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ make_macro!(linebreak 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
2525

2626
//@ snapshot macro_morestuff_pre macro_generated_macro/macro.morestuff.html //pre/text()
2727
make_macro!(morestuff
28-
"space between most kinds of tokens": 1 $x + @ :: >>= 'static
28+
"space between most kinds of tokens": 1 $x:ident + @ :: >>= 'static
2929
"no space inside paren or bracket": (2 a) [2 a] $(2 $a:tt)*
3030
"space inside curly brace": { 2 a }
3131
"no space inside empty delimiters": () [] {}

0 commit comments

Comments
 (0)