@@ -931,8 +931,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
931931
932932 check_abi ( tcx, it. hir_id ( ) , it. span , abi) ;
933933
934- for item in items {
935- let def_id = item. id . owner_id . def_id ;
934+ for & item in items {
935+ let def_id = item. owner_id . def_id ;
936936
937937 let generics = tcx. generics_of ( def_id) ;
938938 let own_counts = generics. own_counts ( ) ;
@@ -944,13 +944,14 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
944944 ( 0 , _) => ( "const" , "consts" , None ) ,
945945 _ => ( "type or const" , "types or consts" , None ) ,
946946 } ;
947+ let span = tcx. def_span ( def_id) ;
947948 struct_span_code_err ! (
948949 tcx. dcx( ) ,
949- item . span,
950+ span,
950951 E0044 ,
951952 "foreign items may not have {kinds} parameters" ,
952953 )
953- . with_span_label ( item . span , format ! ( "can't have {kinds} parameters" ) )
954+ . with_span_label ( span, format ! ( "can't have {kinds} parameters" ) )
954955 . with_help (
955956 // FIXME: once we start storing spans for type arguments, turn this
956957 // into a suggestion.
@@ -964,22 +965,23 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
964965 . emit ( ) ;
965966 }
966967
967- let item = tcx. hir_foreign_item ( item. id ) ;
968- tcx. ensure_ok ( ) . generics_of ( item. owner_id ) ;
969- tcx. ensure_ok ( ) . type_of ( item. owner_id ) ;
970- tcx. ensure_ok ( ) . predicates_of ( item. owner_id ) ;
968+ tcx. ensure_ok ( ) . generics_of ( def_id) ;
969+ tcx. ensure_ok ( ) . type_of ( def_id) ;
970+ tcx. ensure_ok ( ) . predicates_of ( def_id) ;
971971 if tcx. is_conditionally_const ( def_id) {
972972 tcx. ensure_ok ( ) . explicit_implied_const_bounds ( def_id) ;
973973 tcx. ensure_ok ( ) . const_conditions ( def_id) ;
974974 }
975- match item. kind {
976- hir:: ForeignItemKind :: Fn ( sig, ..) => {
977- tcx. ensure_ok ( ) . codegen_fn_attrs ( item. owner_id ) ;
978- tcx. ensure_ok ( ) . fn_sig ( item. owner_id ) ;
975+ match tcx. def_kind ( def_id) {
976+ DefKind :: Fn => {
977+ tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id) ;
978+ tcx. ensure_ok ( ) . fn_sig ( def_id) ;
979+ let item = tcx. hir_foreign_item ( item) ;
980+ let hir:: ForeignItemKind :: Fn ( sig, ..) = item. kind else { bug ! ( ) } ;
979981 require_c_abi_if_c_variadic ( tcx, sig. decl , abi, item. span ) ;
980982 }
981- hir :: ForeignItemKind :: Static ( .. ) => {
982- tcx. ensure_ok ( ) . codegen_fn_attrs ( item . owner_id ) ;
983+ DefKind :: Static { .. } => {
984+ tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id ) ;
983985 }
984986 _ => ( ) ,
985987 }
0 commit comments