@@ -48,7 +48,7 @@ pub use subst::*;
4848pub use vtable:: * ;
4949
5050use std:: fmt:: Debug ;
51- use std:: hash:: Hash ;
51+ use std:: hash:: { Hash , Hasher } ;
5252use std:: ops:: ControlFlow ;
5353use std:: { fmt, str} ;
5454
@@ -1724,6 +1724,59 @@ impl VariantDef {
17241724 }
17251725}
17261726
1727+ impl PartialEq for VariantDef {
1728+ #[ inline]
1729+ fn eq ( & self , other : & Self ) -> bool {
1730+ // There should be only one `VariantDef` for each `def_id`, therefore
1731+ // it is fine to implement `PartialEq` only based on `def_id`.
1732+ //
1733+ // Below, we exhaustively destructure `self` and `other` so that if the
1734+ // definition of `VariantDef` changes, a compile-error will be produced,
1735+ // reminding us to revisit this assumption.
1736+
1737+ let Self {
1738+ def_id : lhs_def_id,
1739+ ctor_def_id : _,
1740+ name : _,
1741+ discr : _,
1742+ fields : _,
1743+ ctor_kind : _,
1744+ flags : _,
1745+ } = & self ;
1746+
1747+ let Self {
1748+ def_id : rhs_def_id,
1749+ ctor_def_id : _,
1750+ name : _,
1751+ discr : _,
1752+ fields : _,
1753+ ctor_kind : _,
1754+ flags : _,
1755+ } = other;
1756+
1757+ lhs_def_id == rhs_def_id
1758+ }
1759+ }
1760+
1761+ impl Eq for VariantDef { }
1762+
1763+ impl Hash for VariantDef {
1764+ #[ inline]
1765+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1766+ // There should be only one `VariantDef` for each `def_id`, therefore
1767+ // it is fine to implement `Hash` only based on `def_id`.
1768+ //
1769+ // Below, we exhaustively destructure `self` so that if the definition
1770+ // of `VariantDef` changes, a compile-error will be produced, reminding
1771+ // us to revisit this assumption.
1772+
1773+ let Self { def_id, ctor_def_id : _, name : _, discr : _, fields : _, ctor_kind : _, flags : _ } =
1774+ & self ;
1775+
1776+ def_id. hash ( s)
1777+ }
1778+ }
1779+
17271780#[ derive( Copy , Clone , Debug , PartialEq , Eq , TyEncodable , TyDecodable , HashStable ) ]
17281781pub enum VariantDiscr {
17291782 /// Explicit value for this variant, i.e., `X = 123`.
@@ -1744,6 +1797,42 @@ pub struct FieldDef {
17441797 pub vis : Visibility ,
17451798}
17461799
1800+ impl PartialEq for FieldDef {
1801+ #[ inline]
1802+ fn eq ( & self , other : & Self ) -> bool {
1803+ // There should be only one `FieldDef` for each `did`, therefore it is
1804+ // fine to implement `PartialEq` only based on `did`.
1805+ //
1806+ // Below, we exhaustively destructure `self` so that if the definition
1807+ // of `FieldDef` changes, a compile-error will be produced, reminding
1808+ // us to revisit this assumption.
1809+
1810+ let Self { did : lhs_did, name : _, vis : _ } = & self ;
1811+
1812+ let Self { did : rhs_did, name : _, vis : _ } = other;
1813+
1814+ lhs_did == rhs_did
1815+ }
1816+ }
1817+
1818+ impl Eq for FieldDef { }
1819+
1820+ impl Hash for FieldDef {
1821+ #[ inline]
1822+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1823+ // There should be only one `FieldDef` for each `did`, therefore it is
1824+ // fine to implement `Hash` only based on `did`.
1825+ //
1826+ // Below, we exhaustively destructure `self` so that if the definition
1827+ // of `FieldDef` changes, a compile-error will be produced, reminding
1828+ // us to revisit this assumption.
1829+
1830+ let Self { did, name : _, vis : _ } = & self ;
1831+
1832+ did. hash ( s)
1833+ }
1834+ }
1835+
17471836bitflags ! {
17481837 #[ derive( TyEncodable , TyDecodable , Default , HashStable ) ]
17491838 pub struct ReprFlags : u8 {
0 commit comments