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
This commit is contained in:
parent
fb29dfcc9a
commit
619051e4f0
6 changed files with 27 additions and 25 deletions
|
@ -249,6 +249,12 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
|
||||||
self.hash_spans
|
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(
|
fn byte_pos_to_line_and_col(
|
||||||
&mut self,
|
&mut self,
|
||||||
byte: BytePos,
|
byte: BytePos,
|
||||||
|
|
|
@ -11,12 +11,6 @@ use smallvec::SmallVec;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
|
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]
|
#[inline]
|
||||||
fn hash_hir_id(&mut self, hir_id: hir::HirId, hasher: &mut StableHasher) {
|
fn hash_hir_id(&mut self, hir_id: hir::HirId, hasher: &mut StableHasher) {
|
||||||
let hcx = self;
|
let hcx = self;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
extern crate rustc_data_structures;
|
extern crate rustc_data_structures;
|
||||||
|
|
||||||
pub mod def;
|
pub mod def;
|
||||||
pub mod def_id;
|
pub use rustc_span::def_id;
|
||||||
mod hir;
|
mod hir;
|
||||||
pub mod hir_id;
|
pub mod hir_id;
|
||||||
pub mod intravisit;
|
pub mod intravisit;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
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::{BodyId, Expr, ImplItemId, ItemId, Mod, TraitItemId, Ty, VisibilityKind};
|
||||||
use crate::hir_id::HirId;
|
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
|
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
||||||
/// instead of implementing everything in librustc.
|
/// instead of implementing everything in librustc.
|
||||||
pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStableContext {
|
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_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
|
||||||
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
|
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
|
||||||
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
|
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
|
||||||
|
@ -24,12 +22,6 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DefId {
|
|
||||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
|
||||||
hcx.hash_def_id(*self, hasher)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
|
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
|
||||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||||
hcx.hash_body_id(*self, hasher)
|
hcx.hash_body_id(*self, hasher)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::HashStableContext;
|
||||||
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::AtomicRef;
|
use rustc_data_structures::AtomicRef;
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
use rustc_serialize::{Decoder, Encoder};
|
use rustc_serialize::{Decoder, Encoder};
|
||||||
|
@ -18,15 +20,6 @@ pub enum CrateNum {
|
||||||
Index(CrateId),
|
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`
|
/// Item definitions in the currently-compiled crate would have the `CrateNum`
|
||||||
/// `LOCAL_CRATE` in their `DefId`.
|
/// `LOCAL_CRATE` in their `DefId`.
|
||||||
pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32_const(0));
|
pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32_const(0));
|
||||||
|
@ -100,6 +93,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! {
|
rustc_index::newtype_index! {
|
||||||
/// A DefIndex is an index into the hir-map for a crate, identifying a
|
/// A DefIndex is an index into the hir-map for a crate, identifying a
|
||||||
/// particular definition. It should really be considered an interned
|
/// particular definition. It should really be considered an interned
|
||||||
|
@ -207,3 +209,9 @@ impl fmt::Debug for LocalDefId {
|
||||||
|
|
||||||
impl rustc_serialize::UseSpecializedEncodable for LocalDefId {}
|
impl rustc_serialize::UseSpecializedEncodable for LocalDefId {}
|
||||||
impl rustc_serialize::UseSpecializedDecodable for LocalDefId {}
|
impl rustc_serialize::UseSpecializedDecodable for LocalDefId {}
|
||||||
|
|
||||||
|
impl<CTX: HashStableContext> HashStable<CTX> for DefId {
|
||||||
|
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
||||||
|
hcx.hash_def_id(*self, hasher)
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,8 @@ use edition::Edition;
|
||||||
pub mod hygiene;
|
pub mod hygiene;
|
||||||
use hygiene::Transparency;
|
use hygiene::Transparency;
|
||||||
pub use hygiene::{DesugaringKind, ExpnData, ExpnId, ExpnKind, MacroKind, SyntaxContext};
|
pub use hygiene::{DesugaringKind, ExpnData, ExpnId, ExpnKind, MacroKind, SyntaxContext};
|
||||||
|
pub mod def_id;
|
||||||
|
use def_id::DefId;
|
||||||
mod span_encoding;
|
mod span_encoding;
|
||||||
pub use span_encoding::{Span, DUMMY_SP};
|
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.
|
/// instead of implementing everything in librustc.
|
||||||
pub trait HashStableContext {
|
pub trait HashStableContext {
|
||||||
fn hash_spans(&self) -> bool;
|
fn hash_spans(&self) -> bool;
|
||||||
|
fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
|
||||||
fn byte_pos_to_line_and_col(
|
fn byte_pos_to_line_and_col(
|
||||||
&mut self,
|
&mut self,
|
||||||
byte: BytePos,
|
byte: BytePos,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue