@@ -38,6 +38,7 @@ use std::borrow::{Cow, IntoCow};
38
38
use std:: num:: wrapping:: OverflowingOps ;
39
39
use std:: cmp:: Ordering ;
40
40
use std:: collections:: hash_map:: Entry :: Vacant ;
41
+ use std:: mem:: transmute;
41
42
use std:: { i8, i16, i32, i64, u8, u16, u32, u64} ;
42
43
use std:: rc:: Rc ;
43
44
@@ -242,7 +243,7 @@ pub fn lookup_const_fn_by_id<'tcx>(tcx: &ty::ctxt<'tcx>, def_id: DefId)
242
243
}
243
244
}
244
245
245
- #[ derive( Clone , Debug , PartialEq ) ]
246
+ #[ derive( Clone , Debug ) ]
246
247
pub enum ConstVal {
247
248
Float ( f64 ) ,
248
249
Int ( i64 ) ,
@@ -254,6 +255,27 @@ pub enum ConstVal {
254
255
Tuple ( ast:: NodeId ) ,
255
256
}
256
257
258
+ /// Note that equality for `ConstVal` means that the it is the same
259
+ /// constant, not that the rust values are equal. In particular, `NaN
260
+ /// == NaN` (at least if it's the same NaN; distinct encodings for NaN
261
+ /// are considering unequal).
262
+ impl PartialEq for ConstVal {
263
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
264
+ fn eq ( & self , other : & ConstVal ) -> bool {
265
+ match ( self , other) {
266
+ ( & Float ( a) , & Float ( b) ) => unsafe { transmute :: < _ , u64 > ( a) == transmute :: < _ , u64 > ( b) } ,
267
+ ( & Int ( a) , & Int ( b) ) => a == b,
268
+ ( & Uint ( a) , & Uint ( b) ) => a == b,
269
+ ( & Str ( ref a) , & Str ( ref b) ) => a == b,
270
+ ( & ByteStr ( ref a) , & ByteStr ( ref b) ) => a == b,
271
+ ( & Bool ( a) , & Bool ( b) ) => a == b,
272
+ ( & Struct ( a) , & Struct ( b) ) => a == b,
273
+ ( & Tuple ( a) , & Tuple ( b) ) => a == b,
274
+ _ => false ,
275
+ }
276
+ }
277
+ }
278
+
257
279
impl ConstVal {
258
280
pub fn description ( & self ) -> & ' static str {
259
281
match * self {
0 commit comments