@@ -308,22 +308,21 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
308
308
hir:: ItemKind :: Const ( ty, ..) => {
309
309
check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
310
310
}
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
+
317
315
hir:: ItemKind :: Trait ( ..) => check_trait ( tcx, item) ,
318
316
hir:: ItemKind :: TraitAlias ( ..) => check_trait ( tcx, item) ,
319
317
// `ForeignItem`s are handled separately.
320
318
hir:: ItemKind :: ForeignMod { .. } => Ok ( ( ) ) ,
321
- hir:: ItemKind :: TyAlias ( hir_ty, hir_generics ) => {
319
+ hir:: ItemKind :: TyAlias ( hir_ty, .. ) => {
322
320
if tcx. type_alias_is_lazy ( item. owner_id ) {
323
321
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
324
322
// 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
327
326
} else {
328
327
Ok ( ( ) )
329
328
}
@@ -1062,6 +1061,7 @@ fn check_type_defn<'tcx>(
1062
1061
all_sized : bool ,
1063
1062
) -> Result < ( ) , ErrorGuaranteed > {
1064
1063
let _ = tcx. representability ( item. owner_id . def_id ) ;
1064
+ let _ = tcx. variances_of ( item. owner_id . def_id ) ;
1065
1065
let adt_def = tcx. adt_def ( item. owner_id ) ;
1066
1066
1067
1067
enter_wf_checking_ctxt ( tcx, item. span , item. owner_id . def_id , |wfcx| {
@@ -1799,10 +1799,10 @@ fn receiver_is_implemented<'tcx>(
1799
1799
}
1800
1800
}
1801
1801
1802
- fn check_variances_for_type_defn < ' tcx > (
1802
+ pub fn check_variances_for_type_defn < ' tcx > (
1803
1803
tcx : TyCtxt < ' tcx > ,
1804
1804
item : LocalDefId ,
1805
- hir_generics : & hir :: Generics < ' tcx > ,
1805
+ variances : & [ ty :: Variance ] ,
1806
1806
) -> Result < ( ) , ErrorGuaranteed > {
1807
1807
let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item) ;
1808
1808
@@ -1819,12 +1819,11 @@ fn check_variances_for_type_defn<'tcx>(
1819
1819
) ;
1820
1820
tcx. type_of ( item) . skip_binder ( ) . error_reported ( ) ?;
1821
1821
}
1822
- kind => span_bug ! ( tcx . def_span ( item ) , "cannot compute the variances of {kind:?}" ) ,
1822
+ _ => return Ok ( ( ) ) ,
1823
1823
}
1824
1824
1825
1825
let ty_predicates = tcx. predicates_of ( item) ;
1826
1826
assert_eq ! ( ty_predicates. parent, None ) ;
1827
- let variances = tcx. variances_of ( item) ;
1828
1827
1829
1828
let mut constrained_parameters: FxHashSet < _ > = variances
1830
1829
. iter ( )
@@ -1835,6 +1834,8 @@ fn check_variances_for_type_defn<'tcx>(
1835
1834
1836
1835
identify_constrained_generic_params ( tcx, ty_predicates, None , & mut constrained_parameters) ;
1837
1836
1837
+ let hir_generics = tcx. hir_node_by_def_id ( item) . generics ( ) . unwrap ( ) ;
1838
+
1838
1839
// Lazily calculated because it is only needed in case of an error.
1839
1840
let explicitly_bounded_params = LazyCell :: new ( || {
1840
1841
let icx = crate :: collect:: ItemCtxt :: new ( tcx, item) ;
0 commit comments