@@ -309,11 +309,11 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
309309 check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
310310 }
311311 hir:: ItemKind :: Struct ( _, hir_generics) => check_type_defn ( tcx, item, false )
312- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
312+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
313313 hir:: ItemKind :: Union ( _, hir_generics) => check_type_defn ( tcx, item, true )
314- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
314+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
315315 hir:: ItemKind :: Enum ( _, hir_generics) => check_type_defn ( tcx, item, true )
316- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
316+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
317317 hir:: ItemKind :: Trait ( ..) => check_trait ( tcx, item) ,
318318 hir:: ItemKind :: TraitAlias ( ..) => check_trait ( tcx, item) ,
319319 // `ForeignItem`s are handled separately.
@@ -323,7 +323,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
323323 // Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
324324 // E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
325325 check_item_type ( tcx, def_id, hir_ty. span , UnsizedHandling :: Allow )
326- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) )
326+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) )
327327 } else {
328328 Ok ( ( ) )
329329 }
@@ -1801,30 +1801,30 @@ fn receiver_is_implemented<'tcx>(
18011801
18021802fn check_variances_for_type_defn < ' tcx > (
18031803 tcx : TyCtxt < ' tcx > ,
1804- item : & hir :: Item < ' tcx > ,
1804+ item : LocalDefId ,
18051805 hir_generics : & hir:: Generics < ' tcx > ,
18061806) -> Result < ( ) , ErrorGuaranteed > {
1807- let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item. owner_id ) ;
1807+ let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item) ;
18081808
1809- match item . kind {
1810- ItemKind :: Enum ( .. ) | ItemKind :: Struct ( .. ) | ItemKind :: Union ( .. ) => {
1811- for field in tcx. adt_def ( item. owner_id ) . all_fields ( ) {
1809+ match tcx . def_kind ( item ) {
1810+ DefKind :: Enum | DefKind :: Struct | DefKind :: Union => {
1811+ for field in tcx. adt_def ( item) . all_fields ( ) {
18121812 field. ty ( tcx, identity_args) . error_reported ( ) ?;
18131813 }
18141814 }
1815- ItemKind :: TyAlias ( .. ) => {
1815+ DefKind :: TyAlias => {
18161816 assert ! (
1817- tcx. type_alias_is_lazy( item. owner_id ) ,
1817+ tcx. type_alias_is_lazy( item) ,
18181818 "should not be computing variance of non-weak type alias"
18191819 ) ;
1820- tcx. type_of ( item. owner_id ) . skip_binder ( ) . error_reported ( ) ?;
1820+ tcx. type_of ( item) . skip_binder ( ) . error_reported ( ) ?;
18211821 }
1822- kind => span_bug ! ( item . span , "cannot compute the variances of {kind:?}" ) ,
1822+ kind => span_bug ! ( tcx . def_span ( item ) , "cannot compute the variances of {kind:?}" ) ,
18231823 }
18241824
1825- let ty_predicates = tcx. predicates_of ( item. owner_id ) ;
1825+ let ty_predicates = tcx. predicates_of ( item) ;
18261826 assert_eq ! ( ty_predicates. parent, None ) ;
1827- let variances = tcx. variances_of ( item. owner_id ) ;
1827+ let variances = tcx. variances_of ( item) ;
18281828
18291829 let mut constrained_parameters: FxHashSet < _ > = variances
18301830 . iter ( )
@@ -1837,7 +1837,7 @@ fn check_variances_for_type_defn<'tcx>(
18371837
18381838 // Lazily calculated because it is only needed in case of an error.
18391839 let explicitly_bounded_params = LazyCell :: new ( || {
1840- let icx = crate :: collect:: ItemCtxt :: new ( tcx, item. owner_id . def_id ) ;
1840+ let icx = crate :: collect:: ItemCtxt :: new ( tcx, item) ;
18411841 hir_generics
18421842 . predicates
18431843 . iter ( )
@@ -1853,7 +1853,7 @@ fn check_variances_for_type_defn<'tcx>(
18531853 . collect :: < FxHashSet < _ > > ( )
18541854 } ) ;
18551855
1856- let ty_generics = tcx. generics_of ( item. owner_id ) ;
1856+ let ty_generics = tcx. generics_of ( item) ;
18571857
18581858 let mut res = Ok ( ( ) ) ;
18591859
@@ -1886,7 +1886,7 @@ fn check_variances_for_type_defn<'tcx>(
18861886 hir:: ParamName :: Error => { }
18871887 _ => {
18881888 let has_explicit_bounds = explicitly_bounded_params. contains ( & parameter) ;
1889- res = Err ( report_bivariance ( tcx, hir_param, has_explicit_bounds, item. kind ) ) ;
1889+ res = Err ( report_bivariance ( tcx, hir_param, has_explicit_bounds, item) ) ;
18901890 }
18911891 }
18921892 }
@@ -1897,12 +1897,12 @@ fn report_bivariance(
18971897 tcx : TyCtxt < ' _ > ,
18981898 param : & rustc_hir:: GenericParam < ' _ > ,
18991899 has_explicit_bounds : bool ,
1900- item_kind : ItemKind < ' _ > ,
1900+ item : LocalDefId ,
19011901) -> ErrorGuaranteed {
19021902 let param_name = param. name . ident ( ) ;
19031903
1904- let help = match item_kind {
1905- ItemKind :: Enum ( .. ) | ItemKind :: Struct ( .. ) | ItemKind :: Union ( .. ) => {
1904+ let help = match tcx . def_kind ( item ) {
1905+ DefKind :: Enum | DefKind :: Struct | DefKind :: Union => {
19061906 if let Some ( def_id) = tcx. lang_items ( ) . phantom_data ( ) {
19071907 errors:: UnusedGenericParameterHelp :: Adt {
19081908 param_name,
@@ -1912,7 +1912,7 @@ fn report_bivariance(
19121912 errors:: UnusedGenericParameterHelp :: AdtNoPhantomData { param_name }
19131913 }
19141914 }
1915- ItemKind :: TyAlias ( .. ) => errors:: UnusedGenericParameterHelp :: TyAlias { param_name } ,
1915+ DefKind :: TyAlias => errors:: UnusedGenericParameterHelp :: TyAlias { param_name } ,
19161916 item_kind => bug ! ( "report_bivariance: unexpected item kind: {item_kind:?}" ) ,
19171917 } ;
19181918
0 commit comments