Skip to content

Make missing_fragment_specifier an unconditional error #128425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ expand_meta_var_expr_unrecognized_var =
variable `{$key}` is not recognized in meta-variable expression

expand_missing_fragment_specifier = missing fragment specifier
.note = fragment specifiers must be specified in the 2024 edition
.note = fragment specifiers must be provided
.suggestion_add_fragspec = try adding a specifier here
.valid = {$valid}

Expand Down
25 changes: 6 additions & 19 deletions compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ use rustc_ast::{DUMMY_NODE_ID, NodeId};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::MultiSpan;
use rustc_lint_defs::BuiltinLintDiag;
use rustc_session::lint::builtin::{META_VARIABLE_MISUSE, MISSING_FRAGMENT_SPECIFIER};
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
use rustc_session::parse::ParseSess;
use rustc_span::edition::Edition;
use rustc_span::{ErrorGuaranteed, MacroRulesNormalizedIdent, Span, kw};
use smallvec::SmallVec;

Expand Down Expand Up @@ -266,23 +265,11 @@ fn check_binders(
// Similarly, this can only happen when checking a toplevel macro.
TokenTree::MetaVarDecl(span, name, kind) => {
if kind.is_none() && node_id != DUMMY_NODE_ID {
// FIXME: Report this as a hard error eventually and remove equivalent errors from
// `parse_tt_inner` and `nameize`. Until then the error may be reported twice, once
// as a hard error and then once as a buffered lint.
if span.edition() >= Edition::Edition2024 {
psess.dcx().emit_err(errors::MissingFragmentSpecifier {
span,
add_span: span.shrink_to_hi(),
valid: VALID_FRAGMENT_NAMES_MSG,
});
} else {
psess.buffer_lint(
MISSING_FRAGMENT_SPECIFIER,
span,
node_id,
BuiltinLintDiag::MissingFragmentSpecifier,
);
}
psess.dcx().emit_err(errors::MissingFragmentSpecifier {
span,
add_span: span.shrink_to_hi(),
valid: VALID_FRAGMENT_NAMES_MSG,
});
}
if !macros.is_empty() {
psess.dcx().span_bug(span, "unexpected MetaVarDecl in nested lhs");
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,6 @@ lint_metavariable_still_repeating = variable `{$name}` is still repeating at thi

lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator

lint_missing_fragment_specifier = missing fragment specifier

lint_missing_unsafe_on_extern = extern blocks should be unsafe
.suggestion = needs `unsafe` before the extern keyword

Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,6 @@ pub(super) fn decorate_lint(
BuiltinLintDiag::CfgAttrNoAttributes => {
lints::CfgAttrNoAttributes.decorate_lint(diag);
}
BuiltinLintDiag::MissingFragmentSpecifier => {
lints::MissingFragmentSpecifier.decorate_lint(diag);
}
BuiltinLintDiag::MetaVariableStillRepeating(name) => {
lints::MetaVariableStillRepeating { name }.decorate_lint(diag);
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2533,10 +2533,6 @@ pub(crate) struct DuplicateMacroAttribute;
#[diag(lint_cfg_attr_no_attributes)]
pub(crate) struct CfgAttrNoAttributes;

#[derive(LintDiagnostic)]
#[diag(lint_missing_fragment_specifier)]
pub(crate) struct MissingFragmentSpecifier;

#[derive(LintDiagnostic)]
#[diag(lint_metavariable_still_repeating)]
pub(crate) struct MetaVariableStillRepeating {
Expand Down
45 changes: 0 additions & 45 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ declare_lint_pass! {
MACRO_USE_EXTERN_CRATE,
META_VARIABLE_MISUSE,
MISSING_ABI,
MISSING_FRAGMENT_SPECIFIER,
MISSING_UNSAFE_ON_EXTERN,
MUST_NOT_SUSPEND,
NAMED_ARGUMENTS_USED_POSITIONALLY,
Expand Down Expand Up @@ -1414,50 +1413,6 @@ declare_lint! {
};
}

declare_lint! {
/// The `missing_fragment_specifier` lint is issued when an unused pattern in a
/// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
/// followed by a fragment specifier (e.g. `:expr`).
///
/// This warning can always be fixed by removing the unused pattern in the
/// `macro_rules!` macro definition.
///
/// ### Example
///
/// ```rust,compile_fail
/// macro_rules! foo {
/// () => {};
/// ($name) => { };
/// }
///
/// fn main() {
/// foo!();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
///
/// ```rust
/// macro_rules! foo {
/// () => {};
/// }
/// fn main() {
/// foo!();
/// }
/// ```
pub MISSING_FRAGMENT_SPECIFIER,
Deny,
"detects missing fragment specifiers in unused `macro_rules!` patterns",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
};
}

declare_lint! {
/// The `late_bound_lifetime_arguments` lint detects generic lifetime
/// arguments in path segments with late bound lifetime parameters.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,6 @@ pub enum BuiltinLintDiag {
UnnameableTestItems,
DuplicateMacroAttribute,
CfgAttrNoAttributes,
MissingFragmentSpecifier,
MetaVariableStillRepeating(MacroRulesNormalizedIdent),
MetaVariableWrongOperator,
DuplicateMatcherBinding,
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc/macro-generated-macro.macro_morestuff_pre.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro_rules! morestuff {
(
<= "space between most kinds of tokens" : 1 $x + @ :: >>= 'static
"no space inside paren or bracket" : (2 a) [2 a] $(2 $a:tt)*
<= "space between most kinds of tokens" : 1 $x:ident + @ :: >>=
'static "no space inside paren or bracket" : (2 a) [2 a] $(2 $a:tt)*
"space inside curly brace" : { 2 a }
"no space inside empty delimiters" : () [] {}
"no space before comma or semicolon" : a, (a), { a }, a; [T; 0];
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc/macro-generated-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

//@ snapshot macro_morestuff_pre macro_generated_macro/macro.morestuff.html //pre/text()
make_macro!(morestuff
"space between most kinds of tokens": 1 $x + @ :: >>= 'static
"space between most kinds of tokens": 1 $x:ident + @ :: >>= 'static
"no space inside paren or bracket": (2 a) [2 a] $(2 $a:tt)*
"space inside curly brace": { 2 a }
"no space inside empty delimiters": () [] {}
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/lint/expansion-time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ macro_rules! foo {
( $($i:ident)* ) => { $($i)+ }; //~ WARN meta-variable repeats with different Kleene operator
}

#[warn(missing_fragment_specifier)]
macro_rules! m { ($i) => {} } //~ WARN missing fragment specifier
//~| WARN this was previously accepted

#[warn(soft_unstable)]
mod benches {
#[bench] //~ WARN use of unstable library feature `test`
Expand Down
41 changes: 6 additions & 35 deletions tests/ui/lint/expansion-time.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,16 @@ note: the lint level is defined here
LL | #[warn(meta_variable_misuse)]
| ^^^^^^^^^^^^^^^^^^^^

warning: missing fragment specifier
--> $DIR/expansion-time.rs:9:19
|
LL | macro_rules! m { ($i) => {} }
| ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
note: the lint level is defined here
--> $DIR/expansion-time.rs:8:8
|
LL | #[warn(missing_fragment_specifier)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: use of unstable library feature `test`: `bench` is a part of custom test frameworks which are unstable
--> $DIR/expansion-time.rs:14:7
--> $DIR/expansion-time.rs:10:7
|
LL | #[bench]
| ^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
note: the lint level is defined here
--> $DIR/expansion-time.rs:12:8
--> $DIR/expansion-time.rs:8:8
|
LL | #[warn(soft_unstable)]
| ^^^^^^^^^^^^^
Expand All @@ -47,39 +33,24 @@ LL | 2
| ^
|
note: the lint level is defined here
--> $DIR/expansion-time.rs:29:8
--> $DIR/expansion-time.rs:25:8
|
LL | #[warn(incomplete_include)]
| ^^^^^^^^^^^^^^^^^^

warning: 4 warnings emitted
warning: 3 warnings emitted

Future incompatibility report: Future breakage diagnostic:
warning: missing fragment specifier
--> $DIR/expansion-time.rs:9:19
|
LL | macro_rules! m { ($i) => {} }
| ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
note: the lint level is defined here
--> $DIR/expansion-time.rs:8:8
|
LL | #[warn(missing_fragment_specifier)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

Future breakage diagnostic:
warning: use of unstable library feature `test`: `bench` is a part of custom test frameworks which are unstable
--> $DIR/expansion-time.rs:14:7
--> $DIR/expansion-time.rs:10:7
|
LL | #[bench]
| ^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
note: the lint level is defined here
--> $DIR/expansion-time.rs:12:8
--> $DIR/expansion-time.rs:8:8
|
LL | #[warn(soft_unstable)]
| ^^^^^^^^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/macros/issue-39404.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused)]

macro_rules! m { ($i) => {} }
//~^ ERROR missing fragment specifier
//~| WARN previously accepted
macro_rules! m {
($i) => {}; //~ ERROR missing fragment specifier
}

fn main() {}
26 changes: 9 additions & 17 deletions tests/ui/macros/issue-39404.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
error: missing fragment specifier
--> $DIR/issue-39404.rs:3:19
--> $DIR/issue-39404.rs:4:6
|
LL | macro_rules! m { ($i) => {} }
| ^^
LL | ($i) => {};
| ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
= note: `#[deny(missing_fragment_specifier)]` on by default
= note: fragment specifiers must be provided
= 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
help: try adding a specifier here
|
LL | ($i:spec) => {};
| +++++

error: aborting due to 1 previous error

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

2 changes: 0 additions & 2 deletions tests/ui/macros/macro-match-nonterminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ macro_rules! test {
//~^ ERROR missing fragment
//~| ERROR missing fragment
//~| ERROR missing fragment
//~| WARN this was previously accepted
//~| WARN this was previously accepted
()
};
}
Expand Down
39 changes: 12 additions & 27 deletions tests/ui/macros/macro-match-nonterminal.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,32 @@ error: missing fragment specifier
|
LL | ($a, $b) => {
| ^^

error: missing fragment specifier
--> $DIR/macro-match-nonterminal.rs:2:6
|
LL | ($a, $b) => {
| ^^
= note: fragment specifiers must be provided
= 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
help: try adding a specifier here
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
= note: `#[deny(missing_fragment_specifier)]` on by default
LL | ($a:spec, $b) => {
| +++++

error: missing fragment specifier
--> $DIR/macro-match-nonterminal.rs:2:10
|
LL | ($a, $b) => {
| ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>

error: aborting due to 3 previous errors
= note: fragment specifiers must be provided
= 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
help: try adding a specifier here
|
LL | ($a, $b:spec) => {
| +++++

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

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

6 changes: 2 additions & 4 deletions tests/ui/macros/macro-missing-fragment-deduplication.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//@ compile-flags: -Zdeduplicate-diagnostics=yes

macro_rules! m {
($name) => {}
//~^ ERROR missing fragment
//~| ERROR missing fragment
//~| WARN this was previously accepted
($name) => {}; //~ ERROR missing fragment
//~| ERROR missing fragment
}

fn main() {
Expand Down
Loading
Loading