@@ -16,7 +16,7 @@ mod check_match;
16
16
pub use self :: check_match:: check_crate;
17
17
pub ( crate ) use self :: check_match:: check_match;
18
18
19
- use interpret:: { const_val_field, const_discr} ;
19
+ use interpret:: { const_val_field, const_discr, self } ;
20
20
21
21
use rustc:: middle:: const_val:: ConstVal ;
22
22
use rustc:: mir:: { Field , BorrowKind , Mutability } ;
@@ -372,7 +372,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
372
372
( PatternKind :: Constant { value : lo } ,
373
373
PatternKind :: Constant { value : hi } ) => {
374
374
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 ( ) ) {
376
376
( RangeEnd :: Excluded , Ordering :: Less ) =>
377
377
PatternKind :: Range { lo, hi, end } ,
378
378
( RangeEnd :: Excluded , _) => {
@@ -1092,7 +1092,12 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> {
1092
1092
}
1093
1093
}
1094
1094
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 > {
1096
1101
use rustc_const_math:: ConstFloat ;
1097
1102
trace ! ( "compare_const_vals: {:?}, {:?}" , a, b) ;
1098
1103
use rustc:: mir:: interpret:: { Value , PrimVal } ;
@@ -1112,7 +1117,11 @@ pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option<Ordering
1112
1117
// FIXME(oli-obk): report cmp errors?
1113
1118
l. try_cmp ( r) . ok ( )
1114
1119
} ,
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
+ } ,
1116
1125
_ => Some ( a. cmp ( & b) ) ,
1117
1126
}
1118
1127
} ,
0 commit comments