Skip to content

Commit d4874e9

Browse files
committed
Move librustc_hir/def_id.rs to librustc_span/def_id.rs
For noww, librustc_hir re-exports the `def_id` module from librustc_span, so the rest of rustc can continue to reference rustc_hir::def_id
1 parent fb29dfc commit d4874e9

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

src/librustc/ich/hcx.rs

+6
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
249249
self.hash_spans
250250
}
251251

252+
#[inline]
253+
fn hash_def_id(&mut self, def_id: DefId, hasher: &mut StableHasher) {
254+
let hcx = self;
255+
hcx.def_path_hash(def_id).hash_stable(hcx, hasher);
256+
}
257+
252258
fn byte_pos_to_line_and_col(
253259
&mut self,
254260
byte: BytePos,

src/librustc/ich/impls_hir.rs

-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ use smallvec::SmallVec;
1111
use std::mem;
1212

1313
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
14-
#[inline]
15-
fn hash_def_id(&mut self, def_id: DefId, hasher: &mut StableHasher) {
16-
let hcx = self;
17-
hcx.def_path_hash(def_id).hash_stable(hcx, hasher);
18-
}
19-
2014
#[inline]
2115
fn hash_hir_id(&mut self, hir_id: hir::HirId, hasher: &mut StableHasher) {
2216
let hcx = self;

src/librustc_hir/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
21
use crate::hir;
2+
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
33

44
use rustc_macros::HashStable_Generic;
55
use rustc_span::hygiene::MacroKind;

src/librustc_hir/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extern crate rustc_data_structures;
1313

1414
pub mod def;
15-
pub mod def_id;
15+
pub use rustc_span::def_id;
1616
mod hir;
1717
pub mod hir_id;
1818
pub mod intravisit;

src/librustc_hir/stable_hash_impls.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
22

3-
use crate::def_id::DefId;
43
use crate::hir::{BodyId, Expr, ImplItemId, ItemId, Mod, TraitItemId, Ty, VisibilityKind};
54
use crate::hir_id::HirId;
65

76
/// Requirements for a `StableHashingContext` to be used in this crate.
87
/// This is a hack to allow using the `HashStable_Generic` derive macro
98
/// instead of implementing everything in librustc.
109
pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStableContext {
11-
fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
1210
fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
1311
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
1412
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
@@ -24,12 +22,6 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
2422
}
2523
}
2624

27-
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DefId {
28-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
29-
hcx.hash_def_id(*self, hasher)
30-
}
31-
}
32-
3325
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
3426
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
3527
hcx.hash_body_id(*self, hasher)

src/librustc_hir/def_id.rs src/librustc_span/def_id.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ pub enum CrateNum {
1818
Index(CrateId),
1919
}
2020

21-
impl ::std::fmt::Debug for CrateNum {
22-
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
23-
match self {
24-
CrateNum::Index(id) => write!(fmt, "crate{}", id.private),
25-
CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"),
26-
}
27-
}
28-
}
29-
3021
/// Item definitions in the currently-compiled crate would have the `CrateNum`
3122
/// `LOCAL_CRATE` in their `DefId`.
3223
pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32_const(0));
@@ -100,6 +91,15 @@ impl rustc_serialize::UseSpecializedDecodable for CrateNum {
10091
}
10192
}
10293

94+
impl ::std::fmt::Debug for CrateNum {
95+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
96+
match self {
97+
CrateNum::Index(id) => write!(fmt, "crate{}", id.private),
98+
CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"),
99+
}
100+
}
101+
}
102+
103103
rustc_index::newtype_index! {
104104
/// A DefIndex is an index into the hir-map for a crate, identifying a
105105
/// particular definition. It should really be considered an interned

src/librustc_span/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ use edition::Edition;
2525
pub mod hygiene;
2626
use hygiene::Transparency;
2727
pub use hygiene::{DesugaringKind, ExpnData, ExpnId, ExpnKind, MacroKind, SyntaxContext};
28-
28+
pub mod def_id;
29+
use def_id::DefId;
2930
mod span_encoding;
3031
pub use span_encoding::{Span, DUMMY_SP};
3132

@@ -1561,6 +1562,7 @@ fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize {
15611562
/// instead of implementing everything in librustc.
15621563
pub trait HashStableContext {
15631564
fn hash_spans(&self) -> bool;
1565+
fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
15641566
fn byte_pos_to_line_and_col(
15651567
&mut self,
15661568
byte: BytePos,
@@ -1651,3 +1653,9 @@ where
16511653
}
16521654
}
16531655
}
1656+
1657+
impl<CTX: HashStableContext> HashStable<CTX> for DefId {
1658+
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
1659+
hcx.hash_def_id(*self, hasher)
1660+
}
1661+
}

0 commit comments

Comments
 (0)