Skip to content

Commit 34187e4

Browse files
committed
Keep going
1 parent bb35981 commit 34187e4

File tree

6 files changed

+53
-15
lines changed

6 files changed

+53
-15
lines changed

compiler/rustc_ast/src/ptr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3030

3131
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3232
/// An owned smart pointer.
33+
#[derive(HashStableEq)]
3334
pub struct P<T: ?Sized> {
3435
ptr: Box<T>,
3536
}

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ macro_rules! impl_stable_hash_via_hash {
232232
};
233233
}
234234

235+
#[macro_export]
236+
macro_rules! impl_hash_stable_eq_via_eq {
237+
($t:ty) => {
238+
impl ::rustc_data_structures::stable_hasher::HashStableEq for $t {
239+
fn hash_stable_eq(&self, other: &Self) -> bool {
240+
self == other
241+
}
242+
}
243+
}
244+
}
245+
235246
impl_stable_hash_via_hash!(i8);
236247
impl_stable_hash_via_hash!(i16);
237248
impl_stable_hash_via_hash!(i32);
@@ -294,6 +305,12 @@ impl<CTX> HashStable<CTX> for ::std::cmp::Ordering {
294305
}
295306
}
296307

308+
impl<T1: HashStableEq, T2: HashStableEq> HashStableEq for (T1, T2) {
309+
fn hash_stable_eq(&self, other: &Self) -> bool {
310+
self.0.hash_stable_eq(&other.0) && self.1.hash_stable_eq(&other.1)
311+
}
312+
}
313+
297314
impl<T1: HashStable<CTX>, CTX> HashStable<CTX> for (T1,) {
298315
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
299316
let (ref _0,) = *self;
@@ -445,6 +462,12 @@ impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for Box<T> {
445462
}
446463
}
447464

465+
impl<T: ?Sized + HashStableEq> HashStableEq for Box<T> {
466+
fn hash_stable_eq(&self, other: &Self) -> bool {
467+
(**self).hash_stable_eq(other)
468+
}
469+
}
470+
448471
impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for ::std::rc::Rc<T> {
449472
#[inline]
450473
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
@@ -570,6 +593,12 @@ where
570593
}
571594
}
572595

596+
impl<'a, T: HashStableEq + ?Sized> HashStableEq for &'a T {
597+
fn hash_stable_eq(&self, other: &Self) -> bool {
598+
(**self).hash_stable_eq(other)
599+
}
600+
}
601+
573602
impl<T, CTX> HashStable<CTX> for ::std::mem::Discriminant<T> {
574603
#[inline]
575604
fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) {

compiler/rustc_hir/src/hir.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ pub enum UnsafeSource {
12431243
UserProvided,
12441244
}
12451245

1246-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
1246+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug, HashStableEq)]
12471247
pub struct BodyId {
12481248
pub hir_id: HirId,
12491249
}
@@ -1476,7 +1476,7 @@ pub struct AnonConst {
14761476
}
14771477

14781478
/// An expression.
1479-
#[derive(Debug)]
1479+
#[derive(Debug, HashStableEq)]
14801480
pub struct Expr<'hir> {
14811481
pub hir_id: HirId,
14821482
pub kind: ExprKind<'hir>,
@@ -2029,7 +2029,7 @@ pub struct FnSig<'hir> {
20292029
// The bodies for items are stored "out of line", in a separate
20302030
// hashmap in the `Crate`. Here we just record the hir-id of the item
20312031
// so it can fetched later.
2032-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
2032+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStableEq)]
20332033
pub struct TraitItemId {
20342034
pub def_id: LocalDefId,
20352035
}
@@ -2046,7 +2046,7 @@ impl TraitItemId {
20462046
/// possibly including a default implementation. A trait item is
20472047
/// either required (meaning it doesn't have an implementation, just a
20482048
/// signature) or provided (meaning it has a default implementation).
2049-
#[derive(Debug)]
2049+
#[derive(Debug, HashStableEq)]
20502050
pub struct TraitItem<'hir> {
20512051
pub ident: Ident,
20522052
pub def_id: LocalDefId,
@@ -2092,7 +2092,7 @@ pub enum TraitItemKind<'hir> {
20922092
// The bodies for items are stored "out of line", in a separate
20932093
// hashmap in the `Crate`. Here we just record the hir-id of the item
20942094
// so it can fetched later.
2095-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
2095+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStableEq)]
20962096
pub struct ImplItemId {
20972097
pub def_id: LocalDefId,
20982098
}
@@ -2106,7 +2106,7 @@ impl ImplItemId {
21062106
}
21072107

