@@ -1755,20 +1755,36 @@ fn check_variances_for_type_defn<'tcx>(
1755
1755
. collect :: < FxHashSet < _ > > ( )
1756
1756
} ) ;
1757
1757
1758
+ let ty_generics = tcx. generics_of ( item. owner_id ) ;
1759
+
1758
1760
for ( index, _) in variances. iter ( ) . enumerate ( ) {
1759
1761
let parameter = Parameter ( index as u32 ) ;
1760
1762
1761
1763
if constrained_parameters. contains ( & parameter) {
1762
1764
continue ;
1763
1765
}
1764
1766
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
+ }
1766
1782
1767
- match param . name {
1783
+ match hir_param . name {
1768
1784
hir:: ParamName :: Error => { }
1769
1785
_ => {
1770
1786
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) ;
1772
1788
}
1773
1789
}
1774
1790
}
0 commit comments