Also handle ConstFloat::F32 in is_allowed

This commit is contained in:
Enrico Schmitz 2017-03-01 15:33:32 +01:00 committed by Enrico Schmitz
parent 7ba3a713a1
commit 0cf7990e72

View File

@ -362,16 +362,28 @@ fn is_allowed(cx: &LateContext, expr: &Expr) -> bool {
let res = ConstContext::with_tables(cx.tcx, cx.tables).eval(expr);
if let Ok(ConstVal::Float(val)) = res {
use std::cmp::Ordering;
match val {
val @ ConstFloat::F32(_) => {
let zero = ConstFloat::F32(0.0);
let zero = ConstFloat::F64(0.0);
let infinity = ConstFloat::F32(::std::f32::INFINITY);
let infinity = ConstFloat::F64(::std::f64::INFINITY);
let neg_infinity = ConstFloat::F32(::std::f32::NEG_INFINITY);
val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal) ||
val.try_cmp(neg_infinity) == Ok(Ordering::Equal)
},
val @ ConstFloat::F64(_) => {
let zero = ConstFloat::F64(0.0);
let neg_infinity = ConstFloat::F64(::std::f64::NEG_INFINITY);
let infinity = ConstFloat::F64(::std::f64::INFINITY);
val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal) ||
val.try_cmp(neg_infinity) == Ok(Ordering::Equal)
let neg_infinity = ConstFloat::F64(::std::f64::NEG_INFINITY);
val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal) ||
val.try_cmp(neg_infinity) == Ok(Ordering::Equal)
}
}
} else {
false
}