@@ -16,7 +16,7 @@ mod check_match;
1616pub use self :: check_match:: check_crate;
1717pub ( crate ) use self :: check_match:: check_match;
1818
19- use interpret:: { const_val_field, const_discr} ;
19+ use interpret:: { const_val_field, const_discr, self } ;
2020
2121use rustc:: middle:: const_val:: ConstVal ;
2222use rustc:: mir:: { Field , BorrowKind , Mutability } ;
@@ -372,7 +372,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
372372 ( PatternKind :: Constant { value : lo } ,
373373 PatternKind :: Constant { value : hi } ) => {
374374 use std:: cmp:: Ordering ;
375- match ( end, compare_const_vals ( & lo. val , & hi. val , ty) . unwrap ( ) ) {
375+ match ( end, compare_const_vals ( self . tcx , & lo. val , & hi. val , ty) . unwrap ( ) ) {
376376 ( RangeEnd :: Excluded , Ordering :: Less ) =>
377377 PatternKind :: Range { lo, hi, end } ,
378378 ( RangeEnd :: Excluded , _) => {
@@ -1092,7 +1092,12 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> {
10921092 }
10931093}
10941094
1095- pub fn compare_const_vals ( a : & ConstVal , b : & ConstVal , ty : Ty ) -> Option < Ordering > {
1095+ pub fn compare_const_vals < ' a , ' tcx > (
1096+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1097+ a : & ConstVal ,
1098+ b : & ConstVal ,
1099+ ty : Ty < ' tcx > ,
1100+ ) -> Option < Ordering > {
10961101 use rustc_const_math:: ConstFloat ;
10971102 trace ! ( "compare_const_vals: {:?}, {:?}" , a, b) ;
10981103 use rustc:: mir:: interpret:: { Value , PrimVal } ;
@@ -1112,7 +1117,11 @@ pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option<Ordering
11121117 // FIXME(oli-obk): report cmp errors?
11131118 l. try_cmp ( r) . ok ( )
11141119 } ,
1115- ty:: TyInt ( _) => Some ( ( a as i128 ) . cmp ( & ( b as i128 ) ) ) ,
1120+ ty:: TyInt ( _) => {
1121+ let a = interpret:: sign_extend ( tcx, a, ty) . expect ( "layout error for TyInt" ) ;
1122+ let b = interpret:: sign_extend ( tcx, b, ty) . expect ( "layout error for TyInt" ) ;
1123+ Some ( ( a as i128 ) . cmp ( & ( b as i128 ) ) )
1124+ } ,
11161125 _ => Some ( a. cmp ( & b) ) ,
11171126 }
11181127 } ,
0 commit comments