@@ -48,7 +48,7 @@ pub use subst::*;
48
48
pub use vtable:: * ;
49
49
50
50
use std:: fmt:: Debug ;
51
- use std:: hash:: Hash ;
51
+ use std:: hash:: { Hash , Hasher } ;
52
52
use std:: ops:: ControlFlow ;
53
53
use std:: { fmt, str} ;
54
54
@@ -1704,6 +1704,59 @@ impl VariantDef {
1704
1704
}
1705
1705
}
1706
1706
1707
+ impl PartialEq for VariantDef {
1708
+ #[ inline]
1709
+ fn eq ( & self , other : & Self ) -> bool {
1710
+ // There should be only one `VariantDef` for each `def_id`, therefore
1711
+ // it is fine to implement `PartialEq` only based on `def_id`.
1712
+ //
1713
+ // Below, we exhaustively destructure `self` and `other` so that if the
1714
+ // definition of `VariantDef` changes, a compile-error will be produced,
1715
+ // reminding us to revisit this assumption.
1716
+
1717
+ let Self {
1718
+ def_id : lhs_def_id,
1719
+ ctor_def_id : _,
1720
+ name : _,
1721
+ discr : _,
1722
+ fields : _,
1723
+ ctor_kind : _,
1724
+ flags : _,
1725
+ } = & self ;
1726
+
1727
+ let Self {
1728
+ def_id : rhs_def_id,
1729
+ ctor_def_id : _,
1730
+ name : _,
1731
+ discr : _,
1732
+ fields : _,
1733
+ ctor_kind : _,
1734
+ flags : _,
1735
+ } = other;
1736
+
1737
+ lhs_def_id == rhs_def_id
1738
+ }
1739
+ }
1740
+
1741
+ impl Eq for VariantDef { }
1742
+
1743
+ impl Hash for VariantDef {
1744
+ #[ inline]
1745
+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1746
+ // There should be only one `VariantDef` for each `def_id`, therefore
1747
+ // it is fine to implement `Hash` only based on `def_id`.
1748
+ //
1749
+ // Below, we exhaustively destructure `self` so that if the definition
1750
+ // of `VariantDef` changes, a compile-error will be produced, reminding
1751
+ // us to revisit this assumption.
1752
+
1753
+ let Self { def_id, ctor_def_id : _, name : _, discr : _, fields : _, ctor_kind : _, flags : _ } =
1754
+ & self ;
1755
+
1756
+ def_id. hash ( s)
1757
+ }
1758
+ }
1759
+
1707
1760
#[ derive( Copy , Clone , Debug , PartialEq , Eq , TyEncodable , TyDecodable , HashStable ) ]
1708
1761
pub enum VariantDiscr {
1709
1762
/// Explicit value for this variant, i.e., `X = 123`.
@@ -1724,6 +1777,42 @@ pub struct FieldDef {
1724
1777
pub vis : Visibility ,
1725
1778
}
1726
1779
1780
+ impl PartialEq for FieldDef {
1781
+ #[ inline]
1782
+ fn eq ( & self , other : & Self ) -> bool {
1783
+ // There should be only one `FieldDef` for each `did`, therefore it is
1784
+ // fine to implement `PartialEq` only based on `did`.
1785
+ //
1786
+ // Below, we exhaustively destructure `self` so that if the definition
1787
+ // of `FieldDef` changes, a compile-error will be produced, reminding
1788
+ // us to revisit this assumption.
1789
+
1790
+ let Self { did : lhs_did, name : _, vis : _ } = & self ;
1791
+
1792
+ let Self { did : rhs_did, name : _, vis : _ } = other;
1793
+
1794
+ lhs_did == rhs_did
1795
+ }
1796
+ }
1797
+
1798
+ impl Eq for FieldDef { }
1799
+
1800
+ impl Hash for FieldDef {
1801
+ #[ inline]
1802
+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1803
+ // There should be only one `FieldDef` for each `did`, therefore it is
1804
+ // fine to implement `Hash` 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, name : _, vis : _ } = & self ;
1811
+
1812
+ did. hash ( s)
1813
+ }
1814
+ }
1815
+
1727
1816
bitflags ! {
1728
1817
#[ derive( TyEncodable , TyDecodable , Default , HashStable ) ]
1729
1818
pub struct ReprFlags : u8 {
0 commit comments