Remove unsafe from consts clippy lints

This commit is contained in:
Konrad Borowski 2018-12-29 00:40:48 +01:00
parent 3c4abb5b80
commit 44bf8e0c3d
1 changed files with 6 additions and 7 deletions

View File

@ -23,7 +23,6 @@ use std::cmp::Ordering::{self, Equal};
use std::cmp::PartialOrd;
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::mem;
use std::rc::Rc;
/// A `LitKind`-like enum to fold constant `Expr`s into.
@ -61,14 +60,14 @@ impl PartialEq for Constant {
(&Constant::F64(l), &Constant::F64(r)) => {
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
// `Fw32 == Fw64` so dont compare them
// mem::transmute is required to catch non-matching 0.0, -0.0, and NaNs
unsafe { mem::transmute::<f64, u64>(l) == mem::transmute::<f64, u64>(r) }
// to_bits is required to catch non-matching 0.0, -0.0, and NaNs
l.to_bits() == r.to_bits()
},
(&Constant::F32(l), &Constant::F32(r)) => {
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
// `Fw32 == Fw64` so dont compare them
// mem::transmute is required to catch non-matching 0.0, -0.0, and NaNs
unsafe { mem::transmute::<f64, u64>(f64::from(l)) == mem::transmute::<f64, u64>(f64::from(r)) }
// to_bits is required to catch non-matching 0.0, -0.0, and NaNs
f64::from(l).to_bits() == f64::from(r).to_bits()
},
(&Constant::Bool(l), &Constant::Bool(r)) => l == r,
(&Constant::Vec(ref l), &Constant::Vec(ref r)) | (&Constant::Tuple(ref l), &Constant::Tuple(ref r)) => {
@ -99,10 +98,10 @@ impl Hash for Constant {
i.hash(state);
},
Constant::F32(f) => {
unsafe { mem::transmute::<f64, u64>(f64::from(f)) }.hash(state);
f64::from(f).to_bits().hash(state);
},
Constant::F64(f) => {
unsafe { mem::transmute::<f64, u64>(f) }.hash(state);
f.to_bits().hash(state);
},
Constant::Bool(b) => {
b.hash(state);