From 9bf2522cf0156e9f6c2be65f8fbd426672d774a1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:27:22 +0200 Subject: [PATCH] Remove `AttributeLintKind::MalFormedDiagnosticAttribute` variant --- .../src/attributes/diagnostic/mod.rs | 29 ++++++++++++------- compiler/rustc_attr_parsing/src/errors.rs | 10 +++++++ compiler/rustc_lint/src/early/diagnostics.rs | 4 --- compiler/rustc_lint/src/lints.rs | 10 ------- compiler/rustc_lint_defs/src/lib.rs | 1 - 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index 32d73ff32361..a03b3e5c1346 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -1,6 +1,6 @@ use std::ops::Range; -use rustc_errors::E0232; +use rustc_errors::{Diagnostic, E0232}; use rustc_hir::AttrPath; use rustc_hir::attrs::diagnostic::{ Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue, @@ -18,6 +18,7 @@ use thin_vec::{ThinVec, thin_vec}; use crate::context::{AcceptContext, Stage}; +use crate::errors::MalFormedDiagnosticAttributeLint; use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser}; pub(crate) mod do_not_recommend; @@ -157,12 +158,15 @@ fn parse_list<'p, S: Stage>( ); } ArgParser::NameValue(_) => { - cx.emit_lint( + cx.emit_dyn_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::MalFormedDiagnosticAttribute { - attribute: mode.as_str(), - options: mode.allowed_options(), - span, + move |dcx, level| { + MalFormedDiagnosticAttributeLint { + attribute: mode.as_str(), + options: mode.allowed_options(), + span, + } + .into_diag(dcx, level) }, span, ); @@ -188,12 +192,15 @@ fn parse_directive_items<'p, S: Stage>( let span = item.span(); macro malformed() {{ - cx.emit_lint( + cx.emit_dyn_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::MalFormedDiagnosticAttribute { - attribute: mode.as_str(), - options: mode.allowed_options(), - span, + move |dcx, level| { + MalFormedDiagnosticAttributeLint { + attribute: mode.as_str(), + options: mode.allowed_options(), + span, + } + .into_diag(dcx, level) }, span, ); diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index 4dc585b55a77..af2b41bf0ff0 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -346,3 +346,13 @@ pub(crate) struct IncorrectDoNotRecommendLocation { "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" )] pub(crate) struct ExpectedNameValue; + +#[derive(Diagnostic)] +#[diag("malformed `{$attribute}` attribute")] +#[help("{$options}")] +pub(crate) struct MalFormedDiagnosticAttributeLint { + pub attribute: &'static str, + pub options: &'static str, + #[label("invalid option found here")] + pub span: Span, +} diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 473c7bbc8b9f..5bca718ec7b7 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,10 +43,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { .into_diag(dcx, level) } - &AttributeLintKind::MalFormedDiagnosticAttribute { attribute, options, span } => { - lints::MalFormedDiagnosticAttributeLint { attribute, options, span } - .into_diag(dcx, level) - } AttributeLintKind::MalformedDiagnosticFormat { warning } => match warning { FormatWarning::PositionalArgument { .. } => { lints::DisallowedPositionalArgument.into_diag(dcx, level) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 46411eb7df9e..891ae0d542f7 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3337,13 +3337,3 @@ pub(crate) struct MissingOptionsForDiagnosticAttribute { "only literals are allowed as values for the `message`, `note` and `label` options. These options must be separated by a comma" )] pub(crate) struct NonMetaItemDiagnosticAttribute; - -#[derive(Diagnostic)] -#[diag("malformed `{$attribute}` attribute")] -#[help("{$options}")] -pub(crate) struct MalFormedDiagnosticAttributeLint { - pub attribute: &'static str, - pub options: &'static str, - #[label("invalid option found here")] - pub span: Span, -} diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index e9e1fd75a2d9..e4b7f74de3a2 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -656,7 +656,6 @@ pub enum DeprecatedSinceKind { pub enum AttributeLintKind { UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>), UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>), - MalFormedDiagnosticAttribute { attribute: &'static str, options: &'static str, span: Span }, MalformedDiagnosticFormat { warning: FormatWarning }, DiagnosticWrappedParserError { description: String, label: String, span: Span }, IgnoredDiagnosticOption { option_name: Symbol, first_span: Span, later_span: Span },