From ee8ca0a89ff8bff74c98ac0920cbfcb366354286 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Fri, 13 Feb 2026 12:43:02 +0000 Subject: [PATCH] Port `#[panic_handler]` to the new attribute parsers --- .../rustc_attr_parsing/src/attributes/rustc_internal.rs | 9 +++++++++ compiler/rustc_attr_parsing/src/context.rs | 1 + compiler/rustc_passes/src/lang_items.rs | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index 7dbf38419a4b..e7b639c9af18 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -668,6 +668,15 @@ impl NoArgsAttributeParser for RustcHasIncoherentInherentImplsParse const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcHasIncoherentInherentImpls; } +pub(crate) struct PanicHandlerParser; + +impl NoArgsAttributeParser for PanicHandlerParser { + const PATH: &[Symbol] = &[sym::panic_handler]; + const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); // Targets are checked per lang item in `rustc_passes` + const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::Lang(LangItem::PanicImpl, span); +} + pub(crate) struct RustcHiddenTypeOfOpaquesParser; impl NoArgsAttributeParser for RustcHiddenTypeOfOpaquesParser { diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index b61da848967a..93a2b819c51f 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -254,6 +254,7 @@ attribute_parsers!( Single>, Single>, Single>, + Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index ba71630d2681..25aea8e9f82a 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -8,7 +8,7 @@ //! * Functions called by the compiler itself. use rustc_ast as ast; -use rustc_ast::fmvisit; +use rustc_ast::visit; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::GenericRequirement;