@@ -27,6 +27,7 @@ use rustc_trait_selection::traits;
2727use rustc_trait_selection:: traits:: error_reporting:: InferCtxtExt as _;
2828use rustc_ty_utils:: representability:: { self , Representability } ;
2929
30+ use rustc_hir:: def:: DefKind ;
3031use std:: iter;
3132use std:: ops:: ControlFlow ;
3233
@@ -711,28 +712,35 @@ fn check_opaque_meets_bounds<'tcx>(
711712 } ) ;
712713}
713714
714- pub fn check_item_type < ' tcx > ( tcx : TyCtxt < ' tcx > , it : & ' tcx hir:: Item < ' tcx > ) {
715+ pub fn check_item_type < ' tcx > ( tcx : TyCtxt < ' tcx > , id : hir:: ItemId ) {
715716 debug ! (
716717 "check_item_type(it.def_id={:?}, it.name={})" ,
717- it . def_id,
718- tcx. def_path_str( it . def_id. to_def_id( ) )
718+ id . def_id,
719+ tcx. def_path_str( id . def_id. to_def_id( ) )
719720 ) ;
720721 let _indenter = indenter ( ) ;
721- match it. kind {
722- // Consts can play a role in type-checking, so they are included here.
723- hir:: ItemKind :: Static ( ..) => {
724- tcx. ensure ( ) . typeck ( it. def_id ) ;
725- maybe_check_static_with_link_section ( tcx, it. def_id , it. span ) ;
726- check_static_inhabited ( tcx, it. def_id , it. span ) ;
722+ match tcx. hir ( ) . def_kind ( id. def_id ) {
723+ DefKind :: Static ( ..) => {
724+ tcx. ensure ( ) . typeck ( id. def_id ) ;
725+ maybe_check_static_with_link_section ( tcx, id. def_id , tcx. def_span ( id. def_id ) ) ;
726+ check_static_inhabited ( tcx, id. def_id , tcx. def_span ( id. def_id ) ) ;
727727 }
728- hir :: ItemKind :: Const ( .. ) => {
729- tcx. ensure ( ) . typeck ( it . def_id ) ;
728+ DefKind :: Const => {
729+ tcx. ensure ( ) . typeck ( id . def_id ) ;
730730 }
731- hir:: ItemKind :: Enum ( ref enum_definition, _) => {
732- check_enum ( tcx, it. span , & enum_definition. variants , it. def_id ) ;
731+ DefKind :: Enum => {
732+ let item = tcx. hir ( ) . item ( id) ;
733+ let hir:: ItemKind :: Enum ( ref enum_definition, _) = item. kind else {
734+ return ;
735+ } ;
736+ check_enum ( tcx, item. span , & enum_definition. variants , item. def_id ) ;
733737 }
734- hir:: ItemKind :: Fn ( ..) => { } // entirely within check_item_body
735- hir:: ItemKind :: Impl ( ref impl_) => {
738+ DefKind :: Fn => { } // entirely within check_item_body
739+ DefKind :: Impl => {
740+ let it = tcx. hir ( ) . item ( id) ;
741+ let hir:: ItemKind :: Impl ( ref impl_) = it. kind else {
742+ return ;
743+ } ;
736744 debug ! ( "ItemKind::Impl {} with id {:?}" , it. ident, it. def_id) ;
737745 if let Some ( impl_trait_ref) = tcx. impl_trait_ref ( it. def_id ) {
738746 check_impl_items_against_trait (
@@ -745,7 +753,11 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
745753 check_on_unimplemented ( tcx, it) ;
746754 }
747755 }
748- hir:: ItemKind :: Trait ( _, _, _, _, ref items) => {
756+ DefKind :: Trait => {
757+ let it = tcx. hir ( ) . item ( id) ;
758+ let hir:: ItemKind :: Trait ( _, _, _, _, ref items) = it. kind else {
759+ return ;
760+ } ;
749761 check_on_unimplemented ( tcx, it) ;
750762
751763 for item in items. iter ( ) {
@@ -771,28 +783,36 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
771783 }
772784 }
773785 }
774- hir :: ItemKind :: Struct ( .. ) => {
775- check_struct ( tcx, it . def_id , it . span ) ;
786+ DefKind :: Struct => {
787+ check_struct ( tcx, id . def_id , tcx . def_span ( id . def_id ) ) ;
776788 }
777- hir :: ItemKind :: Union ( .. ) => {
778- check_union ( tcx, it . def_id , it . span ) ;
789+ DefKind :: Union => {
790+ check_union ( tcx, id . def_id , tcx . def_span ( id . def_id ) ) ;
779791 }
780- hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) => {
792+ DefKind :: OpaqueTy => {
793+ let item = tcx. hir ( ) . item ( id) ;
794+ let hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) = item. kind else {
795+ return ;
796+ } ;
781797 // HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
782798 // `async-std` (and `pub async fn` in general).
783799 // Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
784800 // See https://github.com/rust-lang/rust/issues/75100
785801 if !tcx. sess . opts . actually_rustdoc {
786- let substs = InternalSubsts :: identity_for_item ( tcx, it . def_id . to_def_id ( ) ) ;
787- check_opaque ( tcx, it . def_id , substs, it . span , & origin) ;
802+ let substs = InternalSubsts :: identity_for_item ( tcx, item . def_id . to_def_id ( ) ) ;
803+ check_opaque ( tcx, item . def_id , substs, item . span , & origin) ;
788804 }
789805 }
790- hir :: ItemKind :: TyAlias ( .. ) => {
791- let pty_ty = tcx. type_of ( it . def_id ) ;
792- let generics = tcx. generics_of ( it . def_id ) ;
806+ DefKind :: TyAlias => {
807+ let pty_ty = tcx. type_of ( id . def_id ) ;
808+ let generics = tcx. generics_of ( id . def_id ) ;
793809 check_type_params_are_used ( tcx, & generics, pty_ty) ;
794810 }
795- hir:: ItemKind :: ForeignMod { abi, items } => {
811+ DefKind :: ForeignMod => {
812+ let it = tcx. hir ( ) . item ( id) ;
813+ let hir:: ItemKind :: ForeignMod { abi, items } = it. kind else {
814+ return ;
815+ } ;
796816 check_abi ( tcx, it. hir_id ( ) , it. span , abi) ;
797817
798818 if abi == Abi :: RustIntrinsic {
@@ -851,7 +871,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
851871 }
852872 }
853873 }
854- _ => { /* nothing to do */ }
874+ _ => { }
855875 }
856876}
857877
@@ -1453,8 +1473,8 @@ pub(super) fn check_type_params_are_used<'tcx>(
14531473pub ( super ) fn check_mod_item_types ( tcx : TyCtxt < ' _ > , module_def_id : LocalDefId ) {
14541474 let module = tcx. hir_module_items ( module_def_id) ;
14551475 for id in module. items ( ) {
1456- let item = tcx. hir ( ) . item ( id) ;
1457- check_item_type ( tcx, item )
1476+ // let item = tcx.hir().item(id);
1477+ check_item_type ( tcx, id ) ;
14581478 }
14591479}
14601480
0 commit comments