@@ -308,22 +308,21 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
308308 hir:: ItemKind :: Const ( ty, ..) => {
309309 check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
310310 }
311- hir:: ItemKind :: Struct ( _, hir_generics) => check_type_defn ( tcx, item, false )
312- . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
313- hir:: ItemKind :: Union ( _, hir_generics) => check_type_defn ( tcx, item, true )
314- . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
315- hir:: ItemKind :: Enum ( _, hir_generics) => check_type_defn ( tcx, item, true )
316- . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
311+ hir:: ItemKind :: Struct ( ..) => check_type_defn ( tcx, item, false ) ,
312+ hir:: ItemKind :: Union ( ..) => check_type_defn ( tcx, item, true ) ,
313+ hir:: ItemKind :: Enum ( ..) => check_type_defn ( tcx, item, true ) ,
314+
317315 hir:: ItemKind :: Trait ( ..) => check_trait ( tcx, item) ,
318316 hir:: ItemKind :: TraitAlias ( ..) => check_trait ( tcx, item) ,
319317 // `ForeignItem`s are handled separately.
320318 hir:: ItemKind :: ForeignMod { .. } => Ok ( ( ) ) ,
321- hir:: ItemKind :: TyAlias ( hir_ty, hir_generics ) => {
319+ hir:: ItemKind :: TyAlias ( hir_ty, .. ) => {
322320 if tcx. type_alias_is_lazy ( item. owner_id ) {
323321 // Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
324322 // E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
325- check_item_type ( tcx, def_id, hir_ty. span , UnsizedHandling :: Allow )
326- . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) )
323+ let res = check_item_type ( tcx, def_id, hir_ty. span , UnsizedHandling :: Allow ) ;
324+ let _ = tcx. variances_of ( def_id) ;
325+ res
327326 } else {
328327 Ok ( ( ) )
329328 }
@@ -1062,6 +1061,7 @@ fn check_type_defn<'tcx>(
10621061 all_sized : bool ,
10631062) -> Result < ( ) , ErrorGuaranteed > {
10641063 let _ = tcx. representability ( item. owner_id . def_id ) ;
1064+ let _ = tcx. variances_of ( item. owner_id . def_id ) ;
10651065 let adt_def = tcx. adt_def ( item. owner_id ) ;
10661066
10671067 enter_wf_checking_ctxt ( tcx, item. span , item. owner_id . def_id , |wfcx| {
@@ -1799,10 +1799,10 @@ fn receiver_is_implemented<'tcx>(
17991799 }
18001800}
18011801
1802- fn check_variances_for_type_defn < ' tcx > (
1802+ pub fn check_variances_for_type_defn < ' tcx > (
18031803 tcx : TyCtxt < ' tcx > ,
18041804 item : LocalDefId ,
1805- hir_generics : & hir :: Generics < ' tcx > ,
1805+ variances : & [ ty :: Variance ] ,
18061806) -> Result < ( ) , ErrorGuaranteed > {
18071807 let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item) ;
18081808
@@ -1819,12 +1819,11 @@ fn check_variances_for_type_defn<'tcx>(
18191819 ) ;
18201820 tcx. type_of ( item) . skip_binder ( ) . error_reported ( ) ?;
18211821 }
1822- kind => span_bug ! ( tcx . def_span ( item ) , "cannot compute the variances of {kind:?}" ) ,
1822+ _ => return Ok ( ( ) ) ,
18231823 }
18241824
18251825 let ty_predicates = tcx. predicates_of ( item) ;
18261826 assert_eq ! ( ty_predicates. parent, None ) ;
1827- let variances = tcx. variances_of ( item) ;
18281827
18291828 let mut constrained_parameters: FxHashSet < _ > = variances
18301829 . iter ( )
@@ -1835,6 +1834,8 @@ fn check_variances_for_type_defn<'tcx>(
18351834
18361835 identify_constrained_generic_params ( tcx, ty_predicates, None , & mut constrained_parameters) ;
18371836
1837+ let hir_generics = tcx. hir_node_by_def_id ( item) . generics ( ) . unwrap ( ) ;
1838+
18381839 // Lazily calculated because it is only needed in case of an error.
18391840 let explicitly_bounded_params = LazyCell :: new ( || {
18401841 let icx = crate :: collect:: ItemCtxt :: new ( tcx, item) ;
0 commit comments