@@ -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
@@ -1724,6 +1724,59 @@ impl VariantDef {
1724
1724
}
1725
1725
}
1726
1726
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
+
1727
1780
#[ derive( Copy , Clone , Debug , PartialEq , Eq , TyEncodable , TyDecodable , HashStable ) ]
1728
1781
pub enum VariantDiscr {
1729
1782
/// Explicit value for this variant, i.e., `X = 123`.
@@ -1744,6 +1797,42 @@ pub struct FieldDef {
1744
1797
pub vis : Visibility ,
1745
1798
}
1746
1799
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
+
1747
1836
bitflags ! {
1748
1837
#[ derive( TyEncodable , TyDecodable , Default , HashStable ) ]
1749
1838
pub struct ReprFlags : u8 {
0 commit comments