Skip to content

Commit c937024

Browse files
committed
Auto merge of #3592 - xfix:remove-unsafe-from-consts-clippy-lints, r=flip1995
Remove unsafe from consts clippy lints
2 parents 3c4abb5 + 44bf8e0 commit c937024

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

clippy_lints/src/consts.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::cmp::Ordering::{self, Equal};
2323
use std::cmp::PartialOrd;
2424
use std::convert::TryInto;
2525
use std::hash::{Hash, Hasher};
26-
use std::mem;
2726
use std::rc::Rc;
2827

2928
/// A `LitKind`-like enum to fold constant `Expr`s into.
@@ -61,14 +60,14 @@ impl PartialEq for Constant {
6160
(&Constant::F64(l), &Constant::F64(r)) => {
6261
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
6362
// `Fw32 == Fw64` so don’t compare them
64-
// mem::transmute is required to catch non-matching 0.0, -0.0, and NaNs
65-
unsafe { mem::transmute::<f64, u64>(l) == mem::transmute::<f64, u64>(r) }
63+
// to_bits is required to catch non-matching 0.0, -0.0, and NaNs
64+
l.to_bits() == r.to_bits()
6665
},
6766
(&Constant::F32(l), &Constant::F32(r)) => {
6867
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
6968
// `Fw32 == Fw64` so don’t compare them
70-
// mem::transmute is required to catch non-matching 0.0, -0.0, and NaNs
71-
unsafe { mem::transmute::<f64, u64>(f64::from(l)) == mem::transmute::<f64, u64>(f64::from(r)) }
69+
// to_bits is required to catch non-matching 0.0, -0.0, and NaNs
70+
f64::from(l).to_bits() == f64::from(r).to_bits()
7271
},
7372
(&Constant::Bool(l), &Constant::Bool(r)) => l == r,
7473
(&Constant::Vec(ref l), &Constant::Vec(ref r)) | (&Constant::Tuple(ref l), &Constant::Tuple(ref r)) => {
@@ -99,10 +98,10 @@ impl Hash for Constant {
9998
i.hash(state);
10099
},
101100
Constant::F32(f) => {
102-
unsafe { mem::transmute::<f64, u64>(f64::from(f)) }.hash(state);
101+
f64::from(f).to_bits().hash(state);
103102
},
104103
Constant::F64(f) => {
105-
unsafe { mem::transmute::<f64, u64>(f) }.hash(state);
104+
f.to_bits().hash(state);
106105
},
107106
Constant::Bool(b) => {
108107
b.hash(state);

0 commit comments

Comments
 (0)