Don't derive PartialEq for Term
Using derive, it only compares the internal usize, but this means it
does not look through boxed terms pointers to the actual value for
equality.  Therefore, in PartialEq, convert to TypedTerm and use its
PartialEq.
@@ -612,7 +612,7 @@ mod typecheck {
///
/// Since `Term` values are often pointers, it should be given the same considerations
/// that you would give a raw pointer/reference anywhere else
-#[derive(Clone, Copy, PartialEq, Eq, Hash)]
+#[derive(Clone, Copy, Eq, Hash)]
#[repr(transparent)]
pub struct Term(usize);
impl Term {
@@ -1403,6 +1403,17 @@ impl From<u8> for Term {
unsafe { small_integer.as_term() }
}
}
+impl PartialEq<Term> for Term {
+ fn eq(&self, other: &Term) -> bool {
+ match (self.to_typed_term(), other.to_typed_term()) {
+ (Ok(ref self_typed_term), Ok(ref other_typed_term)) => {
+ self_typed_term.eq(other_typed_term)
+ }
+ (Err(_), Err(_)) => true,
+ _ => false,
+ }
+ }
+}
impl PartialOrd<Term> for Term {
fn partial_cmp(&self, other: &Term) -> Option<cmp::Ordering> {
if let Ok(ref lhs) = self.to_typed_term() {
