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

Remove `AttributeLintKind` variants - part 3

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

r? @JonathanBrouwer
This commit is contained in:
Jonathan Brouwer
2026-04-20 08:14:14 +02:00
committed by GitHub
6 changed files with 62 additions and 80 deletions
@@ -1,5 +1,5 @@
use rustc_ast::ast::{AttrStyle, LitKind, MetaItemLit};
use rustc_errors::{Diagnostic, msg};
use rustc_errors::{Applicability, Diagnostic, msg};
use rustc_feature::template;
use rustc_hir::Target;
use rustc_hir::attrs::{
@@ -13,7 +13,10 @@
use super::prelude::{ALL_TARGETS, AllowedTargets};
use super::{AcceptMapping, AttributeParser};
use crate::context::{AcceptContext, FinalizeContext, Stage};
use crate::errors::{DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, IllFormedAttributeInput};
use crate::errors::{
DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList,
DocAutoCfgHideShowUnexpectedItem, DocUnknownInclude, IllFormedAttributeInput,
};
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
use crate::session_diagnostics::{
DocAliasBadChar, DocAliasEmpty, DocAliasMalformed, DocAliasStartEnd, DocAttrNotCrateLevel,
@@ -364,9 +367,11 @@ fn parse_auto_cfg<S: Stage>(
}
};
let ArgParser::List(list) = item.args() else {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocAutoCfgHideShowExpectsList { attr_name },
move |dcx, level| {
DocAutoCfgHideShowExpectsList { attr_name }.into_diag(dcx, level)
},
item.span(),
);
continue;
@@ -376,9 +381,12 @@ fn parse_auto_cfg<S: Stage>(
for item in list.mixed() {
let MetaItemOrLitParser::MetaItemParser(sub_item) = item else {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocAutoCfgHideShowUnexpectedItem { attr_name },
move |dcx, level| {
DocAutoCfgHideShowUnexpectedItem { attr_name }
.into_diag(dcx, level)
},
item.span(),
);
continue;
@@ -416,10 +424,11 @@ fn parse_auto_cfg<S: Stage>(
}
}
_ => {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocAutoCfgHideShowUnexpectedItem {
attr_name,
move |dcx, level| {
DocAutoCfgHideShowUnexpectedItem { attr_name }
.into_diag(dcx, level)
},
sub_item.span(),
);
@@ -615,14 +624,19 @@ macro_rules! string_arg_and_crate_level {
AttrStyle::Outer => "",
AttrStyle::Inner => "!",
};
cx.emit_lint(
let value = nv.value_as_lit().symbol;
let span = path.span();
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::DocUnknownInclude {
inner,
value: nv.value_as_lit().symbol,
span: path.span(),
move |dcx, level| {
DocUnknownInclude {
inner,
value,
sugg: (span, Applicability::MaybeIncorrect),
}
.into_diag(dcx, level)
},
path.span(),
span,
);
}
Some(name @ (sym::passes | sym::no_default_passes)) => {
@@ -1,4 +1,4 @@
use rustc_hir::lints::AttributeLintKind;
use rustc_errors::Diagnostic;
use rustc_session::lint::builtin::AMBIGUOUS_DERIVE_HELPERS;
use super::prelude::*;
@@ -125,9 +125,9 @@ fn parse_derive_like<S: Stage>(
return None;
}
if rustc_feature::is_builtin_attr_name(ident.name) {
cx.emit_lint(
cx.emit_dyn_lint(
AMBIGUOUS_DERIVE_HELPERS,
AttributeLintKind::AmbiguousDeriveHelpers,
|dcx, level| crate::errors::AmbiguousDeriveHelpers.into_diag(dcx, level),
ident.span,
);
}
+29 -1
View File
@@ -1,4 +1,4 @@
use rustc_errors::{DiagArgValue, MultiSpan};
use rustc_errors::{Applicability, DiagArgValue, MultiSpan};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};
@@ -177,3 +177,31 @@ pub(crate) struct DocAliasDuplicated {
#[derive(Diagnostic)]
#[diag("only `hide` or `show` are allowed in `#[doc(auto_cfg(...))]`")]
pub(crate) struct DocAutoCfgExpectsHideOrShow;
#[derive(Diagnostic)]
#[diag("there exists a built-in attribute with the same name")]
pub(crate) struct AmbiguousDeriveHelpers;
#[derive(Diagnostic)]
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/value items")]
pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
pub attr_name: Symbol,
}
#[derive(Diagnostic)]
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` expects a list of items")]
pub(crate) struct DocAutoCfgHideShowExpectsList {
pub attr_name: Symbol,
}
#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `include`")]
pub(crate) struct DocUnknownInclude {
pub inner: &'static str,
pub value: Symbol,
#[suggestion(
"use `doc = include_str!` instead",
code = "#{inner}[doc = include_str!(\"{value}\")]"
)]
pub sugg: (Span, Applicability),
}
+1 -24
View File
@@ -1,7 +1,7 @@
use std::any::Any;
use rustc_data_structures::sync::DynSend;
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level};
use rustc_hir::lints::{AttributeLintKind, FormatWarning};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
@@ -43,29 +43,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
.into_diag(dcx, level)
}
&AttributeLintKind::AmbiguousDeriveHelpers => {
lints::AmbiguousDeriveHelpers.into_diag(dcx, level)
}
&AttributeLintKind::DocAutoCfgHideShowUnexpectedItem { attr_name } => {
lints::DocAutoCfgHideShowUnexpectedItem { attr_name }.into_diag(dcx, level)
}
&AttributeLintKind::DocAutoCfgHideShowExpectsList { attr_name } => {
lints::DocAutoCfgHideShowExpectsList { attr_name }.into_diag(dcx, level)
}
&AttributeLintKind::DocInvalid => lints::DocInvalid.into_diag(dcx, level),
&AttributeLintKind::DocUnknownInclude { span, inner, value } => {
lints::DocUnknownInclude {
inner,
value,
sugg: (span, Applicability::MaybeIncorrect),
}
.into_diag(dcx, level)
}
&AttributeLintKind::DocUnknownSpotlight { span } => {
lints::DocUnknownSpotlight { sugg_span: span }.into_diag(dcx, level)
}
-32
View File
@@ -3303,38 +3303,6 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
)]
pub(crate) struct ExpectedNameValue;
#[derive(Diagnostic)]
#[diag("there exists a built-in attribute with the same name")]
pub(crate) struct AmbiguousDeriveHelpers;
#[derive(Diagnostic)]
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/value items")]
pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
pub attr_name: Symbol,
}
#[derive(Diagnostic)]
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` expects a list of items")]
pub(crate) struct DocAutoCfgHideShowExpectsList {
pub attr_name: Symbol,
}
#[derive(Diagnostic)]
#[diag("invalid `doc` attribute")]
pub(crate) struct DocInvalid;
#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `include`")]
pub(crate) struct DocUnknownInclude {
pub inner: &'static str,
pub value: Symbol,
#[suggestion(
"use `doc = include_str!` instead",
code = "#{inner}[doc = include_str!(\"{value}\")]"
)]
pub sugg: (Span, Applicability),
}
#[derive(Diagnostic)]
#[diag("unknown `doc` attribute `spotlight`")]
#[note("`doc(spotlight)` was renamed to `doc(notable_trait)`")]
-5
View File
@@ -656,11 +656,6 @@ pub enum DeprecatedSinceKind {
pub enum AttributeLintKind {
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
DocAutoCfgHideShowUnexpectedItem { attr_name: Symbol },
DocAutoCfgHideShowExpectsList { attr_name: Symbol },
DocInvalid,
AmbiguousDeriveHelpers,
DocUnknownInclude { span: Span, inner: &'static str, value: Symbol },
DocUnknownSpotlight { span: Span },
DocUnknownPasses { name: Symbol, span: Span },
DocUnknownPlugins { span: Span },