From d4874e943b3d55ff19b76cabd47dd2463ab9d39e Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 8 Feb 2020 15:06:31 -0500 Subject: [PATCH] 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 --- src/librustc/ich/hcx.rs | 6 ++++++ src/librustc/ich/impls_hir.rs | 6 ------ src/librustc_hir/def.rs | 2 +- src/librustc_hir/lib.rs | 2 +- src/librustc_hir/stable_hash_impls.rs | 8 -------- src/{librustc_hir => librustc_span}/def_id.rs | 18 +++++++++--------- src/librustc_span/lib.rs | 10 +++++++++- 7 files changed, 26 insertions(+), 26 deletions(-) rename src/{librustc_hir => librustc_span}/def_id.rs (100%) diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index aade4c3f74c54..76e4b5f01b775 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -249,6 +249,12 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { self.hash_spans } + #[inline] + fn hash_def_id(&mut self, def_id: DefId, hasher: &mut StableHasher) { + let hcx = self; + hcx.def_path_hash(def_id).hash_stable(hcx, hasher); + } + fn byte_pos_to_line_and_col( &mut self, byte: BytePos, diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 0155861549773..625d8a4670f22 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -11,12 +11,6 @@ use smallvec::SmallVec; use std::mem; impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> { - #[inline] - fn hash_def_id(&mut self, def_id: DefId, hasher: &mut StableHasher) { - let hcx = self; - hcx.def_path_hash(def_id).hash_stable(hcx, hasher); - } - #[inline] fn hash_hir_id(&mut self, hir_id: hir::HirId, hasher: &mut StableHasher) { let hcx = self; diff --git a/src/librustc_hir/def.rs b/src/librustc_hir/def.rs index 83e30d85c5a67..d93749b737232 100644 --- a/src/librustc_hir/def.rs +++ b/src/librustc_hir/def.rs @@ -1,5 +1,5 @@ -use crate::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::hir; +use rustc_span::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_macros::HashStable_Generic; use rustc_span::hygiene::MacroKind; diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs index f54fa291bd6e8..e4edd34bd6e23 100644 --- a/src/librustc_hir/lib.rs +++ b/src/librustc_hir/lib.rs @@ -12,7 +12,7 @@ extern crate rustc_data_structures; pub mod def; -pub mod def_id; +pub use rustc_span::def_id; mod hir; pub mod hir_id; pub mod intravisit; diff --git a/src/librustc_hir/stable_hash_impls.rs b/src/librustc_hir/stable_hash_impls.rs index 294074cd3e5a4..e8407b537011b 100644 --- a/src/librustc_hir/stable_hash_impls.rs +++ b/src/librustc_hir/stable_hash_impls.rs @@ -1,6 +1,5 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -use crate::def_id::DefId; use crate::hir::{BodyId, Expr, ImplItemId, ItemId, Mod, TraitItemId, Ty, VisibilityKind}; use crate::hir_id::HirId; @@ -8,7 +7,6 @@ use crate::hir_id::HirId; /// This is a hack to allow using the `HashStable_Generic` derive macro /// instead of implementing everything in librustc. pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStableContext { - fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher); fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher); fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher); fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher); @@ -24,12 +22,6 @@ impl HashStable for HirId { } } -impl HashStable for DefId { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { - hcx.hash_def_id(*self, hasher) - } -} - impl HashStable for BodyId { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { hcx.hash_body_id(*self, hasher) diff --git a/src/librustc_hir/def_id.rs b/src/librustc_span/def_id.rs similarity index 100% rename from src/librustc_hir/def_id.rs rename to src/librustc_span/def_id.rs index 7ee778ddd8ec7..f4aa802dec6fb 100644 --- a/src/librustc_hir/def_id.rs +++ b/src/librustc_span/def_id.rs @@ -18,15 +18,6 @@ pub enum CrateNum { Index(CrateId), } -impl ::std::fmt::Debug for CrateNum { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - match self { - CrateNum::Index(id) => write!(fmt, "crate{}", id.private), - CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"), - } - } -} - /// Item definitions in the currently-compiled crate would have the `CrateNum` /// `LOCAL_CRATE` in their `DefId`. pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32_const(0)); @@ -100,6 +91,15 @@ impl rustc_serialize::UseSpecializedDecodable for CrateNum { } } +impl ::std::fmt::Debug for CrateNum { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + match self { + CrateNum::Index(id) => write!(fmt, "crate{}", id.private), + CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"), + } + } +} + rustc_index::newtype_index! { /// A DefIndex is an index into the hir-map for a crate, identifying a /// particular definition. It should really be considered an interned diff --git a/src/librustc_span/lib.rs b/src/librustc_span/lib.rs index 413bd77daae24..d548b33a1a3e4 100644 --- a/src/librustc_span/lib.rs +++ b/src/librustc_span/lib.rs @@ -25,7 +25,8 @@ use edition::Edition; pub mod hygiene; use hygiene::Transparency; pub use hygiene::{DesugaringKind, ExpnData, ExpnId, ExpnKind, MacroKind, SyntaxContext}; - +pub mod def_id; +use def_id::DefId; mod span_encoding; pub use span_encoding::{Span, DUMMY_SP}; @@ -1561,6 +1562,7 @@ fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize { /// instead of implementing everything in librustc. pub trait HashStableContext { fn hash_spans(&self) -> bool; + fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher); fn byte_pos_to_line_and_col( &mut self, byte: BytePos, @@ -1651,3 +1653,9 @@ where } } } + +impl HashStable for DefId { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + hcx.hash_def_id(*self, hasher) + } +}