@@ -23,7 +23,6 @@ use std::cmp::Ordering::{self, Equal};
2323use std:: cmp:: PartialOrd ;
2424use std:: convert:: TryInto ;
2525use std:: hash:: { Hash , Hasher } ;
26- use std:: mem;
2726use 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