@@ -38,7 +38,8 @@ use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
3838use rustc_middle:: query:: Providers ;
3939use rustc_middle:: traits:: ObligationCause ;
4040use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
41- use rustc_middle:: ty:: { self , TyCtxt , TypingMode } ;
41+ use rustc_middle:: ty:: print:: with_no_trimmed_paths;
42+ use rustc_middle:: ty:: { self , GenericArgs , TyCtxt , TypingMode } ;
4243use rustc_middle:: { bug, span_bug} ;
4344use rustc_session:: config:: CrateType ;
4445use rustc_session:: lint;
@@ -231,6 +232,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
231232 self . check_rustc_must_implement_one_of ( * attr_span, fn_names, hir_id, target)
232233 } ,
233234 Attribute :: Parsed ( AttributeKind :: DoNotRecommend { attr_span} ) => { self . check_do_not_recommend ( * attr_span, hir_id, target, item) } ,
235+ Attribute :: Parsed ( AttributeKind :: RustcSymbolName ( attr_span) ) => {
236+ self . check_rustc_symbol_name ( * attr_span, hir_id, target)
237+ }
238+ Attribute :: Parsed ( AttributeKind :: RustcDefPath ( attr_span) ) => {
239+ self . check_rustc_def_path ( * attr_span, hir_id, target) ;
240+ }
234241 Attribute :: Parsed (
235242 // tidy-alphabetical-start
236243 AttributeKind :: RustcAllowIncoherentImpl ( ..)
@@ -300,7 +307,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
300307 | AttributeKind :: RustcConfusables { .. }
301308 | AttributeKind :: RustcConstStabilityIndirect
302309 | AttributeKind :: RustcDeallocator
303- | AttributeKind :: RustcDefPath ( ..)
304310 | AttributeKind :: RustcDelayedBugFromInsideQuery
305311 | AttributeKind :: RustcDenyExplicitImpl ( ..)
306312 | AttributeKind :: RustcDummy
@@ -347,7 +353,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
347353 | AttributeKind :: RustcSkipDuringMethodDispatch { .. }
348354 | AttributeKind :: RustcSpecializationTrait ( ..)
349355 | AttributeKind :: RustcStdInternalSymbol ( ..)
350- | AttributeKind :: RustcSymbolName ( ..)
351356 | AttributeKind :: RustcThenThisWouldNeed ( ..)
352357 | AttributeKind :: RustcUnsafeSpecializationMarker ( ..)
353358 | AttributeKind :: RustcVariance
@@ -507,6 +512,64 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
507512 self . check_mix_no_mangle_export ( hir_id, attrs) ;
508513 }
509514
515+ fn is_valid_symbol_attr ( & self , target : & Target ) -> bool {
516+ self . tcx . sess . opts . output_types . should_codegen ( )
517+ && [
518+ Target :: Fn ,
519+ Target :: Method ( MethodKind :: TraitImpl ) ,
520+ Target :: Method ( MethodKind :: Inherent ) ,
521+ Target :: Method ( MethodKind :: Trait { body : true } ) ,
522+ Target :: ForeignFn ,
523+ Target :: ForeignStatic ,
524+ Target :: Impl { of_trait : false } ,
525+ ]
526+ . contains ( target)
527+ }
528+
529+ fn check_rustc_symbol_name ( & self , attr_span : Span , hir_id : HirId , target : Target ) {
530+ use rustc_symbol_mangling:: errors:: { Kind , TestOutput } ;
531+ let tcx = self . tcx ;
532+ if !self . is_valid_symbol_attr ( & target) {
533+ return ;
534+ }
535+ let def_id = hir_id. owner . def_id . to_def_id ( ) ;
536+ let instance = ty:: Instance :: new_raw (
537+ def_id,
538+ tcx. erase_and_anonymize_regions ( GenericArgs :: identity_for_item ( tcx, def_id) ) ,
539+ ) ;
540+ let mangled = tcx. symbol_name ( instance) ;
541+ tcx. dcx ( ) . emit_err ( TestOutput {
542+ span : attr_span,
543+ kind : Kind :: SymbolName ,
544+ content : format ! ( "{mangled}" ) ,
545+ } ) ;
546+ if let Ok ( demangling) = rustc_demangle:: try_demangle ( mangled. name ) {
547+ tcx. dcx ( ) . emit_err ( TestOutput {
548+ span : attr_span,
549+ kind : Kind :: Demangling ,
550+ content : format ! ( "{demangling}" ) ,
551+ } ) ;
552+ tcx. dcx ( ) . emit_err ( TestOutput {
553+ span : attr_span,
554+ kind : Kind :: DemanglingAlt ,
555+ content : format ! ( "{demangling:#}" ) ,
556+ } ) ;
557+ }
558+ }
559+
560+ fn check_rustc_def_path ( & self , attr_span : Span , hir_id : HirId , target : Target ) {
561+ use rustc_symbol_mangling:: errors:: { Kind , TestOutput } ;
562+ let tcx = self . tcx ;
563+ if !self . is_valid_symbol_attr ( & target) {
564+ return ;
565+ }
566+ tcx. dcx ( ) . emit_err ( TestOutput {
567+ span : attr_span,
568+ kind : Kind :: DefPath ,
569+ content : with_no_trimmed_paths ! ( tcx. def_path_str( hir_id. owner. def_id) ) ,
570+ } ) ;
571+ }
572+
510573 fn check_rustc_must_implement_one_of (
511574 & self ,
512575 attr_span : Span ,
0 commit comments