11use rustc_hir as hir;
2+ use rustc_hir:: attrs:: AttributeKind ;
23use rustc_hir:: def_id:: { CRATE_DEF_ID , LocalDefId } ;
3- use rustc_hir:: intravisit;
4+ use rustc_hir:: { find_attr , intravisit} ;
45use rustc_middle:: hir:: nested_filter;
56use rustc_middle:: ty:: { self , TyCtxt , TypeVisitableExt } ;
67use rustc_span:: sym;
@@ -28,7 +29,7 @@ pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
2829
2930pub ( crate ) fn predicates_and_item_bounds ( tcx : TyCtxt < ' _ > ) {
3031 for id in tcx. hir_crate_items ( ( ) ) . owners ( ) {
31- if tcx. has_attr ( id, sym :: rustc_dump_predicates ) {
32+ if find_attr ! ( tcx. get_all_attrs ( id) , AttributeKind :: RustcDumpPredicates ) {
3233 let preds = tcx. predicates_of ( id) . instantiate_identity ( tcx) . predicates ;
3334 let span = tcx. def_span ( id) ;
3435
@@ -38,7 +39,7 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
3839 }
3940 diag. emit ( ) ;
4041 }
41- if tcx. has_attr ( id, sym :: rustc_dump_item_bounds ) {
42+ if find_attr ! ( tcx. get_all_attrs ( id) , AttributeKind :: RustcDumpItemBounds ) {
4243 let bounds = tcx. item_bounds ( id) . instantiate_identity ( ) ;
4344 let span = tcx. def_span ( id) ;
4445
@@ -54,7 +55,7 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
5455pub ( crate ) fn def_parents ( tcx : TyCtxt < ' _ > ) {
5556 for iid in tcx. hir_free_items ( ) {
5657 let did = iid. owner_id . def_id ;
57- if tcx. has_attr ( did, sym :: rustc_dump_def_parents ) {
58+ if find_attr ! ( tcx. get_all_attrs ( did) , AttributeKind :: RustcDumpDefParents ) {
5859 struct AnonConstFinder < ' tcx > {
5960 tcx : TyCtxt < ' tcx > ,
6061 anon_consts : Vec < LocalDefId > ,
@@ -102,7 +103,9 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
102103 for id in tcx. hir_free_items ( ) {
103104 let def_id = id. owner_id . def_id ;
104105
105- let Some ( attr) = tcx. get_attr ( def_id, sym:: rustc_dump_vtable) else {
106+ let Some ( & attr_span) =
107+ find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: RustcDumpVtable ( span) => span)
108+ else {
106109 continue ;
107110 } ;
108111
@@ -111,14 +114,14 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
111114 let trait_ref = tcx. impl_trait_ref ( def_id) . instantiate_identity ( ) ;
112115 if trait_ref. has_non_region_param ( ) {
113116 tcx. dcx ( ) . span_err (
114- attr . span ( ) ,
117+ attr_span ,
115118 "`rustc_dump_vtable` must be applied to non-generic impl" ,
116119 ) ;
117120 continue ;
118121 }
119122 if !tcx. is_dyn_compatible ( trait_ref. def_id ) {
120123 tcx. dcx ( ) . span_err (
121- attr . span ( ) ,
124+ attr_span ,
122125 "`rustc_dump_vtable` must be applied to dyn-compatible trait" ,
123126 ) ;
124127 continue ;
@@ -127,7 +130,7 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
127130 . try_normalize_erasing_regions ( ty:: TypingEnv :: fully_monomorphized ( ) , trait_ref)
128131 else {
129132 tcx. dcx ( ) . span_err (
130- attr . span ( ) ,
133+ attr_span ,
131134 "`rustc_dump_vtable` applied to impl header that cannot be normalized" ,
132135 ) ;
133136 continue ;
@@ -138,7 +141,7 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
138141 let ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
139142 if ty. has_non_region_param ( ) {
140143 tcx. dcx ( ) . span_err (
141- attr . span ( ) ,
144+ attr_span ,
142145 "`rustc_dump_vtable` must be applied to non-generic type" ,
143146 ) ;
144147 continue ;
@@ -147,14 +150,13 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
147150 tcx. try_normalize_erasing_regions ( ty:: TypingEnv :: fully_monomorphized ( ) , ty)
148151 else {
149152 tcx. dcx ( ) . span_err (
150- attr . span ( ) ,
153+ attr_span ,
151154 "`rustc_dump_vtable` applied to type alias that cannot be normalized" ,
152155 ) ;
153156 continue ;
154157 } ;
155158 let ty:: Dynamic ( data, _) = * ty. kind ( ) else {
156- tcx. dcx ( )
157- . span_err ( attr. span ( ) , "`rustc_dump_vtable` to type alias of dyn type" ) ;
159+ tcx. dcx ( ) . span_err ( attr_span, "`rustc_dump_vtable` to type alias of dyn type" ) ;
158160 continue ;
159161 } ;
160162 if let Some ( principal) = data. principal ( ) {
@@ -167,7 +169,7 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
167169 }
168170 _ => {
169171 tcx. dcx ( ) . span_err (
170- attr . span ( ) ,
172+ attr_span ,
171173 "`rustc_dump_vtable` only applies to impl, or type alias of dyn type" ,
172174 ) ;
173175 continue ;
0 commit comments