diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index 6a0fff1d37f5..f6030d6479d1 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 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 3847f897f85c..8efb5190d952 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -373,3 +373,12 @@ pub(crate) struct MalFormedDiagnosticAttributeLint { #[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 8324043c9809..3038a2ed0522 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -2,7 +2,7 @@ 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 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { .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 1cfa580b58b8..6e4c79ecfac9 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,15 +3282,6 @@ fn add_to_diag(self, diag: &mut Diag<'_, G>) { } } -#[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 5c7fac926a9f..5c45195a41de 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,