@@ -1802,8 +1802,8 @@ fn receiver_is_implemented<'tcx>(
1802
1802
pub fn check_variances_for_type_defn < ' tcx > (
1803
1803
tcx : TyCtxt < ' tcx > ,
1804
1804
item : LocalDefId ,
1805
- variances : & [ ty:: Variance ] ,
1806
- ) -> Result < ( ) , ErrorGuaranteed > {
1805
+ variances : & ' tcx [ ty:: Variance ] ,
1806
+ ) -> Result < & ' tcx [ ty :: Variance ] , ErrorGuaranteed > {
1807
1807
let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item) ;
1808
1808
1809
1809
match tcx. def_kind ( item) {
@@ -1819,7 +1819,7 @@ pub fn check_variances_for_type_defn<'tcx>(
1819
1819
) ;
1820
1820
tcx. type_of ( item) . skip_binder ( ) . error_reported ( ) ?;
1821
1821
}
1822
- _ => return Ok ( ( ) ) ,
1822
+ _ => return Ok ( variances ) ,
1823
1823
}
1824
1824
1825
1825
let ty_predicates = tcx. predicates_of ( item) ;
@@ -1856,7 +1856,7 @@ pub fn check_variances_for_type_defn<'tcx>(
1856
1856
1857
1857
let ty_generics = tcx. generics_of ( item) ;
1858
1858
1859
- let mut res = Ok ( ( ) ) ;
1859
+ let mut variances = variances ;
1860
1860
1861
1861
for ( index, _) in variances. iter ( ) . enumerate ( ) {
1862
1862
let parameter = Parameter ( index as u32 ) ;
@@ -1868,30 +1868,30 @@ pub fn check_variances_for_type_defn<'tcx>(
1868
1868
let ty_param = & ty_generics. own_params [ index] ;
1869
1869
let hir_param = & hir_generics. params [ index] ;
1870
1870
1871
- if ty_param. def_id != hir_param. def_id . into ( ) {
1871
+ let guar = if ty_param. def_id != hir_param. def_id . into ( ) {
1872
1872
// Valid programs always have lifetimes before types in the generic parameter list.
1873
1873
// ty_generics are normalized to be in this required order, and variances are built
1874
1874
// from ty generics, not from hir generics. but we need hir generics to get
1875
1875
// a span out.
1876
1876
//
1877
1877
// If they aren't in the same order, then the user has written invalid code, and already
1878
1878
// got an error about it (or I'm wrong about this).
1879
- tcx. dcx ( ) . span_delayed_bug (
1880
- hir_param. span ,
1881
- "hir generics and ty generics in different order" ,
1882
- ) ;
1883
- continue ;
1884
- }
1885
-
1886
- match hir_param. name {
1887
- hir:: ParamName :: Error ( guar) => res = Err ( guar) ,
1888
- _ => {
1889
- let has_explicit_bounds = explicitly_bounded_params. contains ( & parameter) ;
1890
- res = Err ( report_bivariance ( tcx, hir_param, has_explicit_bounds, item) ) ;
1879
+ tcx. dcx ( )
1880
+ . span_delayed_bug ( hir_param. span , "hir generics and ty generics in different order" )
1881
+ } else {
1882
+ match hir_param. name {
1883
+ hir:: ParamName :: Error ( guar) => guar,
1884
+ _ => {
1885
+ let has_explicit_bounds = explicitly_bounded_params. contains ( & parameter) ;
1886
+ report_bivariance ( tcx, hir_param, has_explicit_bounds, item)
1887
+ }
1891
1888
}
1892
- }
1889
+ } ;
1890
+ let mut v = variances. to_vec ( ) ;
1891
+ v[ index] = ty:: Variance :: Errvariant ( guar) ;
1892
+ variances = tcx. arena . alloc_slice ( & v) ;
1893
1893
}
1894
- res
1894
+ Ok ( variances )
1895
1895
}
1896
1896
1897
1897
fn report_bivariance (
0 commit comments