@@ -308,21 +308,12 @@ 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) => {
312
- let res = check_type_defn ( tcx, item, false ) ;
313
- check_variances_for_type_defn ( tcx, item, hir_generics) ;
314
- res
315
- }
316
- hir:: ItemKind :: Union ( _, hir_generics) => {
317
- let res = check_type_defn ( tcx, item, true ) ;
318
- check_variances_for_type_defn ( tcx, item, hir_generics) ;
319
- res
320
- }
321
- hir:: ItemKind :: Enum ( _, hir_generics) => {
322
- let res = check_type_defn ( tcx, item, true ) ;
323
- check_variances_for_type_defn ( tcx, item, hir_generics) ;
324
- res
325
- }
311
+ hir:: ItemKind :: Struct ( _, hir_generics) => check_type_defn ( tcx, item, false )
312
+ . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
313
+ hir:: ItemKind :: Union ( _, hir_generics) => check_type_defn ( tcx, item, true )
314
+ . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
315
+ hir:: ItemKind :: Enum ( _, hir_generics) => check_type_defn ( tcx, item, true )
316
+ . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
326
317
hir:: ItemKind :: Trait ( ..) => check_trait ( tcx, item) ,
327
318
hir:: ItemKind :: TraitAlias ( ..) => check_trait ( tcx, item) ,
328
319
// `ForeignItem`s are handled separately.
@@ -331,9 +322,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
331
322
if tcx. type_alias_is_lazy ( item. owner_id ) {
332
323
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
333
324
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
334
- let res = check_item_type ( tcx, def_id, hir_ty. span , UnsizedHandling :: Allow ) ;
335
- check_variances_for_type_defn ( tcx, item, hir_generics) ;
336
- res
325
+ check_item_type ( tcx, def_id, hir_ty. span , UnsizedHandling :: Allow )
326
+ . and ( check_variances_for_type_defn ( tcx, item, hir_generics) )
337
327
} else {
338
328
Ok ( ( ) )
339
329
}
@@ -1813,25 +1803,21 @@ fn check_variances_for_type_defn<'tcx>(
1813
1803
tcx : TyCtxt < ' tcx > ,
1814
1804
item : & hir:: Item < ' tcx > ,
1815
1805
hir_generics : & hir:: Generics < ' tcx > ,
1816
- ) {
1806
+ ) -> Result < ( ) , ErrorGuaranteed > {
1817
1807
let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item. owner_id ) ;
1818
1808
1819
1809
match item. kind {
1820
1810
ItemKind :: Enum ( ..) | ItemKind :: Struct ( ..) | ItemKind :: Union ( ..) => {
1821
1811
for field in tcx. adt_def ( item. owner_id ) . all_fields ( ) {
1822
- if field. ty ( tcx, identity_args) . references_error ( ) {
1823
- return ;
1824
- }
1812
+ field. ty ( tcx, identity_args) . error_reported ( ) ?;
1825
1813
}
1826
1814
}
1827
1815
ItemKind :: TyAlias ( ..) => {
1828
1816
assert ! (
1829
1817
tcx. type_alias_is_lazy( item. owner_id) ,
1830
1818
"should not be computing variance of non-weak type alias"
1831
1819
) ;
1832
- if tcx. type_of ( item. owner_id ) . skip_binder ( ) . references_error ( ) {
1833
- return ;
1834
- }
1820
+ tcx. type_of ( item. owner_id ) . skip_binder ( ) . error_reported ( ) ?;
1835
1821
}
1836
1822
kind => span_bug ! ( item. span, "cannot compute the variances of {kind:?}" ) ,
1837
1823
}
@@ -1869,6 +1855,8 @@ fn check_variances_for_type_defn<'tcx>(
1869
1855
1870
1856
let ty_generics = tcx. generics_of ( item. owner_id ) ;
1871
1857
1858
+ let mut res = Ok ( ( ) ) ;
1859
+
1872
1860
for ( index, _) in variances. iter ( ) . enumerate ( ) {
1873
1861
let parameter = Parameter ( index as u32 ) ;
1874
1862
@@ -1895,13 +1883,14 @@ fn check_variances_for_type_defn<'tcx>(
1895
1883
}
1896
1884
1897
1885
match hir_param. name {
1898
- hir:: ParamName :: Error ( _guar ) => { }
1886
+ hir:: ParamName :: Error ( guar ) => res = Err ( guar ) ,
1899
1887
_ => {
1900
1888
let has_explicit_bounds = explicitly_bounded_params. contains ( & parameter) ;
1901
- report_bivariance ( tcx, hir_param, has_explicit_bounds, item. kind ) ;
1889
+ res = Err ( report_bivariance ( tcx, hir_param, has_explicit_bounds, item. kind ) ) ;
1902
1890
}
1903
1891
}
1904
1892
}
1893
+ res
1905
1894
}
1906
1895
1907
1896
fn report_bivariance (
0 commit comments