@@ -1755,20 +1755,36 @@ fn check_variances_for_type_defn<'tcx>(
17551755 . collect :: < FxHashSet < _ > > ( )
17561756 } ) ;
17571757
1758+ let ty_generics = tcx. generics_of ( item. owner_id ) ;
1759+
17581760 for ( index, _) in variances. iter ( ) . enumerate ( ) {
17591761 let parameter = Parameter ( index as u32 ) ;
17601762
17611763 if constrained_parameters. contains ( & parameter) {
17621764 continue ;
17631765 }
17641766
1765- let param = & hir_generics. params [ index] ;
1767+ let ty_param = & ty_generics. params [ index] ;
1768+ let hir_param = & hir_generics. params [ index] ;
1769+
1770+ if ty_param. def_id != hir_param. def_id . into ( ) {
1771+ // valid programs always have lifetimes before types in the generic parameter list
1772+ // ty_generics are normalized to be in this required order, and variances are built
1773+ // from ty generics, not from hir generics. but we need hir generics to get
1774+ // a span out
1775+ //
1776+ // if they aren't in the same order, then the user has written invalid code, and already
1777+ // got an error about it (or I'm wrong about this)
1778+ tcx. sess
1779+ . delay_span_bug ( hir_param. span , "hir generics and ty generics in different order" ) ;
1780+ continue ;
1781+ }
17661782
1767- match param . name {
1783+ match hir_param . name {
17681784 hir:: ParamName :: Error => { }
17691785 _ => {
17701786 let has_explicit_bounds = explicitly_bounded_params. contains ( & parameter) ;
1771- report_bivariance ( tcx, param , has_explicit_bounds) ;
1787+ report_bivariance ( tcx, hir_param , has_explicit_bounds) ;
17721788 }
17731789 }
17741790 }
0 commit comments