11use std:: path:: PathBuf ;
22
33use rustc_ast:: { LitIntType , LitKind , MetaItemLit } ;
4+ use rustc_hir:: LangItem ;
45use rustc_hir:: attrs:: {
56 BorrowckGraphvizFormatKind , CguFields , CguKind , DivergingBlockBehavior ,
67 DivergingFallbackBehavior , RustcCleanAttribute , RustcCleanQueries , RustcLayoutType ,
@@ -12,7 +13,7 @@ use rustc_span::Symbol;
1213use super :: prelude:: * ;
1314use super :: util:: parse_single_integer;
1415use crate :: session_diagnostics:: {
15- AttributeRequiresOpt , CguFieldsMissing , RustcScalableVectorCountOutOfRange ,
16+ AttributeRequiresOpt , CguFieldsMissing , RustcScalableVectorCountOutOfRange , UnknownLangItem ,
1617} ;
1718
1819pub ( crate ) struct RustcMainParser ;
@@ -626,6 +627,32 @@ impl<S: Stage> SingleAttributeParser<S> for RustcScalableVectorParser {
626627 }
627628}
628629
630+ pub ( crate ) struct LangParser ;
631+
632+ impl < S : Stage > SingleAttributeParser < S > for LangParser {
633+ const PATH : & [ Symbol ] = & [ sym:: lang] ;
634+ const ATTRIBUTE_ORDER : AttributeOrder = AttributeOrder :: KeepInnermost ;
635+ const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Error ;
636+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ; // Targets are checked per lang item in `rustc_passes`
637+ const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "name" ) ;
638+
639+ fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser ) -> Option < AttributeKind > {
640+ let Some ( nv) = args. name_value ( ) else {
641+ cx. expected_name_value ( cx. attr_span , None ) ;
642+ return None ;
643+ } ;
644+ let Some ( name) = nv. value_as_str ( ) else {
645+ cx. expected_string_literal ( nv. value_span , Some ( nv. value_as_lit ( ) ) ) ;
646+ return None ;
647+ } ;
648+ let Some ( lang_item) = LangItem :: from_name ( name) else {
649+ cx. emit_err ( UnknownLangItem { span : cx. attr_span , name } ) ;
650+ return None ;
651+ } ;
652+ Some ( AttributeKind :: Lang ( lang_item, cx. attr_span ) )
653+ }
654+ }
655+
629656pub ( crate ) struct RustcHasIncoherentInherentImplsParser ;
630657
631658impl < S : Stage > NoArgsAttributeParser < S > for RustcHasIncoherentInherentImplsParser {
@@ -641,6 +668,15 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcHasIncoherentInherentImplsParse
641668 const CREATE : fn ( Span ) -> AttributeKind = |_| AttributeKind :: RustcHasIncoherentInherentImpls ;
642669}
643670
671+ pub ( crate ) struct PanicHandlerParser ;
672+
673+ impl < S : Stage > NoArgsAttributeParser < S > for PanicHandlerParser {
674+ const PATH : & [ Symbol ] = & [ sym:: panic_handler] ;
675+ const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Error ;
676+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ; // Targets are checked per lang item in `rustc_passes`
677+ const CREATE : fn ( Span ) -> AttributeKind = |span| AttributeKind :: Lang ( LangItem :: PanicImpl , span) ;
678+ }
679+
644680pub ( crate ) struct RustcHiddenTypeOfOpaquesParser ;
645681
646682impl < S : Stage > NoArgsAttributeParser < S > for RustcHiddenTypeOfOpaquesParser {
0 commit comments