diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index f6030d6479d1..00e753eea97c 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 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 8efb5190d952..b421e8568895 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 3038a2ed0522..29c302ff2802 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::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 6e4c79ecfac9..c2c140a3c6d9 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,16 +3282,6 @@ fn add_to_diag(self, diag: &mut Diag<'_, G>) { } } -#[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 5c45195a41de..aef62c768337 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, }