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]: https://github.com/rust-lang/rust/pull/75516 [2]: https://github.com/rust-lang/rust/pull/80210 [3]: https://github.com/rust-lang/rust/pull/128006
This commit is contained in:
parent
208cb5da15
commit
841f7ce69a
23 changed files with 108 additions and 345 deletions
|
|
@ -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}
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -778,7 +778,6 @@ pub enum BuiltinLintDiag {
|
|||
UnnameableTestItems,
|
||||
DuplicateMacroAttribute,
|
||||
CfgAttrNoAttributes,
|
||||
MissingFragmentSpecifier,
|
||||
MetaVariableStillRepeating(MacroRulesNormalizedIdent),
|
||||
MetaVariableWrongOperator,
|
||||
DuplicateMatcherBinding,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue