11use rustc_ast:: Attribute ;
22use rustc_hir:: def:: DefKind ;
3- use rustc_hir:: def_id:: DefId ;
3+ use rustc_hir:: def_id:: LocalDefId ;
44use rustc_middle:: ty:: layout:: { FnAbiError , LayoutError } ;
55use rustc_middle:: ty:: { self , GenericArgs , Instance , Ty , TyCtxt } ;
66use rustc_span:: source_map:: Spanned ;
@@ -15,32 +15,17 @@ pub fn test_abi(tcx: TyCtxt<'_>) {
1515 // if the `rustc_attrs` feature is not enabled, don't bother testing ABI
1616 return ;
1717 }
18- for id in tcx. hir ( ) . items ( ) {
19- for attr in tcx. get_attrs ( id. owner_id , sym:: rustc_abi) {
20- match tcx. def_kind ( id. owner_id ) {
21- DefKind :: Fn => {
22- dump_abi_of_fn_item ( tcx, id. owner_id . def_id . into ( ) , attr) ;
18+ for id in tcx. hir_crate_items ( ( ) ) . definitions ( ) {
19+ for attr in tcx. get_attrs ( id, sym:: rustc_abi) {
20+ match tcx. def_kind ( id) {
21+ DefKind :: Fn | DefKind :: AssocFn => {
22+ dump_abi_of_fn_item ( tcx, id, attr) ;
2323 }
2424 DefKind :: TyAlias { .. } => {
25- dump_abi_of_fn_type ( tcx, id. owner_id . def_id . into ( ) , attr) ;
25+ dump_abi_of_fn_type ( tcx, id, attr) ;
2626 }
2727 _ => {
28- tcx. sess . emit_err ( AbiInvalidAttribute { span : tcx. def_span ( id. owner_id ) } ) ;
29- }
30- }
31- }
32- if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: Impl { .. } ) {
33- // To find associated functions we need to go into the child items here.
34- for & id in tcx. associated_item_def_ids ( id. owner_id ) {
35- for attr in tcx. get_attrs ( id, sym:: rustc_abi) {
36- match tcx. def_kind ( id) {
37- DefKind :: AssocFn => {
38- dump_abi_of_fn_item ( tcx, id, attr) ;
39- }
40- _ => {
41- tcx. sess . emit_err ( AbiInvalidAttribute { span : tcx. def_span ( id) } ) ;
42- }
43- }
28+ tcx. sess . emit_err ( AbiInvalidAttribute { span : tcx. def_span ( id) } ) ;
4429 }
4530 }
4631 }
@@ -50,7 +35,7 @@ pub fn test_abi(tcx: TyCtxt<'_>) {
5035fn unwrap_fn_abi < ' tcx > (
5136 abi : Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > ,
5237 tcx : TyCtxt < ' tcx > ,
53- item_def_id : DefId ,
38+ item_def_id : LocalDefId ,
5439) -> & ' tcx FnAbi < ' tcx , Ty < ' tcx > > {
5540 match abi {
5641 Ok ( abi) => abi,
@@ -72,10 +57,10 @@ fn unwrap_fn_abi<'tcx>(
7257 }
7358}
7459
75- fn dump_abi_of_fn_item ( tcx : TyCtxt < ' _ > , item_def_id : DefId , attr : & Attribute ) {
60+ fn dump_abi_of_fn_item ( tcx : TyCtxt < ' _ > , item_def_id : LocalDefId , attr : & Attribute ) {
7661 let param_env = tcx. param_env ( item_def_id) ;
7762 let args = GenericArgs :: identity_for_item ( tcx, item_def_id) ;
78- let instance = match Instance :: resolve ( tcx, param_env, item_def_id, args) {
63+ let instance = match Instance :: resolve ( tcx, param_env, item_def_id. into ( ) , args) {
7964 Ok ( Some ( instance) ) => instance,
8065 Ok ( None ) => {
8166 // Not sure what to do here, but `LayoutError::Unknown` seems reasonable?
@@ -100,7 +85,7 @@ fn dump_abi_of_fn_item(tcx: TyCtxt<'_>, item_def_id: DefId, attr: &Attribute) {
10085 for meta_item in meta_items {
10186 match meta_item. name_or_empty ( ) {
10287 sym:: debug => {
103- let fn_name = tcx. item_name ( item_def_id) ;
88+ let fn_name = tcx. item_name ( item_def_id. into ( ) ) ;
10489 tcx. sess . emit_err ( AbiOf {
10590 span : tcx. def_span ( item_def_id) ,
10691 fn_name,
@@ -129,7 +114,7 @@ fn test_abi_eq<'tcx>(abi1: &'tcx FnAbi<'tcx, Ty<'tcx>>, abi2: &'tcx FnAbi<'tcx,
129114 && abi1. args . iter ( ) . zip ( abi2. args . iter ( ) ) . all ( |( arg1, arg2) | arg1. eq_abi ( arg2) )
130115}
131116
132- fn dump_abi_of_fn_type ( tcx : TyCtxt < ' _ > , item_def_id : DefId , attr : & Attribute ) {
117+ fn dump_abi_of_fn_type ( tcx : TyCtxt < ' _ > , item_def_id : LocalDefId , attr : & Attribute ) {
133118 let param_env = tcx. param_env ( item_def_id) ;
134119 let ty = tcx. type_of ( item_def_id) . instantiate_identity ( ) ;
135120 let span = tcx. def_span ( item_def_id) ;
@@ -152,7 +137,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: DefId, attr: &Attribute) {
152137 item_def_id,
153138 ) ;
154139
155- let fn_name = tcx. item_name ( item_def_id) ;
140+ let fn_name = tcx. item_name ( item_def_id. into ( ) ) ;
156141 tcx. sess . emit_err ( AbiOf { span, fn_name, fn_abi : format ! ( "{:#?}" , abi) } ) ;
157142 }
158143 sym:: assert_eq => {
0 commit comments