21082108
/// Represents anything within an `impl` block.
2109-
#[derive(Debug)]
2109+
#[derive(Debug, HashStableEq)]
21102110
pub struct ImplItem<'hir> {
21112111
pub ident: Ident,
21122112
pub def_id: LocalDefId,
@@ -2209,7 +2209,7 @@ impl TypeBinding<'_> {
22092209
}
22102210
}
22112211

2212-
#[derive(Debug)]
2212+
#[derive(Debug, HashStableEq)]
22132213
pub struct Ty<'hir> {
22142214
pub hir_id: HirId,
22152215
pub kind: TyKind<'hir>,
@@ -2607,7 +2607,7 @@ pub struct PolyTraitRef<'hir> {
26072607

26082608
pub type Visibility<'hir> = Spanned<VisibilityKind<'hir>>;
26092609

2610-
#[derive(Copy, Clone, Debug)]
2610+
#[derive(Copy, Clone, Debug, HashStableEq)]
26112611
pub enum VisibilityKind<'hir> {
26122612
Public,
26132613
Crate(CrateSugar),
@@ -2683,7 +2683,7 @@ impl<'hir> VariantData<'hir> {
26832683
// The bodies for items are stored "out of line", in a separate
26842684
// hashmap in the `Crate`. Here we just record the hir-id of the item
26852685
// so it can fetched later.
2686-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash)]
2686+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash, HashStableEq)]
26872687
pub struct ItemId {
26882688
pub def_id: LocalDefId,
26892689
}
@@ -2699,7 +2699,7 @@ impl ItemId {
26992699
/// An item
27002700
///
27012701
/// The name might be a dummy name in case of anonymous items
2702-
#[derive(Debug)]
2702+
#[derive(Debug, HashStableEq)]
27032703
pub struct Item<'hir> {
27042704
pub ident: Ident,
27052705
pub def_id: LocalDefId,
@@ -2926,7 +2926,7 @@ pub enum AssocItemKind {
29262926
// The bodies for items are stored "out of line", in a separate
29272927
// hashmap in the `Crate`. Here we just record the hir-id of the item
29282928
// so it can fetched later.
2929-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
2929+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStableEq)]
29302930
pub struct ForeignItemId {
29312931
pub def_id: LocalDefId,
29322932
}
@@ -2952,7 +2952,7 @@ pub struct ForeignItemRef {
29522952
pub span: Span,
29532953
}
29542954

2955-
#[derive(Debug)]
2955+
#[derive(Debug, HashStableEq)]
29562956
pub struct ForeignItem<'hir> {
29572957
pub ident: Ident,
29582958
pub kind: ForeignItemKind<'hir>,

compiler/rustc_hir/src/lang_items.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! language_item_table {
4444

4545
enum_from_u32! {
4646
/// A representation of all the valid language items in Rust.
47-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
47+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, HashStableEq)]
4848
pub enum LangItem {
4949
$(
5050
#[doc = concat!("The `", stringify!($name), "` lang item.")]
@@ -84,6 +84,7 @@ macro_rules! language_item_table {
8484
/// All of the language items, defined or not.
8585
/// Defined lang items can come from the current crate or its dependencies.
8686
#[derive(HashStable_Generic, Debug)]
87+
#[stable_hasher(no_hash_stable_eq)]
8788
pub struct LanguageItems {
8889
/// Mappings from lang items to their possibly found [`DefId`]s.
8990
/// The index corresponds to the order in [`LangItem`].

compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
1+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey, HashStableEq};
22

33
use crate::hir::{
44
AttributeMap, BodyId, Crate, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item,
@@ -33,6 +33,12 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
3333
}
3434
}
3535

36+
impl HashStableEq for HirId {
37+
fn hash_stable_eq(&self, other: &HirId) -> bool {
38+
self == other
39+
}
40+
}
41+
3642
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemLocalId {
3743
type KeyType = ItemLocalId;
3844

compiler/rustc_span/src/def_id.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ rustc_index::newtype_index! {
192192
/// A DefIndex is an index into the hir-map for a crate, identifying a
193193
/// particular definition. It should really be considered an interned
194194
/// shorthand for a particular DefPath.
195+
#[derive(HashStableEq)]
195196
pub struct DefIndex {
196197
ENCODABLE = custom // (only encodable in metadata)
197198

@@ -333,7 +334,7 @@ rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
333334
/// few cases where we know that only `DefId`s from the local crate are expected;
334335
/// a `DefId` from a different crate would signify a bug somewhere. This
335336
/// is when `LocalDefId` comes in handy.
336-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
337+
#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStableEq)]
337338
pub struct LocalDefId {
338339
pub local_def_index: DefIndex,
339340
}

0 commit comments

Comments
 (0)