@@ -930,8 +930,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
930930
931931 check_abi ( tcx, it. hir_id ( ) , it. span , abi) ;
932932
933- for item in items {
934- let def_id = item. id . owner_id . def_id ;
933+ for & item in items {
934+ let def_id = item. owner_id . def_id ;
935935
936936 let generics = tcx. generics_of ( def_id) ;
937937 let own_counts = generics. own_counts ( ) ;
@@ -943,13 +943,14 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
943943 ( 0 , _) => ( "const" , "consts" , None ) ,
944944 _ => ( "type or const" , "types or consts" , None ) ,
945945 } ;
946+ let span = tcx. def_span ( def_id) ;
946947 struct_span_code_err ! (
947948 tcx. dcx( ) ,
948- item . span,
949+ span,
949950 E0044 ,
950951 "foreign items may not have {kinds} parameters" ,
951952 )
952- . with_span_label ( item . span , format ! ( "can't have {kinds} parameters" ) )
953+ . with_span_label ( span, format ! ( "can't have {kinds} parameters" ) )
953954 . with_help (
954955 // FIXME: once we start storing spans for type arguments, turn this
955956 // into a suggestion.
@@ -963,22 +964,23 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
963964 . emit ( ) ;
964965 }
965966
966- let item = tcx. hir_foreign_item ( item. id ) ;
967- tcx. ensure_ok ( ) . generics_of ( item. owner_id ) ;
968- tcx. ensure_ok ( ) . type_of ( item. owner_id ) ;
969- tcx. ensure_ok ( ) . predicates_of ( item. owner_id ) ;
967+ tcx. ensure_ok ( ) . generics_of ( def_id) ;
968+ tcx. ensure_ok ( ) . type_of ( def_id) ;
969+ tcx. ensure_ok ( ) . predicates_of ( def_id) ;
970970 if tcx. is_conditionally_const ( def_id) {
971971 tcx. ensure_ok ( ) . explicit_implied_const_bounds ( def_id) ;
972972 tcx. ensure_ok ( ) . const_conditions ( def_id) ;
973973 }
974- match item. kind {
975- hir:: ForeignItemKind :: Fn ( sig, ..) => {
976- tcx. ensure_ok ( ) . codegen_fn_attrs ( item. owner_id ) ;
977- tcx. ensure_ok ( ) . fn_sig ( item. owner_id ) ;
974+ match tcx. def_kind ( def_id) {
975+ DefKind :: Fn => {
976+ tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id) ;
977+ tcx. ensure_ok ( ) . fn_sig ( def_id) ;
978+ let item = tcx. hir_foreign_item ( item) ;
979+ let hir:: ForeignItemKind :: Fn ( sig, ..) = item. kind else { bug ! ( ) } ;
978980 require_c_abi_if_c_variadic ( tcx, sig. decl , abi, item. span ) ;
979981 }
980- hir :: ForeignItemKind :: Static ( .. ) => {
981- tcx. ensure_ok ( ) . codegen_fn_attrs ( item . owner_id ) ;
982+ DefKind :: Static { .. } => {
983+ tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id ) ;
982984 }
983985 _ => ( ) ,
984986 }
0 commit comments