@@ -27,6 +27,7 @@ use rustc_trait_selection::traits;
27
27
use rustc_trait_selection:: traits:: error_reporting:: InferCtxtExt as _;
28
28
use rustc_ty_utils:: representability:: { self , Representability } ;
29
29
30
+ use rustc_hir:: def:: DefKind ;
30
31
use std:: iter;
31
32
use std:: ops:: ControlFlow ;
32
33
@@ -711,28 +712,35 @@ fn check_opaque_meets_bounds<'tcx>(
711
712
} ) ;
712
713
}
713
714
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 ) {
715
716
debug ! (
716
717
"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( ) )
719
720
) ;
720
721
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. 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 ) ) ;
727
727
}
728
- hir :: ItemKind :: Const ( .. ) => {
729
- tcx. ensure ( ) . typeck ( it . def_id ) ;
728
+ DefKind :: Const => {
729
+ tcx. ensure ( ) . typeck ( id . def_id ) ;
730
730
}
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 ) ;
733
737
}
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
+ } ;
736
744
debug ! ( "ItemKind::Impl {} with id {:?}" , it. ident, it. def_id) ;
737
745
if let Some ( impl_trait_ref) = tcx. impl_trait_ref ( it. def_id ) {
738
746
check_impl_items_against_trait (
@@ -745,7 +753,11 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
745
753
check_on_unimplemented ( tcx, it) ;
746
754
}
747
755
}
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
+ } ;
749
761
check_on_unimplemented ( tcx, it) ;
750
762
751
763
for item in items. iter ( ) {
@@ -771,28 +783,36 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
771
783
}
772
784
}
773
785
}
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 ) ) ;
776
788
}
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 ) ) ;
779
791
}
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
+ } ;
781
797
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
782
798
// `async-std` (and `pub async fn` in general).
783
799
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
784
800
// See https://github.com/rust-lang/rust/issues/75100
785
801
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) ;
788
804
}
789
805
}
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 ) ;
793
809
check_type_params_are_used ( tcx, & generics, pty_ty) ;
794
810
}
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
+ } ;
796
816
check_abi ( tcx, it. hir_id ( ) , it. span , abi) ;
797
817
798
818
if abi == Abi :: RustIntrinsic {
@@ -851,7 +871,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
851
871
}
852
872
}
853
873
}
854
- _ => { /* nothing to do */ }
874
+ _ => { }
855
875
}
856
876
}
857
877
@@ -1451,7 +1471,10 @@ pub(super) fn check_type_params_are_used<'tcx>(
1451
1471
}
1452
1472
1453
1473
pub ( super ) fn check_mod_item_types ( tcx : TyCtxt < ' _ > , module_def_id : LocalDefId ) {
1454
- tcx. hir ( ) . visit_item_likes_in_module ( module_def_id, & mut CheckItemTypesVisitor { tcx } ) ;
1474
+ let module = tcx. hir_module_items ( module_def_id) ;
1475
+ for id in module. items ( ) {
1476
+ check_item_type ( tcx, id) ;
1477
+ }
1455
1478
}
1456
1479
1457
1480
pub ( super ) use wfcheck:: check_item_well_formed;
0 commit comments