This commit is contained in:
Oliver Schneider 2016-02-15 17:00:06 +01:00
parent e809eb61d7
commit cf536d7a4f
3 changed files with 11 additions and 11 deletions

View file

@ -15,16 +15,16 @@ use syntax::ptr::P;
#[derive(Debug, Copy, Clone)]
pub enum FloatWidth {
Fw32,
Fw64,
FwAny,
F32,
F64,
Any,
}
impl From<FloatTy> for FloatWidth {
fn from(ty: FloatTy) -> FloatWidth {
match ty {
FloatTy::F32 => FloatWidth::Fw32,
FloatTy::F64 => FloatWidth::Fw64,
FloatTy::F32 => FloatWidth::F32,
FloatTy::F64 => FloatWidth::F64,
}
}
}
@ -200,7 +200,7 @@ fn lit_to_constant(lit: &LitKind) -> Constant {
LitKind::Char(c) => Constant::Char(c),
LitKind::Int(value, ty) => Constant::Int(value, ty, Sign::Plus),
LitKind::Float(ref is, ty) => Constant::Float(is.to_string(), ty.into()),
LitKind::FloatUnsuffixed(ref is) => Constant::Float(is.to_string(), FloatWidth::FwAny),
LitKind::FloatUnsuffixed(ref is) => Constant::Float(is.to_string(), FloatWidth::Any),
LitKind::Bool(b) => Constant::Bool(b),
}
}

View file

@ -47,8 +47,8 @@ impl LateLintPass for ZeroDivZeroPass {
// since we're about to suggest a use of std::f32::NaN or std::f64::NaN,
// match the precision of the literals that are given.
let float_type = match (lhs_width, rhs_width) {
(FloatWidth::Fw64, _)
| (_, FloatWidth::Fw64) => "f64",
(FloatWidth::F64, _)
| (_, FloatWidth::F64) => "f64",
_ => "f32"
};
span_help_and_lint(cx, ZERO_DIVIDED_BY_ZERO, expr.span,

View file

@ -77,9 +77,9 @@ fn test_ops() {
check(ONE, &binop(BiMul, litone.clone(), litone.clone()));
check(ONE, &binop(BiDiv, litone.clone(), litone.clone()));
let half_any = Constant::Float("0.5".into(), FloatWidth::FwAny);
let half32 = Constant::Float("0.5".into(), FloatWidth::Fw32);
let half64 = Constant::Float("0.5".into(), FloatWidth::Fw64);
let half_any = Constant::Float("0.5".into(), FloatWidth::Any);
let half32 = Constant::Float("0.5".into(), FloatWidth::F32);
let half64 = Constant::Float("0.5".into(), FloatWidth::F64);
assert_eq!(half_any, half32);
assert_eq!(half_any, half64);