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)] #[derive(Debug, Copy, Clone)]
pub enum FloatWidth { pub enum FloatWidth {
Fw32, F32,
Fw64, F64,
FwAny, Any,
} }
impl From<FloatTy> for FloatWidth { impl From<FloatTy> for FloatWidth {
fn from(ty: FloatTy) -> FloatWidth { fn from(ty: FloatTy) -> FloatWidth {
match ty { match ty {
FloatTy::F32 => FloatWidth::Fw32, FloatTy::F32 => FloatWidth::F32,
FloatTy::F64 => FloatWidth::Fw64, FloatTy::F64 => FloatWidth::F64,
} }
} }
} }
@ -200,7 +200,7 @@ fn lit_to_constant(lit: &LitKind) -> Constant {
LitKind::Char(c) => Constant::Char(c), LitKind::Char(c) => Constant::Char(c),
LitKind::Int(value, ty) => Constant::Int(value, ty, Sign::Plus), LitKind::Int(value, ty) => Constant::Int(value, ty, Sign::Plus),
LitKind::Float(ref is, ty) => Constant::Float(is.to_string(), ty.into()), 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), 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, // 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. // match the precision of the literals that are given.
let float_type = match (lhs_width, rhs_width) { let float_type = match (lhs_width, rhs_width) {
(FloatWidth::Fw64, _) (FloatWidth::F64, _)
| (_, FloatWidth::Fw64) => "f64", | (_, FloatWidth::F64) => "f64",
_ => "f32" _ => "f32"
}; };
span_help_and_lint(cx, ZERO_DIVIDED_BY_ZERO, expr.span, 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(BiMul, litone.clone(), litone.clone()));
check(ONE, &binop(BiDiv, litone.clone(), litone.clone())); check(ONE, &binop(BiDiv, litone.clone(), litone.clone()));
let half_any = Constant::Float("0.5".into(), FloatWidth::FwAny); let half_any = Constant::Float("0.5".into(), FloatWidth::Any);
let half32 = Constant::Float("0.5".into(), FloatWidth::Fw32); let half32 = Constant::Float("0.5".into(), FloatWidth::F32);
let half64 = Constant::Float("0.5".into(), FloatWidth::Fw64); let half64 = Constant::Float("0.5".into(), FloatWidth::F64);
assert_eq!(half_any, half32); assert_eq!(half_any, half32);
assert_eq!(half_any, half64); assert_eq!(half_any, half64);