@@ -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 , _) => {
@@ -1076,7 +1076,12 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> {
10761076 }
10771077}
10781078
1079- pub fn compare_const_vals ( a : & ConstVal , b : & ConstVal , ty : Ty ) -> Option < Ordering > {
1079+ pub fn compare_const_vals < ' a , ' tcx > (
1080+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1081+ a : & ConstVal ,
1082+ b : & ConstVal ,
1083+ ty : Ty < ' tcx > ,
1084+ ) -> Option < Ordering > {
10801085 use rustc_const_math:: ConstFloat ;
10811086 trace ! ( "compare_const_vals: {:?}, {:?}" , a, b) ;
10821087 use rustc:: mir:: interpret:: { Value , PrimVal } ;
@@ -1096,7 +1101,11 @@ pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option<Ordering
10961101 // FIXME(oli-obk): report cmp errors?
10971102 l. try_cmp ( r) . ok ( )
10981103 } ,
1099- ty:: TyInt ( _) => Some ( ( a as i128 ) . cmp ( & ( b as i128 ) ) ) ,
1104+ ty:: TyInt ( _) => {
1105+ let a = interpret:: sign_extend ( tcx, a, ty) . expect ( "layout error for TyInt" ) ;
1106+ let b = interpret:: sign_extend ( tcx, b, ty) . expect ( "layout error for TyInt" ) ;
1107+ Some ( ( a as i128 ) . cmp ( & ( b as i128 ) ) )
1108+ } ,
11001109 _ => Some ( a. cmp ( & b) ) ,
11011110 }
11021111 } ,
0 commit comments