From eba0efd9aaef79149de08d1affe969c5213c0fe7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 23 Mar 2026 12:11:17 +0100 Subject: [PATCH] Remove more `BuiltinLintDiag` in `rustc_attr_parsing` --- .../src/attributes/cfg_select.rs | 14 ++++++++++---- compiler/rustc_attr_parsing/src/errors.rs | 17 +++++++++++++++++ compiler/rustc_lint/src/early/diagnostics.rs | 7 ------- compiler/rustc_lint/src/lints.rs | 17 ----------------- compiler/rustc_lint_defs/src/lib.rs | 4 ---- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs b/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs index f3612afe69e5..4ff224006ca8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg_select.rs @@ -2,18 +2,18 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{AttrStyle, NodeId, token}; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::Diagnostic; use rustc_feature::{AttributeTemplate, Features}; use rustc_hir::attrs::CfgEntry; use rustc_hir::{AttrPath, Target}; use rustc_parse::exp; use rustc_parse::parser::{Parser, Recovery}; use rustc_session::Session; -use rustc_session::lint::BuiltinLintDiag; use rustc_session::lint::builtin::UNREACHABLE_CFG_SELECT_PREDICATES; use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; use crate::parser::{AllowExprMetavar, MetaItemOrLitParser}; -use crate::{AttributeParser, ParsedDescription, ShouldEmit, parse_cfg_entry}; +use crate::{AttributeParser, ParsedDescription, ShouldEmit, errors, parse_cfg_entry}; #[derive(Clone)] pub enum CfgSelectPredicate { @@ -153,11 +153,17 @@ fn lint_unreachable( let branch_is_unreachable = |predicate: CfgSelectPredicate, wildcard_span| { let span = predicate.span(); - p.psess.buffer_lint( + p.psess.dyn_buffer_lint( UNREACHABLE_CFG_SELECT_PREDICATES, span, lint_node_id, - BuiltinLintDiag::UnreachableCfg { span, wildcard_span }, + move |dcx, level| match wildcard_span { + Some(wildcard_span) => { + errors::UnreachableCfgSelectPredicateWildcard { span, wildcard_span } + .into_diag(dcx, level) + } + None => errors::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level), + }, ); }; diff --git a/compiler/rustc_attr_parsing/src/errors.rs b/compiler/rustc_attr_parsing/src/errors.rs index 4eb9425b34bb..d4236416dd6a 100644 --- a/compiler/rustc_attr_parsing/src/errors.rs +++ b/compiler/rustc_attr_parsing/src/errors.rs @@ -26,6 +26,13 @@ pub(crate) struct ItemFollowingInnerAttr { pub span: Span, } +#[derive(Diagnostic)] +#[diag("unreachable configuration predicate")] +pub(crate) struct UnreachableCfgSelectPredicate { + #[label("this configuration predicate is never reached")] + pub span: Span, +} + #[derive(Diagnostic)] #[diag("most attributes are not supported in `where` clauses")] #[help("only `#[cfg]` and `#[cfg_attr]` are supported")] @@ -33,3 +40,13 @@ pub(crate) struct UnsupportedAttributesInWhere { #[primary_span] pub span: MultiSpan, } + +#[derive(Diagnostic)] +#[diag("unreachable configuration predicate")] +pub(crate) struct UnreachableCfgSelectPredicateWildcard { + #[label("this configuration predicate is never reached")] + pub span: Span, + + #[label("always matches")] + pub wildcard_span: Span, +} diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 43bb3971d7ac..a6d7f0a11e32 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -224,13 +224,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { } .into_diag(dcx, level) } - BuiltinLintDiag::UnreachableCfg { span, wildcard_span } => match wildcard_span { - Some(wildcard_span) => { - lints::UnreachableCfgSelectPredicateWildcard { span, wildcard_span } - .into_diag(dcx, level) - } - None => lints::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level), - }, BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => { lints::UnusedCrateDependency { extern_crate, local_crate }.into_diag(dcx, level) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index c7c92356c378..f9cc259bdf4f 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3709,23 +3709,6 @@ pub(crate) struct UnknownCrateTypesSuggestion { pub snippet: Symbol, } -#[derive(Diagnostic)] -#[diag("unreachable configuration predicate")] -pub(crate) struct UnreachableCfgSelectPredicate { - #[label("this configuration predicate is never reached")] - pub span: Span, -} - -#[derive(Diagnostic)] -#[diag("unreachable configuration predicate")] -pub(crate) struct UnreachableCfgSelectPredicateWildcard { - #[label("this configuration predicate is never reached")] - pub span: Span, - - #[label("always matches")] - pub wildcard_span: Span, -} - #[derive(Diagnostic)] #[diag("positional format arguments are not allowed here")] #[help( diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 0faa50442961..6314add5f1ae 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -732,10 +732,6 @@ pub enum BuiltinLintDiag { local_crate: Symbol, }, AttributeLint(AttributeLintKind), - UnreachableCfg { - span: Span, - wildcard_span: Option, - }, } #[derive(Debug, HashStable_Generic)]