Rollup merge of #155661 - GuillaumeGomez:rm-attributelintkind, r=JonathanBrouwer

Remove `AttributeLintKind` variants - part 6

Part of https://github.com/rust-lang/rust/issues/153099.

r? @JonathanBrouwer
This commit is contained in:
Guillaume Gomez
2026-04-23 14:42:50 +02:00
committed by GitHub
6 changed files with 133 additions and 143 deletions
@@ -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,10 @@
use thin_vec::{ThinVec, thin_vec};
use crate::context::{AcceptContext, Stage};
use crate::errors::{
DisallowedPlaceholder, DisallowedPositionalArgument, IgnoredDiagnosticOption,
InvalidFormatSpecifier, MalFormedDiagnosticAttributeLint, WrappedParserError,
};
use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser};
pub(crate) mod do_not_recommend;
@@ -112,12 +116,12 @@ fn merge<T, S: Stage>(
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,
);
@@ -157,12 +161,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 +195,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,
);
@@ -210,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,
);
}}
@@ -245,9 +256,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,
);
}
@@ -255,12 +276,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,
);
@@ -5,7 +5,6 @@
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,8 @@
AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow,
DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral,
DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude,
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput,
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs,
IllFormedAttributeInput, MalformedDoc,
};
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
use crate::session_diagnostics::{
@@ -84,18 +84,18 @@ fn expected_name_value<S: Stage>(
span: Span,
_name: Option<Symbol>,
) {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::ExpectedNameValue,
|dcx, level| ExpectedNameValue.into_diag(dcx, level),
span,
);
}
// FIXME: remove this method once merged and use `cx.expected_no_args(span)` instead.
fn expected_no_args<S: Stage>(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,
);
}
@@ -107,9 +107,9 @@ fn expected_string_literal<S: Stage>(
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 +203,9 @@ fn parse_single_test_doc_attr_item<S: Stage>(
// 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 +399,9 @@ fn parse_auto_cfg<S: Stage>(
// 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 +605,9 @@ macro_rules! string_arg_and_crate_level {
// 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,
);
}
+67
View File
@@ -325,3 +325,70 @@ 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;
#[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(
"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,
}
#[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> {
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 {
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,
}
+1 -28
View File
@@ -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,33 +43,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
.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),
&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)
}
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)
}
&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)
-67
View File
@@ -3282,63 +3282,6 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
}
}
#[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(
"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;
#[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> {
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 {
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}")]
@@ -3358,13 +3301,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,
}
-7
View File
@@ -656,13 +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 },
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 },
NonMetaItemDiagnosticAttribute,
}