Skip to content

Commit

Permalink
[illicit] Compare AnonRc's for equality only by data pointers, not vt…
Browse files Browse the repository at this point in the history
…ables.
  • Loading branch information
anp committed May 23, 2020
1 parent 6cfae55 commit 8b885dd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions illicit/src/anon_rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,24 @@ impl AnonRc {
}
}

/// compare the pointers by their data locations, ignoring vtables
macro_rules! data_ptrs_eq {
($trt:ident: $anon1:expr, $anon2:expr) => {
std::ptr::eq(
$anon1 as &dyn $trt as *const dyn $trt as *const u8,
$anon2 as &dyn $trt as *const dyn $trt as *const u8,
)
};
}

impl PartialEq for AnonRc {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
&& self.depth == other.depth
&& self.name == other.name
&& self.location == other.location
&& Rc::ptr_eq(&self.inner, &other.inner)
&& Rc::ptr_eq(&self.debug, &other.debug)
&& data_ptrs_eq!(Any: &self.inner, &other.inner)
&& data_ptrs_eq!(Debug: &self.debug, &other.debug)
}
}
impl Eq for AnonRc {}
Expand Down

0 comments on commit 8b885dd

Please sign in to comment.