Skip to content

Commit e58d3f5

Browse files
committed
Move HashStable impls.
1 parent 61d483c commit e58d3f5

File tree

5 files changed

+63
-57
lines changed

5 files changed

+63
-57
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use rustc_ast::{self as ast, Attribute, Lit, LitKind, MetaItem, MetaItemKind, NestedMetaItem};
44
use rustc_ast_pretty::pprust;
5+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
56
use rustc_errors::{struct_span_err, Applicability};
67
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
78
use rustc_macros::HashStable_Generic;
@@ -1049,3 +1050,21 @@ fn allow_unstable<'a>(
10491050
name
10501051
}))
10511052
}
1053+
1054+
impl<Ctxt> HashStable<Ctxt> for InlineAttr {
1055+
fn hash_stable(&self, hcx: &mut Ctxt, hasher: &mut StableHasher) {
1056+
std::mem::discriminant(self).hash_stable(hcx, hasher);
1057+
}
1058+
}
1059+
1060+
impl<Ctxt> HashStable<Ctxt> for InstructionSetAttr {
1061+
fn hash_stable(&self, hcx: &mut Ctxt, hasher: &mut StableHasher) {
1062+
std::mem::discriminant(self).hash_stable(hcx, hasher);
1063+
}
1064+
}
1065+
1066+
impl<Ctxt> HashStable<Ctxt> for OptimizeAttr {
1067+
fn hash_stable(&self, hcx: &mut Ctxt, hasher: &mut StableHasher) {
1068+
std::mem::discriminant(self).hash_stable(hcx, hasher);
1069+
}
1070+
}

compiler/rustc_middle/src/ich/hcx.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
230230
self.hash_spans
231231
}
232232

233+
#[inline]
234+
fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
235+
self.def_path_hash(def_id)
236+
}
237+
233238
#[inline]
234239
fn hash_crate_num(&mut self, cnum: CrateNum, hasher: &mut StableHasher) {
235240
let hcx = self;

compiler/rustc_middle/src/ich/impls_hir.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
//! types in no particular order.
33
44
use crate::ich::{NodeIdHashingMode, StableHashingContext};
5-
use rustc_attr as attr;
65
use rustc_data_structures::fingerprint::Fingerprint;
76
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
87
use rustc_hir as hir;
9-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
8+
use rustc_hir::def_id::LocalDefId;
109
use rustc_hir::definitions::DefPathHash;
1110
use smallvec::SmallVec;
1211
use std::mem;
@@ -122,41 +121,6 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
122121
}
123122
}
124123

125-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {
126-
type KeyType = DefPathHash;
127-
128-
#[inline]
129-
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
130-
hcx.def_path_hash(*self)
131-
}
132-
}
133-
134-
impl<'a> HashStable<StableHashingContext<'a>> for LocalDefId {
135-
#[inline]
136-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
137-
hcx.def_path_hash(self.to_def_id()).hash_stable(hcx, hasher);
138-
}
139-
}
140-
141-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for LocalDefId {
142-
type KeyType = DefPathHash;
143-
144-
#[inline]
145-
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
146-
hcx.def_path_hash(self.to_def_id())
147-
}
148-
}
149-
150-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for CrateNum {
151-
type KeyType = DefPathHash;
152-
153-
#[inline]
154-
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
155-
let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX };
156-
def_id.to_stable_hash_key(hcx)
157-
}
158-
}
159-
160124
impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::ItemLocalId {
161125
type KeyType = hir::ItemLocalId;
162126

@@ -214,21 +178,3 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
214178
)
215179
}
216180
}
217-
218-
impl<'hir> HashStable<StableHashingContext<'hir>> for attr::InlineAttr {
219-
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
220-
mem::discriminant(self).hash_stable(hcx, hasher);
221-
}
222-
}
223-
224-
impl<'hir> HashStable<StableHashingContext<'hir>> for attr::InstructionSetAttr {
225-
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
226-
mem::discriminant(self).hash_stable(hcx, hasher);
227-
}
228-
}
229-
230-
impl<'hir> HashStable<StableHashingContext<'hir>> for attr::OptimizeAttr {
231-
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
232-
mem::discriminant(self).hash_stable(hcx, hasher);
233-
}
234-
}

compiler/rustc_span/src/def_id.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::HashStableContext;
22
use rustc_data_structures::fingerprint::Fingerprint;
3-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
44
use rustc_data_structures::AtomicRef;
55
use rustc_index::vec::Idx;
66
use rustc_macros::HashStable_Generic;
@@ -274,8 +274,43 @@ impl<CTX: HashStableContext> HashStable<CTX> for DefId {
274274
}
275275
}
276276

277+
impl<CTX: HashStableContext> ToStableHashKey<CTX> for DefId {
278+
type KeyType = DefPathHash;
279+
280+
#[inline]
281+
fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash {
282+
hcx.def_path_hash(*self)
283+
}
284+
}
285+
286+
impl<CTX: HashStableContext> HashStable<CTX> for LocalDefId {
287+
#[inline]
288+
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
289+
hcx.def_path_hash(self.to_def_id()).hash_stable(hcx, hasher);
290+
}
291+
}
292+
293+
impl<CTX: HashStableContext> ToStableHashKey<CTX> for LocalDefId {
294+
type KeyType = DefPathHash;
295+
296+
#[inline]
297+
fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash {
298+
hcx.def_path_hash(self.to_def_id())
299+
}
300+
}
301+
277302
impl<CTX: HashStableContext> HashStable<CTX> for CrateNum {
278303
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
279304
hcx.hash_crate_num(*self, hasher)
280305
}
281306
}
307+
308+
impl<CTX: HashStableContext> ToStableHashKey<CTX> for CrateNum {
309+
type KeyType = DefPathHash;
310+
311+
#[inline]
312+
fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash {
313+
let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX };
314+
def_id.to_stable_hash_key(hcx)
315+
}
316+
}

compiler/rustc_span/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub use hygiene::SyntaxContext;
3333
use hygiene::Transparency;
3434
pub use hygiene::{DesugaringKind, ExpnData, ExpnId, ExpnKind, ForLoopLoc, MacroKind};
3535
pub mod def_id;
36-
use def_id::{CrateNum, DefId, LOCAL_CRATE};
36+
use def_id::{CrateNum, DefId, DefPathHash, LOCAL_CRATE};
3737
mod span_encoding;
3838
pub use span_encoding::{Span, DUMMY_SP};
3939

@@ -1840,6 +1840,7 @@ fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize {
18401840
/// This is a hack to allow using the `HashStable_Generic` derive macro
18411841
/// instead of implementing everything in librustc_middle.
18421842
pub trait HashStableContext {
1843+
fn def_path_hash(&self, def_id: DefId) -> DefPathHash;
18431844
fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
18441845
fn hash_crate_num(&mut self, _: CrateNum, hasher: &mut StableHasher);
18451846
fn hash_spans(&self) -> bool;

0 commit comments

Comments
 (0)