diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index ea5d7cf5cda8..665c516c3e8e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -13,6 +13,7 @@ use super::prelude::{ALL_TARGETS, AllowedTargets}; use super::{AcceptMapping, AttributeParser}; use crate::context::{AcceptContext, FinalizeContext, Stage}; +use crate::errors::{DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, IllFormedAttributeInput}; use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser}; use crate::session_diagnostics::{ DocAliasBadChar, DocAliasEmpty, DocAliasMalformed, DocAliasStartEnd, DocAttrNotCrateLevel, @@ -257,9 +258,7 @@ fn add_alias( if let Some(first_definition) = self.attribute.aliases.get(&alias).copied() { cx.emit_dyn_lint( rustc_session::lint::builtin::UNUSED_ATTRIBUTES, - move |dcx, level| { - crate::errors::DocAliasDuplicated { first_definition }.into_diag(dcx, level) - }, + move |dcx, level| DocAliasDuplicated { first_definition }.into_diag(dcx, level), span, ); } @@ -345,9 +344,9 @@ fn parse_auto_cfg( ArgParser::List(list) => { for meta in list.mixed() { let MetaItemOrLitParser::MetaItemParser(item) = meta else { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::DocAutoCfgExpectsHideOrShow, + |dcx, level| DocAutoCfgExpectsHideOrShow.into_diag(dcx, level), meta.span(), ); continue; @@ -356,9 +355,9 @@ fn parse_auto_cfg( Some(sym::hide) => (HideOrShow::Hide, sym::hide), Some(sym::show) => (HideOrShow::Show, sym::show), _ => { - cx.emit_lint( + cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, - AttributeLintKind::DocAutoCfgExpectsHideOrShow, + |dcx, level| DocAutoCfgExpectsHideOrShow.into_diag(dcx, level), item.span(), ); continue; @@ -671,8 +670,7 @@ fn accept_single_doc_attr( cx.emit_dyn_lint( rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES, move |dcx, level| { - crate::errors::IllFormedAttributeInput::new(&suggestions, None, None) - .into_diag(dcx, level) + IllFormedAttributeInput::new(&suggestions, None, None).into_diag(dcx, level) }, span, ); diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index 75a97c49f29c..8148a859958b 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -173,3 +173,7 @@ pub(crate) struct DocAliasDuplicated { #[label("first defined here")] pub first_definition: Span, } + +#[derive(Diagnostic)] +#[diag("only `hide` or `show` are allowed in `#[doc(auto_cfg(...))]`")] +pub(crate) struct DocAutoCfgExpectsHideOrShow; diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 2ff0ab66fde8..fb59cd35ad46 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::DocAutoCfgExpectsHideOrShow => { - lints::DocAutoCfgExpectsHideOrShow.into_diag(dcx, level) - } - &AttributeLintKind::AmbiguousDeriveHelpers => { lints::AmbiguousDeriveHelpers.into_diag(dcx, level) } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 24c59958077b..b92efc408ae8 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3303,10 +3303,6 @@ fn add_to_diag(self, diag: &mut Diag<'_, G>) { )] pub(crate) struct ExpectedNameValue; -#[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; diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 99efe5cfed9b..29da46770d52 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)>), - DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowUnexpectedItem { attr_name: Symbol }, DocAutoCfgHideShowExpectsList { attr_name: Symbol }, DocInvalid,