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

Merged
Merged
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
@@ -113,7 +113,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}

25 changes: 6 additions & 19 deletions compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
@@ -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;

@@ -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");
2 changes: 0 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
@@ -533,8 +533,6 @@ lint_mismatched_lifetime_syntaxes_suggestion_implicit =
lint_mismatched_lifetime_syntaxes_suggestion_mixed =
one option is to remove the lifetime for references and use the anonymous lifetime for paths

lint_missing_fragment_specifier = missing fragment specifier

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

3 changes: 0 additions & 3 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -432,9 +432,6 @@ pub fn decorate_builtin_lint(
BuiltinLintDiag::CfgAttrNoAttributes => {
lints::CfgAttrNoAttributes.decorate_lint(diag);
}
BuiltinLintDiag::MissingFragmentSpecifier => {
lints::MissingFragmentSpecifier.decorate_lint(diag);
}
BuiltinLintDiag::MetaVariableStillRepeating(name) => {
lints::MetaVariableStillRepeating { name }.decorate_lint(diag);
}
5 changes: 5 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -619,6 +619,11 @@ fn register_builtins(store: &mut LintStore) {
"converted into hard error, \
see <https://github.com/rust-lang/rust/issues/116558> for more information",
);
store.register_removed(
"missing_fragment_specifier",
"converted into hard error, \
see <https://github.com/rust-lang/rust/issues/40107> for more information",
);
}

fn register_internals(store: &mut LintStore) {
4 changes: 0 additions & 4 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
@@ -2616,10 +2616,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 {
46 changes: 0 additions & 46 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
@@ -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,
@@ -1417,51 +1416,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,edition2021
/// 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::FutureReleaseError,
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
report_in_deps: true,
};
}

declare_lint! {
/// The `late_bound_lifetime_arguments` lint detects generic lifetime
/// arguments in path segments with late bound lifetime parameters.
1 change: 0 additions & 1 deletion compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -778,7 +778,6 @@ pub enum BuiltinLintDiag {
UnnameableTestItems,
DuplicateMacroAttribute,
CfgAttrNoAttributes,
MissingFragmentSpecifier,
MetaVariableStillRepeating(MacroRulesNormalizedIdent),
MetaVariableWrongOperator,
DuplicateMatcherBinding,
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];
2 changes: 1 addition & 1 deletion tests/rustdoc/macro/macro-generated-macro.rs
Original file line number Diff line number Diff 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

//@ 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": () [] {}
4 changes: 0 additions & 4 deletions tests/ui/lint/expansion-time.rs
Original file line number Diff line number Diff line change
@@ -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

#[deprecated = "reason"]
macro_rules! deprecated {
() => {}
33 changes: 2 additions & 31 deletions tests/ui/lint/expansion-time.stderr
Original file line number Diff line number Diff line change
@@ -12,46 +12,17 @@ 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: include macro expected single expression in source
--> $DIR/expansion-time-include.rs:4:1
|
LL | 2
| ^
|
note: the lint level is defined here
--> $DIR/expansion-time.rs:22:8
--> $DIR/expansion-time.rs:18:8
|
LL | #[warn(incomplete_include)]
| ^^^^^^^^^^^^^^^^^^

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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: 2 warnings emitted

19 changes: 14 additions & 5 deletions tests/ui/lint/future-incompatible-lint-group.rs
Original file line number Diff line number Diff line change
@@ -4,14 +4,23 @@
// lints for changes that are not tied to an edition
#![deny(future_incompatible)]

// Error since this is a `future_incompatible` lint
macro_rules! m {
($i) => {};
//~^ ERROR missing fragment specifier
enum E { V }

trait Tr1 {
type V;
fn foo() -> Self::V;
}

impl Tr1 for E {
type V = u8;

// Error since this is a `future_incompatible` lint
fn foo() -> Self::V { 0 }
//~^ ERROR ambiguous associated item
//~| WARN this was previously accepted
}

trait Tr {
trait Tr2 {
// Warn only since this is not a `future_incompatible` lint
fn f(u8) {}
//~^ WARN anonymous parameters are deprecated
44 changes: 19 additions & 25 deletions tests/ui/lint/future-incompatible-lint-group.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
error: missing fragment specifier
--> $DIR/future-incompatible-lint-group.rs:9:6
|
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: the lint level is defined here
--> $DIR/future-incompatible-lint-group.rs:5:9
|
LL | #![deny(future_incompatible)]
| ^^^^^^^^^^^^^^^^^^^
= note: `#[deny(missing_fragment_specifier)]` implied by `#[deny(future_incompatible)]`

warning: anonymous parameters are deprecated and will be removed in the next edition
--> $DIR/future-incompatible-lint-group.rs:16:10
--> $DIR/future-incompatible-lint-group.rs:25:10
|
LL | fn f(u8) {}
| ^^ help: try naming the parameter or explicitly ignoring it: `_: u8`
@@ -23,21 +8,30 @@ LL | fn f(u8) {}
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
= note: `#[warn(anonymous_parameters)]` on by default

error: aborting due to 1 previous error; 1 warning emitted

Future incompatibility report: Future breakage diagnostic:
error: missing fragment specifier
--> $DIR/future-incompatible-lint-group.rs:9:6
error: ambiguous associated item
--> $DIR/future-incompatible-lint-group.rs:18:17
|
LL | ($i) => {};
| ^^
LL | fn foo() -> Self::V { 0 }
| ^^^^^^^ help: use fully-qualified syntax: `<E as Tr1>::V`
|
= 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: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
note: `V` could refer to the variant defined here
--> $DIR/future-incompatible-lint-group.rs:7:10
|
LL | enum E { V }
| ^
note: `V` could also refer to the associated type defined here
--> $DIR/future-incompatible-lint-group.rs:10:5
|
LL | type V;
| ^^^^^^
note: the lint level is defined here
--> $DIR/future-incompatible-lint-group.rs:5:9
|
LL | #![deny(future_incompatible)]
| ^^^^^^^^^^^^^^^^^^^
= note: `#[deny(missing_fragment_specifier)]` implied by `#[deny(future_incompatible)]`
= note: `#[deny(ambiguous_associated_items)]` implied by `#[deny(future_incompatible)]`

error: aborting due to 1 previous error; 1 warning emitted

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
@@ -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
()
};
}
Loading