@@ -23,7 +23,6 @@ use std::cmp::Ordering::{self, Equal};
23
23
use std:: cmp:: PartialOrd ;
24
24
use std:: convert:: TryInto ;
25
25
use std:: hash:: { Hash , Hasher } ;
26
- use std:: mem;
27
26
use std:: rc:: Rc ;
28
27
29
28
/// A `LitKind`-like enum to fold constant `Expr`s into.
@@ -61,14 +60,14 @@ impl PartialEq for Constant {
61
60
( & Constant :: F64 ( l) , & Constant :: F64 ( r) ) => {
62
61
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
63
62
// `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 ( )
66
65
} ,
67
66
( & Constant :: F32 ( l) , & Constant :: F32 ( r) ) => {
68
67
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
69
68
// `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 ( )
72
71
} ,
73
72
( & Constant :: Bool ( l) , & Constant :: Bool ( r) ) => l == r,
74
73
( & Constant :: Vec ( ref l) , & Constant :: Vec ( ref r) ) | ( & Constant :: Tuple ( ref l) , & Constant :: Tuple ( ref r) ) => {
@@ -99,10 +98,10 @@ impl Hash for Constant {
99
98
i. hash ( state) ;
100
99
} ,
101
100
Constant :: F32 ( f) => {
102
- unsafe { mem :: transmute :: < f64 , u64 > ( f64 :: from ( f) ) } . hash ( state) ;
101
+ f64:: from ( f) . to_bits ( ) . hash ( state) ;
103
102
} ,
104
103
Constant :: F64 ( f) => {
105
- unsafe { mem :: transmute :: < f64 , u64 > ( f ) } . hash ( state) ;
104
+ f . to_bits ( ) . hash ( state) ;
106
105
} ,
107
106
Constant :: Bool ( b) => {
108
107
b. hash ( state) ;
0 commit comments