From 359910e21ec021b7d9977c4454ee02adec990911 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:16:12 +0200 Subject: [PATCH 1/7] Remove `AttributeLintKind::MalformedDoc` variant --- .../rustc_attr_parsing/src/attributes/doc.rs | 17 +++++++++-------- compiler/rustc_attr_parsing/src/errors.rs | 7 +++++++ compiler/rustc_lint/src/early/diagnostics.rs | 2 -- compiler/rustc_lint/src/lints.rs | 7 ------- compiler/rustc_lint_defs/src/lib.rs | 1 - 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index 2b6d56c411939..aac0adfff5f09 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -18,6 +18,7 @@ use crate::errors::{ DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral, DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput, + MalformedDoc, }; use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser}; use crate::session_diagnostics::{ @@ -107,9 +108,9 @@ fn expected_string_literal( span: Span, _actual_literal: Option<&MetaItemLit>, ) { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::MalformedDoc, + |dcx, level| MalformedDoc.into_diag(dcx, level), span, ); } @@ -203,9 +204,9 @@ impl DocParser { // FIXME: remove this method once merged and uncomment the line below instead. // cx.expected_list(cx.attr_span, args); let span = cx.attr_span; - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::MalformedDoc, + |dcx, level| MalformedDoc.into_diag(dcx, level), span, ); return; @@ -399,9 +400,9 @@ impl DocParser { // FIXME: remove this method once merged and uncomment the line // below instead. // cx.expected_identifier(sub_item.path().span()); - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::MalformedDoc, + |dcx, level| MalformedDoc.into_diag(dcx, level), sub_item.path().span(), ); continue; @@ -605,9 +606,9 @@ impl DocParser { // FIXME: remove this method once merged and uncomment the line // below instead. // cx.unexpected_literal(lit.span); - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::MalformedDoc, + |dcx, level| MalformedDoc.into_diag(dcx, level), lit.span, ); } diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index d3e6845799e7f..aca238ead7c10 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -325,3 +325,10 @@ pub(crate) struct IncorrectDoNotRecommendLocation { #[label("not a trait implementation")] pub target_span: Span, } + +#[derive(Diagnostic)] +#[diag("malformed `doc` attribute input")] +#[warning( + "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 MalformedDoc; diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 92c4748483278..60d6daf222e63 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,8 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { .into_diag(dcx, level) } - &AttributeLintKind::MalformedDoc => lints::MalformedDoc.into_diag(dcx, level), - &AttributeLintKind::ExpectedNoArgs => lints::ExpectedNoArgs.into_diag(dcx, level), &AttributeLintKind::ExpectedNameValue => lints::ExpectedNameValue.into_diag(dcx, level), diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index ccbc325648e38..5da9f2a9a7467 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,13 +3282,6 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion { } } -#[derive(Diagnostic)] -#[diag("malformed `doc` attribute input")] -#[warning( - "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 MalformedDoc; - #[derive(Diagnostic)] #[diag("didn't expect any arguments here")] #[warning( diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 45ac2c59b04e9..2a34e8b641dd3 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)>), - MalformedDoc, ExpectedNoArgs, ExpectedNameValue, MalFormedDiagnosticAttribute { attribute: &'static str, options: &'static str, span: Span }, From af3652c1dc655456710c24831ad65d48d9a58984 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:18:28 +0200 Subject: [PATCH 2/7] Remove `AttributeLintKind::ExpectedNoArgs` variant --- compiler/rustc_attr_parsing/src/attributes/doc.rs | 8 ++++---- compiler/rustc_attr_parsing/src/errors.rs | 7 +++++++ compiler/rustc_lint/src/early/diagnostics.rs | 2 -- compiler/rustc_lint/src/lints.rs | 7 ------- compiler/rustc_lint_defs/src/lib.rs | 1 - 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index aac0adfff5f09..c6065743d7f79 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -17,8 +17,8 @@ use crate::errors::{ AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral, DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude, - DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput, - MalformedDoc, + DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNoArgs, + IllFormedAttributeInput, MalformedDoc, }; use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser}; use crate::session_diagnostics::{ @@ -94,9 +94,9 @@ fn expected_name_value( // FIXME: remove this method once merged and use `cx.expected_no_args(span)` instead. fn expected_no_args(cx: &mut AcceptContext<'_, '_, S>, span: Span) { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::ExpectedNoArgs, + |dcx, level| ExpectedNoArgs.into_diag(dcx, level), span, ); } diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index aca238ead7c10..b3e66abddd411 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -332,3 +332,10 @@ 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 MalformedDoc; + +#[derive(Diagnostic)] +#[diag("didn't expect any arguments here")] +#[warning( + "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 ExpectedNoArgs; diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 60d6daf222e63..fd10e240a726e 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,8 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { .into_diag(dcx, level) } - &AttributeLintKind::ExpectedNoArgs => lints::ExpectedNoArgs.into_diag(dcx, level), - &AttributeLintKind::ExpectedNameValue => lints::ExpectedNameValue.into_diag(dcx, level), &AttributeLintKind::MalFormedDiagnosticAttribute { attribute, options, span } => { lints::MalFormedDiagnosticAttributeLint { attribute, options, span } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 5da9f2a9a7467..d22e2bebd5aa0 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,13 +3282,6 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion { } } -#[derive(Diagnostic)] -#[diag("didn't expect any arguments here")] -#[warning( - "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 ExpectedNoArgs; - #[derive(Diagnostic)] #[diag("expected this to be of the form `... = \"...\"`")] #[warning( diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 2a34e8b641dd3..57860d5676674 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)>), - ExpectedNoArgs, ExpectedNameValue, MalFormedDiagnosticAttribute { attribute: &'static str, options: &'static str, span: Span }, MalformedDiagnosticFormat { warning: FormatWarning }, From ad11f2efec0c2cd6e52d068a5c0bff1ebd37ac83 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:22:06 +0200 Subject: [PATCH 3/7] Remove `AttributeLintKind::ExpectedNameValue` variant --- compiler/rustc_attr_parsing/src/attributes/doc.rs | 7 +++---- compiler/rustc_attr_parsing/src/errors.rs | 7 +++++++ compiler/rustc_lint/src/early/diagnostics.rs | 1 - compiler/rustc_lint/src/lints.rs | 7 ------- compiler/rustc_lint_defs/src/lib.rs | 1 - 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index c6065743d7f79..321f6e08a733f 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -5,7 +5,6 @@ use rustc_hir::Target; use rustc_hir::attrs::{ AttributeKind, CfgEntry, CfgHideShow, CfgInfo, DocAttribute, DocInline, HideOrShow, }; -use rustc_hir::lints::AttributeLintKind; use rustc_session::parse::feature_err; use rustc_span::{Span, Symbol, edition, sym}; use thin_vec::ThinVec; @@ -17,7 +16,7 @@ use crate::errors::{ AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral, DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude, - DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNoArgs, + DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs, IllFormedAttributeInput, MalformedDoc, }; use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser}; @@ -85,9 +84,9 @@ fn expected_name_value( span: Span, _name: Option, ) { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::ExpectedNameValue, + |dcx, level| ExpectedNameValue.into_diag(dcx, level), span, ); } diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index b3e66abddd411..4dc585b55a777 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -339,3 +339,10 @@ pub(crate) struct MalformedDoc; "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 ExpectedNoArgs; + +#[derive(Diagnostic)] +#[diag("expected this to be of the form `... = \"...\"`")] +#[warning( + "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; diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index fd10e240a726e..473c7bbc8b9fc 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,7 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { .into_diag(dcx, level) } - &AttributeLintKind::ExpectedNameValue => lints::ExpectedNameValue.into_diag(dcx, level), &AttributeLintKind::MalFormedDiagnosticAttribute { attribute, options, span } => { lints::MalFormedDiagnosticAttributeLint { attribute, options, span } .into_diag(dcx, level) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index d22e2bebd5aa0..46411eb7df9e1 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,13 +3282,6 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion { } } -#[derive(Diagnostic)] -#[diag("expected this to be of the form `... = \"...\"`")] -#[warning( - "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("positional format arguments are not allowed here")] #[help( diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 57860d5676674..e9e1fd75a2d9b 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)>), - ExpectedNameValue, MalFormedDiagnosticAttribute { attribute: &'static str, options: &'static str, span: Span }, MalformedDiagnosticFormat { warning: FormatWarning }, DiagnosticWrappedParserError { description: String, label: String, span: Span }, From 9bf2522cf0156e9f6c2be65f8fbd426672d774a1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:27:22 +0200 Subject: [PATCH 4/7] 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 32d73ff32361c..a03b3e5c13467 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 rustc_span::{Ident, InnerSpan, Span, Symbol, kw, sym}; 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 4dc585b55a777..af2b41bf0ff02 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -346,3 +346,13 @@ pub(crate) struct ExpectedNoArgs; "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 473c7bbc8b9fc..5bca718ec7b77 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,10 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { .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 46411eb7df9e1..891ae0d542f7d 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3337,13 +3337,3 @@ pub(crate) struct EqInternalMethodImplemented; "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 e9e1fd75a2d9b..e4b7f74de3a20 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 }, From eb8be4f99149b66b09f34b9c40689c7a5c73fbc4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:31:49 +0200 Subject: [PATCH 5/7] Remove `AttributeLintKind::MalformedDiagnosticFormat` variant --- .../src/attributes/diagnostic/mod.rs | 19 ++++++++++++++++--- compiler/rustc_attr_parsing/src/errors.rs | 17 +++++++++++++++++ compiler/rustc_lint/src/early/diagnostics.rs | 11 ----------- compiler/rustc_lint/src/lints.rs | 17 ----------------- compiler/rustc_lint_defs/src/lib.rs | 1 - 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index a03b3e5c13467..6a0fff1d37f5c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -18,7 +18,10 @@ use rustc_span::{Ident, InnerSpan, Span, Symbol, kw, sym}; use thin_vec::{ThinVec, thin_vec}; use crate::context::{AcceptContext, Stage}; -use crate::errors::MalFormedDiagnosticAttributeLint; +use crate::errors::{ + DisallowedPlaceholder, DisallowedPositionalArgument, InvalidFormatSpecifier, + MalFormedDiagnosticAttributeLint, +}; use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser}; pub(crate) mod do_not_recommend; @@ -252,9 +255,19 @@ fn parse_directive_items<'p, S: Stage>( let (FormatWarning::InvalidSpecifier { span, .. } | FormatWarning::PositionalArgument { span, .. } | FormatWarning::DisallowedPlaceholder { span }) = warning; - cx.emit_lint( + cx.emit_dyn_lint( MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, - AttributeLintKind::MalformedDiagnosticFormat { warning }, + move |dcx, level| match warning { + FormatWarning::PositionalArgument { .. } => { + DisallowedPositionalArgument.into_diag(dcx, level) + } + FormatWarning::InvalidSpecifier { .. } => { + InvalidFormatSpecifier.into_diag(dcx, level) + } + FormatWarning::DisallowedPlaceholder { .. } => { + DisallowedPlaceholder.into_diag(dcx, level) + } + }, span, ); } diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index af2b41bf0ff02..3847f897f85c1 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -356,3 +356,20 @@ pub(crate) struct MalFormedDiagnosticAttributeLint { #[label("invalid option found here")] pub span: Span, } + +#[derive(Diagnostic)] +#[diag("positional format arguments are not allowed here")] +#[help( + "only named format arguments with the name of one of the generic types are allowed in this context" +)] +pub(crate) struct DisallowedPositionalArgument; + +#[derive(Diagnostic)] +#[diag("format arguments are not allowed here")] +#[help("consider removing this format argument")] +pub(crate) struct DisallowedPlaceholder; + +#[derive(Diagnostic)] +#[diag("invalid format specifier")] +#[help("no format specifier are supported in this position")] +pub(crate) struct InvalidFormatSpecifier; diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 5bca718ec7b77..8324043c9809d 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,17 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { .into_diag(dcx, level) } - AttributeLintKind::MalformedDiagnosticFormat { warning } => match warning { - FormatWarning::PositionalArgument { .. } => { - lints::DisallowedPositionalArgument.into_diag(dcx, level) - } - FormatWarning::InvalidSpecifier { .. } => { - lints::InvalidFormatSpecifier.into_diag(dcx, level) - } - FormatWarning::DisallowedPlaceholder { .. } => { - lints::DisallowedPlaceholder.into_diag(dcx, level) - } - }, AttributeLintKind::DiagnosticWrappedParserError { description, label, span } => { lints::WrappedParserError { description, label, span: *span }.into_diag(dcx, level) } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 891ae0d542f7d..1cfa580b58b8f 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,23 +3282,6 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion { } } -#[derive(Diagnostic)] -#[diag("positional format arguments are not allowed here")] -#[help( - "only named format arguments with the name of one of the generic types are allowed in this context" -)] -pub(crate) struct DisallowedPositionalArgument; - -#[derive(Diagnostic)] -#[diag("format arguments are not allowed here")] -#[help("consider removing this format argument")] -pub(crate) struct DisallowedPlaceholder; - -#[derive(Diagnostic)] -#[diag("invalid format specifier")] -#[help("no format specifier are supported in this position")] -pub(crate) struct InvalidFormatSpecifier; - #[derive(Diagnostic)] #[diag("{$description}")] pub(crate) struct WrappedParserError<'a> { diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index e4b7f74de3a20..5c7fac926a9fc 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)>), - MalformedDiagnosticFormat { warning: FormatWarning }, DiagnosticWrappedParserError { description: String, label: String, span: Span }, IgnoredDiagnosticOption { option_name: Symbol, first_span: Span, later_span: Span }, MissingOptionsForDiagnosticAttribute { attribute: &'static str, options: &'static str }, From f9cb68421555a54569ad36fe039940b5c37a5fa7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:41:43 +0200 Subject: [PATCH 6/7] Remove `AttributeLintKind::DiagnosticWrappedParserError` variant --- .../src/attributes/diagnostic/mod.rs | 15 +++++++++------ compiler/rustc_attr_parsing/src/errors.rs | 9 +++++++++ compiler/rustc_lint/src/early/diagnostics.rs | 5 +---- compiler/rustc_lint/src/lints.rs | 9 --------- compiler/rustc_lint_defs/src/lib.rs | 1 - 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index 6a0fff1d37f5c..f6030d6479d1a 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -20,7 +20,7 @@ use thin_vec::{ThinVec, thin_vec}; use crate::context::{AcceptContext, Stage}; use crate::errors::{ DisallowedPlaceholder, DisallowedPositionalArgument, InvalidFormatSpecifier, - MalFormedDiagnosticAttributeLint, + MalFormedDiagnosticAttributeLint, WrappedParserError, }; use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser}; @@ -275,12 +275,15 @@ fn parse_directive_items<'p, S: Stage>( f } Err(e) => { - cx.emit_lint( + cx.emit_dyn_lint( MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, - AttributeLintKind::DiagnosticWrappedParserError { - description: e.description, - label: e.label, - span: slice_span(input.span, e.span, is_snippet), + move |dcx, level| { + WrappedParserError { + description: &e.description, + label: &e.label, + span: slice_span(input.span, e.span.clone(), is_snippet), + } + .into_diag(dcx, level) }, input.span, ); diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index 3847f897f85c1..8efb5190d952a 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -373,3 +373,12 @@ pub(crate) struct DisallowedPlaceholder; #[diag("invalid format specifier")] #[help("no format specifier are supported in this position")] pub(crate) struct InvalidFormatSpecifier; + +#[derive(Diagnostic)] +#[diag("{$description}")] +pub(crate) struct WrappedParserError<'a> { + pub description: &'a str, + #[label("{$label}")] + pub span: Span, + pub label: &'a str, +} diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 8324043c9809d..3038a2ed0522f 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -2,7 +2,7 @@ use std::any::Any; use rustc_data_structures::sync::DynSend; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level}; -use rustc_hir::lints::{AttributeLintKind, FormatWarning}; +use rustc_hir::lints::AttributeLintKind; use rustc_middle::ty::TyCtxt; use rustc_session::Session; @@ -43,9 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { .into_diag(dcx, level) } - AttributeLintKind::DiagnosticWrappedParserError { description, label, span } => { - lints::WrappedParserError { description, label, span: *span }.into_diag(dcx, level) - } &AttributeLintKind::IgnoredDiagnosticOption { option_name, first_span, later_span } => { lints::IgnoredDiagnosticOption { option_name, first_span, later_span } .into_diag(dcx, level) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 1cfa580b58b8f..6e4c79ecfac90 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,15 +3282,6 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion { } } -#[derive(Diagnostic)] -#[diag("{$description}")] -pub(crate) struct WrappedParserError<'a> { - pub description: &'a str, - #[label("{$label}")] - pub span: Span, - pub label: &'a str, -} - #[derive(Diagnostic)] #[diag("`{$option_name}` is ignored due to previous definition of `{$option_name}`")] pub(crate) struct IgnoredDiagnosticOption { diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 5c7fac926a9fc..5c45195a41de8 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)>), - DiagnosticWrappedParserError { description: String, label: String, span: Span }, IgnoredDiagnosticOption { option_name: Symbol, first_span: Span, later_span: Span }, MissingOptionsForDiagnosticAttribute { attribute: &'static str, options: &'static str }, NonMetaItemDiagnosticAttribute, From b716ebc7d1cc72bd65f6007c052014f2c631965d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Apr 2026 23:49:01 +0200 Subject: [PATCH 7/7] Remove `AttributeLintKind::IgnoredDiagnosticOption` variant --- .../src/attributes/diagnostic/mod.rs | 23 ++++++++++--------- 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, 22 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 f6030d6479d1a..00e753eea97cd 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -19,8 +19,8 @@ use thin_vec::{ThinVec, thin_vec}; use crate::context::{AcceptContext, Stage}; use crate::errors::{ - DisallowedPlaceholder, DisallowedPositionalArgument, InvalidFormatSpecifier, - MalFormedDiagnosticAttributeLint, WrappedParserError, + DisallowedPlaceholder, DisallowedPositionalArgument, IgnoredDiagnosticOption, + InvalidFormatSpecifier, MalFormedDiagnosticAttributeLint, WrappedParserError, }; use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser}; @@ -116,12 +116,12 @@ fn merge( match (first, later) { (Some(_) | None, None) => {} (Some((first_span, _)), Some((later_span, _))) => { - cx.emit_lint( + let first_span = *first_span; + cx.emit_dyn_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::IgnoredDiagnosticOption { - first_span: *first_span, - later_span, - option_name, + move |dcx, level| { + IgnoredDiagnosticOption { first_span, later_span, option_name } + .into_diag(dcx, level) }, later_span, ); @@ -220,13 +220,14 @@ fn parse_directive_items<'p, S: Stage>( }} macro duplicate($name: ident, $($first_span:tt)*) {{ - cx.emit_lint( + let first_span = $($first_span)*; + cx.emit_dyn_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::IgnoredDiagnosticOption { - first_span: $($first_span)*, + move |dcx, level| IgnoredDiagnosticOption { + first_span, later_span: span, option_name: $name, - }, + }.into_diag(dcx, level), span, ); }} diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index 8efb5190d952a..b421e85688958 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -382,3 +382,13 @@ pub(crate) struct WrappedParserError<'a> { pub span: Span, pub label: &'a str, } + +#[derive(Diagnostic)] +#[diag("`{$option_name}` is ignored due to previous definition of `{$option_name}`")] +pub(crate) struct IgnoredDiagnosticOption { + pub option_name: Symbol, + #[label("`{$option_name}` is first declared here")] + pub first_span: Span, + #[label("`{$option_name}` is later redundantly declared here")] + pub later_span: Span, +} diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 3038a2ed0522f..29c302ff2802a 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,10 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> { .into_diag(dcx, level) } - &AttributeLintKind::IgnoredDiagnosticOption { option_name, first_span, later_span } => { - lints::IgnoredDiagnosticOption { option_name, first_span, later_span } - .into_diag(dcx, level) - } &AttributeLintKind::MissingOptionsForDiagnosticAttribute { attribute, options } => { lints::MissingOptionsForDiagnosticAttribute { attribute, options } .into_diag(dcx, level) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 6e4c79ecfac90..c2c140a3c6d92 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,16 +3282,6 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion { } } -#[derive(Diagnostic)] -#[diag("`{$option_name}` is ignored due to previous definition of `{$option_name}`")] -pub(crate) struct IgnoredDiagnosticOption { - pub option_name: Symbol, - #[label("`{$option_name}` is first declared here")] - pub first_span: Span, - #[label("`{$option_name}` is later redundantly declared here")] - pub later_span: Span, -} - #[derive(Diagnostic)] #[diag("missing options for `{$attribute}` attribute")] #[help("{$options}")] diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 5c45195a41de8..aef62c768337b 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)>), - IgnoredDiagnosticOption { option_name: Symbol, first_span: Span, later_span: Span }, MissingOptionsForDiagnosticAttribute { attribute: &'static str, options: &'static str }, NonMetaItemDiagnosticAttribute, }