diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index a03b3e5c1346..6a0fff1d37f5 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 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 af2b41bf0ff0..3847f897f85c 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 5bca718ec7b7..8324043c9809 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -43,17 +43,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { .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 891ae0d542f7..1cfa580b58b8 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3282,23 +3282,6 @@ fn add_to_diag(self, diag: &mut Diag<'_, G>) { } } -#[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 e4b7f74de3a2..5c7fac926a9f 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 },