@@ -1802,8 +1802,8 @@ fn receiver_is_implemented<'tcx>(
18021802pub fn check_variances_for_type_defn < ' tcx > (
18031803 tcx : TyCtxt < ' tcx > ,
18041804 item : LocalDefId ,
1805- variances : & [ ty:: Variance ] ,
1806- ) -> Result < ( ) , ErrorGuaranteed > {
1805+ variances : & ' tcx [ ty:: Variance ] ,
1806+ ) -> Result < & ' tcx [ ty :: Variance ] , ErrorGuaranteed > {
18071807 let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item) ;
18081808
18091809 match tcx. def_kind ( item) {
@@ -1819,7 +1819,7 @@ pub fn check_variances_for_type_defn<'tcx>(
18191819 ) ;
18201820 tcx. type_of ( item) . skip_binder ( ) . error_reported ( ) ?;
18211821 }
1822- _ => return Ok ( ( ) ) ,
1822+ _ => return Ok ( variances ) ,
18231823 }
18241824
18251825 let ty_predicates = tcx. predicates_of ( item) ;
@@ -1856,7 +1856,7 @@ pub fn check_variances_for_type_defn<'tcx>(
18561856
18571857 let ty_generics = tcx. generics_of ( item) ;
18581858
1859- let mut res = Ok ( ( ) ) ;
1859+ let mut variances = variances ;
18601860
18611861 for ( index, _) in variances. iter ( ) . enumerate ( ) {
18621862 let parameter = Parameter ( index as u32 ) ;
@@ -1868,30 +1868,30 @@ pub fn check_variances_for_type_defn<'tcx>(
18681868 let ty_param = & ty_generics. own_params [ index] ;
18691869 let hir_param = & hir_generics. params [ index] ;
18701870
1871- if ty_param. def_id != hir_param. def_id . into ( ) {
1871+ let guar = if ty_param. def_id != hir_param. def_id . into ( ) {
18721872 // Valid programs always have lifetimes before types in the generic parameter list.
18731873 // ty_generics are normalized to be in this required order, and variances are built
18741874 // from ty generics, not from hir generics. but we need hir generics to get
18751875 // a span out.
18761876 //
18771877 // If they aren't in the same order, then the user has written invalid code, and already
18781878 // 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+ }
18911888 }
1892- }
1889+ } ;
1890+ let mut v = variances. to_vec ( ) ;
1891+ v[ index] = ty:: Variance :: Errvariant ( guar) ;
1892+ variances = tcx. arena . alloc_slice ( & v) ;
18931893 }
1894- res
1894+ Ok ( variances )
18951895}
18961896
18971897fn report_bivariance (
0 commit comments