@@ -390,6 +390,8 @@ pub struct ConstEvalErr {
390
390
pub enum ErrKind {
391
391
CannotCast ,
392
392
CannotCastTo ( & ' static str ) ,
393
+ InvalidOpForInts ( hir:: BinOp_ ) ,
394
+ InvalidOpForUInts ( hir:: BinOp_ ) ,
393
395
InvalidOpForBools ( hir:: BinOp_ ) ,
394
396
InvalidOpForFloats ( hir:: BinOp_ ) ,
395
397
InvalidOpForIntUint ( hir:: BinOp_ ) ,
@@ -428,6 +430,8 @@ impl ConstEvalErr {
428
430
match self . kind {
429
431
CannotCast => "can't cast this type" . into_cow ( ) ,
430
432
CannotCastTo ( s) => format ! ( "can't cast this type to {}" , s) . into_cow ( ) ,
433
+ InvalidOpForInts ( _) => "can't do this op on signed integrals" . into_cow ( ) ,
434
+ InvalidOpForUInts ( _) => "can't do this op on unsigned integrals" . into_cow ( ) ,
431
435
InvalidOpForBools ( _) => "can't do this op on bools" . into_cow ( ) ,
432
436
InvalidOpForFloats ( _) => "can't do this op on floats" . into_cow ( ) ,
433
437
InvalidOpForIntUint ( ..) => "can't do this op on an isize and usize" . into_cow ( ) ,
@@ -764,8 +768,6 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
764
768
e : & Expr ,
765
769
ty_hint : EvalHint < ' tcx > ,
766
770
fn_args : FnArgMap ) -> EvalResult {
767
- fn fromb ( b : bool ) -> ConstVal { Int ( b as i64 ) }
768
-
769
771
// Try to compute the type of the expression based on the EvalHint.
770
772
// (See also the definition of EvalHint, and the FIXME above EvalHint.)
771
773
let ety = match ty_hint {
@@ -837,13 +839,13 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
837
839
hir:: BiMul => Float ( a * b) ,
838
840
hir:: BiDiv => Float ( a / b) ,
839
841
hir:: BiRem => Float ( a % b) ,
840
- hir:: BiEq => fromb ( a == b) ,
841
- hir:: BiLt => fromb ( a < b) ,
842
- hir:: BiLe => fromb ( a <= b) ,
843
- hir:: BiNe => fromb ( a != b) ,
844
- hir:: BiGe => fromb ( a >= b) ,
845
- hir:: BiGt => fromb ( a > b) ,
846
- _ => signal ! ( e, InvalidOpForFloats ( op. node) )
842
+ hir:: BiEq => Bool ( a == b) ,
843
+ hir:: BiLt => Bool ( a < b) ,
844
+ hir:: BiLe => Bool ( a <= b) ,
845
+ hir:: BiNe => Bool ( a != b) ,
846
+ hir:: BiGe => Bool ( a >= b) ,
847
+ hir:: BiGt => Bool ( a > b) ,
848
+ _ => signal ! ( e, InvalidOpForFloats ( op. node) ) ,
847
849
}
848
850
}
849
851
( Int ( a) , Int ( b) ) => {
@@ -853,17 +855,18 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
853
855
hir:: BiMul => try!( const_int_checked_mul ( a, b, e, expr_int_type) ) ,
854
856
hir:: BiDiv => try!( const_int_checked_div ( a, b, e, expr_int_type) ) ,
855
857
hir:: BiRem => try!( const_int_checked_rem ( a, b, e, expr_int_type) ) ,
856
- hir:: BiAnd | hir :: BiBitAnd => Int ( a & b) ,
857
- hir:: BiOr | hir :: BiBitOr => Int ( a | b) ,
858
+ hir:: BiBitAnd => Int ( a & b) ,
859
+ hir:: BiBitOr => Int ( a | b) ,
858
860
hir:: BiBitXor => Int ( a ^ b) ,
859
861
hir:: BiShl => try!( const_int_checked_shl ( a, b, e, expr_int_type) ) ,
860
862
hir:: BiShr => try!( const_int_checked_shr ( a, b, e, expr_int_type) ) ,
861
- hir:: BiEq => fromb ( a == b) ,
862
- hir:: BiLt => fromb ( a < b) ,
863
- hir:: BiLe => fromb ( a <= b) ,
864
- hir:: BiNe => fromb ( a != b) ,
865
- hir:: BiGe => fromb ( a >= b) ,
866
- hir:: BiGt => fromb ( a > b)
863
+ hir:: BiEq => Bool ( a == b) ,
864
+ hir:: BiLt => Bool ( a < b) ,
865
+ hir:: BiLe => Bool ( a <= b) ,
866
+ hir:: BiNe => Bool ( a != b) ,
867
+ hir:: BiGe => Bool ( a >= b) ,
868
+ hir:: BiGt => Bool ( a > b) ,
869
+ _ => signal ! ( e, InvalidOpForInts ( op. node) ) ,
867
870
}
868
871
}
869
872
( Uint ( a) , Uint ( b) ) => {
@@ -873,17 +876,18 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
873
876
hir:: BiMul => try!( const_uint_checked_mul ( a, b, e, expr_uint_type) ) ,
874
877
hir:: BiDiv => try!( const_uint_checked_div ( a, b, e, expr_uint_type) ) ,
875
878
hir:: BiRem => try!( const_uint_checked_rem ( a, b, e, expr_uint_type) ) ,
876
- hir:: BiAnd | hir :: BiBitAnd => Uint ( a & b) ,
877
- hir:: BiOr | hir :: BiBitOr => Uint ( a | b) ,
879
+ hir:: BiBitAnd => Uint ( a & b) ,
880
+ hir:: BiBitOr => Uint ( a | b) ,
878
881
hir:: BiBitXor => Uint ( a ^ b) ,
879
882
hir:: BiShl => try!( const_uint_checked_shl ( a, b, e, expr_uint_type) ) ,
880
883
hir:: BiShr => try!( const_uint_checked_shr ( a, b, e, expr_uint_type) ) ,
881
- hir:: BiEq => fromb ( a == b) ,
882
- hir:: BiLt => fromb ( a < b) ,
883
- hir:: BiLe => fromb ( a <= b) ,
884
- hir:: BiNe => fromb ( a != b) ,
885
- hir:: BiGe => fromb ( a >= b) ,
886
- hir:: BiGt => fromb ( a > b) ,
884
+ hir:: BiEq => Bool ( a == b) ,
885
+ hir:: BiLt => Bool ( a < b) ,
886
+ hir:: BiLe => Bool ( a <= b) ,
887
+ hir:: BiNe => Bool ( a != b) ,
888
+ hir:: BiGe => Bool ( a >= b) ,
889
+ hir:: BiGt => Bool ( a > b) ,
890
+ _ => signal ! ( e, InvalidOpForUInts ( op. node) ) ,
887
891
}
888
892
}
889
893
// shifts can have any integral type as their rhs
0 commit comments