Add extra debug assertions for equality for Adt/Variant/FieldDef
This commit is contained in:
parent
521f4dae1b
commit
2b1d4bf44e
2 changed files with 44 additions and 5 deletions
|
@ -111,12 +111,30 @@ impl Ord for AdtDefData {
|
|||
}
|
||||
}
|
||||
|
||||
/// There should be only one AdtDef for each `did`, therefore
|
||||
/// it is fine to implement `PartialEq` only based on `did`.
|
||||
impl PartialEq for AdtDefData {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.did == other.did
|
||||
// There should be only one `AdtDefData` for each `def_id`, therefore
|
||||
// it is fine to implement `PartialEq` only based on `def_id`.
|
||||
//
|
||||
// Below, we exhaustively destructure `self` and `other` so that if the
|
||||
// definition of `AdtDefData` changes, a compile-error will be produced,
|
||||
// reminding us to revisit this assumption.
|
||||
|
||||
let Self { did: self_def_id, variants: _, flags: _, repr: _ } = self;
|
||||
let Self { did: other_def_id, variants: _, flags: _, repr: _ } = other;
|
||||
|
||||
let res = self_def_id == other_def_id;
|
||||
|
||||
// Double check that implicit assumption detailed above.
|
||||
if cfg!(debug_assertions) && res {
|
||||
let deep = self.flags == other.flags
|
||||
&& self.repr == other.repr
|
||||
&& self.variants == other.variants;
|
||||
assert!(deep, "AdtDefData for the same def-id has differing data");
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue