use std::num::wrapping::OverflowingOps;
use std::cmp::Ordering;
use std::collections::hash_map::Entry::Vacant;
+use std::mem::transmute;
use std::{i8, i16, i32, i64, u8, u16, u32, u64};
use std::rc::Rc;
}
}
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug)]
pub enum ConstVal {
Float(f64),
Int(i64),
Tuple(ast::NodeId),
}
+/// Note that equality for `ConstVal` means that the it is the same
+/// constant, not that the rust values are equal. In particular, `NaN
+/// == NaN` (at least if it's the same NaN; distinct encodings for NaN
+/// are considering unequal).
+impl PartialEq for ConstVal {
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn eq(&self, other: &ConstVal) -> bool {
+ match (self, other) {
+ (&Float(a), &Float(b)) => unsafe{transmute::<_,u64>(a) == transmute::<_,u64>(b)},
+ (&Int(a), &Int(b)) => a == b,
+ (&Uint(a), &Uint(b)) => a == b,
+ (&Str(ref a), &Str(ref b)) => a == b,
+ (&ByteStr(ref a), &ByteStr(ref b)) => a == b,
+ (&Bool(a), &Bool(b)) => a == b,
+ (&Struct(a), &Struct(b)) => a == b,
+ (&Tuple(a), &Tuple(b)) => a == b,
+ _ => false,
+ }
+ }
+}
+
impl ConstVal {
pub fn description(&self) -> &'static str {
match *self {
///////////////////////////////////////////////////////////////////////////
// Constants
+//
+// Two constants are equal if they are the same constant. Note that
+// this does not necessarily mean that they are "==" in Rust -- in
+// particular one must be wary of `NaN`!
#[derive(Clone, Debug, PartialEq)]
pub struct Constant<H:Hair> {
Item { def_id: H::DefId, substs: H::Substs },
Value { value: H::ConstVal },
}
+