1
Fork 0

rustc: use LocalDefId instead of DefIndex in HirId.

This commit is contained in:
Eduard-Mihai Burtescu 2020-03-18 20:27:59 +02:00
parent 6130b9959c
commit f3ec069886
32 changed files with 138 additions and 201 deletions

View file

@ -477,7 +477,7 @@ impl<'tcx> DepNodeParams<'tcx> for HirId {
fn to_fingerprint(&self, tcx: TyCtxt<'_>) -> Fingerprint { fn to_fingerprint(&self, tcx: TyCtxt<'_>) -> Fingerprint {
let HirId { owner, local_id } = *self; let HirId { owner, local_id } = *self;
let def_path_hash = tcx.def_path_hash(DefId::local(owner)); let def_path_hash = tcx.def_path_hash(owner.to_def_id());
let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into()); let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into());
def_path_hash.0.combine(local_id) def_path_hash.0.combine(local_id)

View file

@ -902,7 +902,7 @@ impl DepGraph {
fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: DefId) -> bool { fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
def_id.index == hir_id.owner def_id.index == hir_id.owner.local_def_index
} }
/// A "work product" is an intermediate result that we save into the /// A "work product" is an intermediate result that we save into the

View file

@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::svh::Svh; use rustc_data_structures::svh::Svh;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::CRATE_DEF_INDEX; use rustc_hir::def_id::CRATE_DEF_INDEX;
use rustc_hir::def_id::{DefIndex, LOCAL_CRATE}; use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::*; use rustc_hir::*;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
@ -30,12 +30,12 @@ pub(super) struct NodeCollector<'a, 'hir> {
/// Source map /// Source map
source_map: &'a SourceMap, source_map: &'a SourceMap,
map: IndexVec<DefIndex, HirOwnerData<'hir>>, map: IndexVec<LocalDefId, HirOwnerData<'hir>>,
/// The parent of this node /// The parent of this node
parent_node: hir::HirId, parent_node: hir::HirId,
current_dep_node_owner: DefIndex, current_dep_node_owner: LocalDefId,
definitions: &'a definitions::Definitions, definitions: &'a definitions::Definitions,
@ -126,7 +126,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
krate, krate,
source_map: sess.source_map(), source_map: sess.source_map(),
parent_node: hir::CRATE_HIR_ID, parent_node: hir::CRATE_HIR_ID,
current_dep_node_owner: CRATE_DEF_INDEX, current_dep_node_owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
definitions, definitions,
hcx, hcx,
hir_body_nodes, hir_body_nodes,
@ -148,7 +148,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
crate_disambiguator: CrateDisambiguator, crate_disambiguator: CrateDisambiguator,
cstore: &dyn CrateStore, cstore: &dyn CrateStore,
commandline_args_hash: u64, commandline_args_hash: u64,
) -> (IndexVec<DefIndex, HirOwnerData<'hir>>, Svh) { ) -> (IndexVec<LocalDefId, HirOwnerData<'hir>>, Svh) {
// Insert bodies into the map // Insert bodies into the map
for (id, body) in self.krate.bodies.iter() { for (id, body) in self.krate.bodies.iter() {
let bodies = &mut self.map[id.hir_id.owner].with_bodies.as_mut().unwrap().bodies; let bodies = &mut self.map[id.hir_id.owner].with_bodies.as_mut().unwrap().bodies;
@ -261,9 +261,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}", current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
self.source_map.span_to_string(span), self.source_map.span_to_string(span),
node_str, node_str,
self.definitions.def_path(self.current_dep_node_owner).to_string_no_crate(), self.definitions
.def_path(self.current_dep_node_owner.local_def_index)
.to_string_no_crate(),
self.current_dep_node_owner, self.current_dep_node_owner,
self.definitions.def_path(hir_id.owner).to_string_no_crate(), self.definitions.def_path(hir_id.owner.local_def_index).to_string_no_crate(),
hir_id.owner, hir_id.owner,
forgot_str, forgot_str,
) )
@ -285,13 +287,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
F: FnOnce(&mut Self, Fingerprint), F: FnOnce(&mut Self, Fingerprint),
>( >(
&mut self, &mut self,
dep_node_owner: DefIndex, dep_node_owner: LocalDefId,
item_like: &T, item_like: &T,
f: F, f: F,
) { ) {
let prev_owner = self.current_dep_node_owner; let prev_owner = self.current_dep_node_owner;
let def_path_hash = self.definitions.def_path_hash(dep_node_owner); let def_path_hash = self.definitions.def_path_hash(dep_node_owner.local_def_index);
let hash = hash_body(&mut self.hcx, def_path_hash, item_like, &mut self.hir_body_nodes); let hash = hash_body(&mut self.hcx, def_path_hash, item_like, &mut self.hir_body_nodes);
@ -340,7 +342,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_item(&mut self, i: &'hir Item<'hir>) { fn visit_item(&mut self, i: &'hir Item<'hir>) {
debug!("visit_item: {:?}", i); debug!("visit_item: {:?}", i);
debug_assert_eq!( debug_assert_eq!(
i.hir_id.owner, i.hir_id.owner.local_def_index,
self.definitions.opt_def_index(self.definitions.hir_to_node_id(i.hir_id)).unwrap() self.definitions.opt_def_index(self.definitions.hir_to_node_id(i.hir_id)).unwrap()
); );
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| { self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
@ -372,7 +374,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) { fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
debug_assert_eq!( debug_assert_eq!(
ti.hir_id.owner, ti.hir_id.owner.local_def_index,
self.definitions.opt_def_index(self.definitions.hir_to_node_id(ti.hir_id)).unwrap() self.definitions.opt_def_index(self.definitions.hir_to_node_id(ti.hir_id)).unwrap()
); );
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| { self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
@ -386,7 +388,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) { fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
debug_assert_eq!( debug_assert_eq!(
ii.hir_id.owner, ii.hir_id.owner.local_def_index,
self.definitions.opt_def_index(self.definitions.hir_to_node_id(ii.hir_id)).unwrap() self.definitions.opt_def_index(self.definitions.hir_to_node_id(ii.hir_id)).unwrap()
); );
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| { self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
@ -506,10 +508,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
} }
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) { fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) {
let node_id = self.definitions.hir_to_node_id(macro_def.hir_id); self.with_dep_node_owner(macro_def.hir_id.owner, macro_def, |this, hash| {
let def_index = self.definitions.opt_def_index(node_id).unwrap();
self.with_dep_node_owner(def_index, macro_def, |this, hash| {
this.insert_with_hash( this.insert_with_hash(
macro_def.span, macro_def.span,
macro_def.hir_id, macro_def.hir_id,

View file

@ -3,7 +3,7 @@ use crate::ty::TyCtxt;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator}; use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefIndex, LocalDefId, CRATE_DEF_INDEX}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_INDEX};
use rustc_hir::intravisit; use rustc_hir::intravisit;
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::{HirId, ItemLocalId}; use rustc_hir::{HirId, ItemLocalId};
@ -32,7 +32,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
struct HirIdValidator<'a, 'hir> { struct HirIdValidator<'a, 'hir> {
hir_map: Map<'hir>, hir_map: Map<'hir>,
owner_def_index: Option<DefIndex>, owner: Option<LocalDefId>,
hir_ids_seen: FxHashSet<ItemLocalId>, hir_ids_seen: FxHashSet<ItemLocalId>,
errors: &'a Lock<Vec<String>>, errors: &'a Lock<Vec<String>>,
} }
@ -46,7 +46,7 @@ impl<'a, 'hir> OuterVisitor<'a, 'hir> {
fn new_inner_visitor(&self, hir_map: Map<'hir>) -> HirIdValidator<'a, 'hir> { fn new_inner_visitor(&self, hir_map: Map<'hir>) -> HirIdValidator<'a, 'hir> {
HirIdValidator { HirIdValidator {
hir_map, hir_map,
owner_def_index: None, owner: None,
hir_ids_seen: Default::default(), hir_ids_seen: Default::default(),
errors: self.errors, errors: self.errors,
} }
@ -78,12 +78,12 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
} }
fn check<F: FnOnce(&mut HirIdValidator<'a, 'hir>)>(&mut self, hir_id: HirId, walk: F) { fn check<F: FnOnce(&mut HirIdValidator<'a, 'hir>)>(&mut self, hir_id: HirId, walk: F) {
assert!(self.owner_def_index.is_none()); assert!(self.owner.is_none());
let owner_def_index = self.hir_map.local_def_id(hir_id).index; let owner = self.hir_map.local_def_id(hir_id).expect_local();
self.owner_def_index = Some(owner_def_index); self.owner = Some(owner);
walk(self); walk(self);
if owner_def_index == CRATE_DEF_INDEX { if owner.local_def_index == CRATE_DEF_INDEX {
return; return;
} }
@ -105,31 +105,26 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
let mut missing_items = Vec::with_capacity(missing.len()); let mut missing_items = Vec::with_capacity(missing.len());
for local_id in missing { for local_id in missing {
let hir_id = let hir_id = HirId { owner, local_id: ItemLocalId::from_u32(local_id) };
HirId { owner: owner_def_index, local_id: ItemLocalId::from_u32(local_id) };
trace!("missing hir id {:#?}", hir_id); trace!("missing hir id {:#?}", hir_id);
missing_items.push(format!( missing_items.push(format!(
"[local_id: {}, owner: {}]", "[local_id: {}, owner: {}]",
local_id, local_id,
self.hir_map self.hir_map.def_path(owner).to_string_no_crate()
.def_path(LocalDefId { local_def_index: owner_def_index })
.to_string_no_crate()
)); ));
} }
self.error(|| { self.error(|| {
format!( format!(
"ItemLocalIds not assigned densely in {}. \ "ItemLocalIds not assigned densely in {}. \
Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}", Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}",
self.hir_map self.hir_map.def_path(owner).to_string_no_crate(),
.def_path(LocalDefId { local_def_index: owner_def_index })
.to_string_no_crate(),
max, max,
missing_items, missing_items,
self.hir_ids_seen self.hir_ids_seen
.iter() .iter()
.map(|&local_id| HirId { owner: owner_def_index, local_id }) .map(|&local_id| HirId { owner, local_id })
.map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h))) .map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h)))
.collect::<Vec<_>>() .collect::<Vec<_>>()
) )
@ -146,7 +141,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
} }
fn visit_id(&mut self, hir_id: HirId) { fn visit_id(&mut self, hir_id: HirId) {
let owner = self.owner_def_index.expect("no owner_def_index"); let owner = self.owner.expect("no owner");
if hir_id == hir::DUMMY_HIR_ID { if hir_id == hir::DUMMY_HIR_ID {
self.error(|| { self.error(|| {
@ -163,10 +158,8 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
format!( format!(
"HirIdValidator: The recorded owner of {} is {} instead of {}", "HirIdValidator: The recorded owner of {} is {} instead of {}",
self.hir_map.node_to_string(hir_id), self.hir_map.node_to_string(hir_id),
self.hir_map.def_path(hir_id.owner_local_def_id()).to_string_no_crate(), self.hir_map.def_path(hir_id.owner).to_string_no_crate(),
self.hir_map self.hir_map.def_path(owner).to_string_no_crate()
.def_path(LocalDefId { local_def_index: owner })
.to_string_no_crate()
) )
}); });
} }

View file

@ -138,7 +138,7 @@ pub struct IndexedHir<'hir> {
/// The SVH of the local crate. /// The SVH of the local crate.
pub crate_hash: Svh, pub crate_hash: Svh,
pub(super) map: IndexVec<DefIndex, HirOwnerData<'hir>>, pub(super) map: IndexVec<LocalDefId, HirOwnerData<'hir>>,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -345,10 +345,10 @@ impl<'hir> Map<'hir> {
fn get_entry(&self, id: HirId) -> Entry<'hir> { fn get_entry(&self, id: HirId) -> Entry<'hir> {
if id.local_id == ItemLocalId::from_u32(0) { if id.local_id == ItemLocalId::from_u32(0) {
let owner = self.tcx.hir_owner(id.owner_def_id()); let owner = self.tcx.hir_owner(id.owner);
Entry { parent: owner.parent, node: owner.node } Entry { parent: owner.parent, node: owner.node }
} else { } else {
let owner = self.tcx.hir_owner_items(id.owner_def_id()); let owner = self.tcx.hir_owner_items(id.owner);
let item = owner.items[id.local_id].as_ref().unwrap(); let item = owner.items[id.local_id].as_ref().unwrap();
Entry { parent: HirId { owner: id.owner, local_id: item.parent }, node: item.node } Entry { parent: HirId { owner: id.owner, local_id: item.parent }, node: item.node }
} }
@ -376,11 +376,7 @@ impl<'hir> Map<'hir> {
} }
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> { pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
self.tcx self.tcx.hir_owner_items(id.hir_id.owner).bodies.get(&id.hir_id.local_id).unwrap()
.hir_owner_items(DefId::local(id.hir_id.owner))
.bodies
.get(&id.hir_id.local_id)
.unwrap()
} }
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> { pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
@ -494,7 +490,7 @@ impl<'hir> Map<'hir> {
where where
V: ItemLikeVisitor<'hir>, V: ItemLikeVisitor<'hir>,
{ {
let module = self.tcx.hir_module_items(module); let module = self.tcx.hir_module_items(module.expect_local());
for id in &module.items { for id in &module.items {
visitor.visit_item(self.expect_item(*id)); visitor.visit_item(self.expect_item(*id));

View file

@ -11,7 +11,7 @@ use crate::ty::TyCtxt;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
use rustc_hir::Body; use rustc_hir::Body;
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_hir::ItemLocalId; use rustc_hir::ItemLocalId;
@ -60,27 +60,27 @@ impl<'tcx> TyCtxt<'tcx> {
map::Map { tcx: self } map::Map { tcx: self }
} }
pub fn parent_module(self, id: HirId) -> DefId { pub fn parent_module(self, id: HirId) -> LocalDefId {
self.parent_module_from_def_id(DefId::local(id.owner)) self.parent_module_from_def_id(id.owner)
} }
} }
pub fn provide(providers: &mut Providers<'_>) { pub fn provide(providers: &mut Providers<'_>) {
providers.parent_module_from_def_id = |tcx, id| { providers.parent_module_from_def_id = |tcx, id| {
let hir = tcx.hir(); let hir = tcx.hir();
hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id).unwrap())) hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id.to_def_id()).unwrap()))
.expect_local()
}; };
providers.hir_crate = |tcx, _| tcx.untracked_crate; providers.hir_crate = |tcx, _| tcx.untracked_crate;
providers.index_hir = map::index_hir; providers.index_hir = map::index_hir;
providers.hir_module_items = |tcx, id| { providers.hir_module_items = |tcx, id| {
assert_eq!(id.krate, LOCAL_CRATE);
let hir = tcx.hir(); let hir = tcx.hir();
let module = hir.as_local_hir_id(id).unwrap(); let module = hir.as_local_hir_id(id.to_def_id()).unwrap();
&tcx.untracked_crate.modules[&module] &tcx.untracked_crate.modules[&module]
}; };
providers.hir_owner = |tcx, id| tcx.index_hir(id.krate).map[id.index].signature.unwrap(); providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature.unwrap();
providers.hir_owner_items = |tcx, id| { providers.hir_owner_items = |tcx, id| {
tcx.index_hir(id.krate).map[id.index].with_bodies.as_ref().map(|items| &**items).unwrap() tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|items| &**items).unwrap()
}; };
map::provide(providers); map::provide(providers);
} }

View file

@ -21,7 +21,7 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
NodeIdHashingMode::HashDefPath => { NodeIdHashingMode::HashDefPath => {
let hir::HirId { owner, local_id } = hir_id; let hir::HirId { owner, local_id } = hir_id;
hcx.local_def_path_hash(owner).hash_stable(hcx, hasher); hcx.local_def_path_hash(owner.local_def_index).hash_stable(hcx, hasher);
local_id.hash_stable(hcx, hasher); local_id.hash_stable(hcx, hasher);
} }
} }
@ -231,7 +231,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
let import_keys = import_ids let import_keys = import_ids
.iter() .iter()
.map(|hir_id| (hcx.local_def_path_hash(hir_id.owner), hir_id.local_id)) .map(|hir_id| (hcx.local_def_path_hash(hir_id.owner.local_def_index), hir_id.local_id))
.collect(); .collect();
(hcx.def_path_hash(*def_id), import_keys) (hcx.def_path_hash(*def_id), import_keys)
} }

View file

@ -9,7 +9,6 @@
use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::ty::{self, DefIdTree, TyCtxt}; use crate::ty::{self, DefIdTree, TyCtxt};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::Node; use rustc_hir::Node;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
@ -594,7 +593,7 @@ impl<'tcx> ScopeTree {
region scope tree for {:?} / {:?}", region scope tree for {:?} / {:?}",
param_owner, param_owner,
self.root_parent.map(|id| tcx.hir().local_def_id(id)), self.root_parent.map(|id| tcx.hir().local_def_id(id)),
self.root_body.map(|hir_id| DefId::local(hir_id.owner)) self.root_body.map(|hir_id| hir_id.owner)
), ),
); );
} }

View file

@ -66,24 +66,27 @@ rustc_queries! {
// The items in a module. // The items in a module.
// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`. // This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
// Avoid calling this query directly. // Avoid calling this query directly.
query hir_module_items(key: DefId) -> &'tcx hir::ModuleItems { query hir_module_items(key: LocalDefId) -> &'tcx hir::ModuleItems {
eval_always eval_always
desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
} }
// An HIR item with a `DefId` that can own other HIR items which do not themselves have // An HIR item with a `LocalDefId` that can own other HIR items which do
// a `DefId`. // not themselves have a `LocalDefId`.
// This can be conveniently accessed by methods on `tcx.hir()`. // This can be conveniently accessed by methods on `tcx.hir()`.
// Avoid calling this query directly. // Avoid calling this query directly.
query hir_owner(key: DefId) -> &'tcx HirOwner<'tcx> { query hir_owner(key: LocalDefId) -> &'tcx HirOwner<'tcx> {
eval_always eval_always
desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
} }
// The HIR items which do not themselves have a `DefId` and are owned by another HIR item // The HIR items which do not themselves have a `LocalDefId` and are
// with a `DefId`. // owned by another HIR item with a `LocalDefId`.
// This can be conveniently accessed by methods on `tcx.hir()`. // This can be conveniently accessed by methods on `tcx.hir()`.
// Avoid calling this query directly. // Avoid calling this query directly.
query hir_owner_items(key: DefId) -> &'tcx HirOwnerItems<'tcx> { query hir_owner_items(key: LocalDefId) -> &'tcx HirOwnerItems<'tcx> {
eval_always eval_always
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
} }
/// Records the type of every item. /// Records the type of every item.
@ -135,8 +138,9 @@ rustc_queries! {
desc { "computing the lint levels for items in this crate" } desc { "computing the lint levels for items in this crate" }
} }
query parent_module_from_def_id(_: DefId) -> DefId { query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
eval_always eval_always
desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
} }
} }

View file

@ -205,13 +205,13 @@ fn validate_hir_id_for_typeck_tables(
mut_access: bool, mut_access: bool,
) { ) {
if let Some(local_id_root) = local_id_root { if let Some(local_id_root) = local_id_root {
if hir_id.owner != local_id_root.index { if hir_id.owner.to_def_id() != local_id_root {
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
bug!( bug!(
"node {} with HirId::owner {:?} cannot be placed in \ "node {} with HirId::owner {:?} cannot be placed in \
TypeckTables with local_id_root {:?}", TypeckTables with local_id_root {:?}",
tcx.hir().node_to_string(hir_id), tcx.hir().node_to_string(hir_id),
DefId::local(hir_id.owner), hir_id.owner,
local_id_root local_id_root
) )
}); });
@ -732,8 +732,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
let local_id_root = local_id_root.expect("trying to hash invalid TypeckTables"); let local_id_root = local_id_root.expect("trying to hash invalid TypeckTables");
let var_owner_def_id = let var_owner_def_id = DefId {
DefId { krate: local_id_root.krate, index: var_path.hir_id.owner }; krate: local_id_root.krate,
index: var_path.hir_id.owner.local_def_index,
};
let closure_def_id = let closure_def_id =
DefId { krate: local_id_root.krate, index: closure_expr_id.local_def_index }; DefId { krate: local_id_root.krate, index: closure_expr_id.local_def_index };
( (
@ -1153,7 +1155,7 @@ impl<'tcx> TyCtxt<'tcx> {
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default(); let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
for (k, v) in resolutions.trait_map { for (k, v) in resolutions.trait_map {
let hir_id = definitions.node_to_hir_id(k); let hir_id = definitions.node_to_hir_id(k);
let map = trait_map.entry(hir_id.owner_local_def_id()).or_default(); let map = trait_map.entry(hir_id.owner).or_default();
let v = v let v = v
.into_iter() .into_iter()
.map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id))) .map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id)))
@ -2635,22 +2637,19 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx StableVec<TraitCandidate>> { pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx StableVec<TraitCandidate>> {
self.in_scope_traits_map(id.owner_local_def_id()).and_then(|map| map.get(&id.local_id)) self.in_scope_traits_map(id.owner).and_then(|map| map.get(&id.local_id))
} }
pub fn named_region(self, id: HirId) -> Option<resolve_lifetime::Region> { pub fn named_region(self, id: HirId) -> Option<resolve_lifetime::Region> {
self.named_region_map(id.owner_local_def_id()) self.named_region_map(id.owner).and_then(|map| map.get(&id.local_id).cloned())
.and_then(|map| map.get(&id.local_id).cloned())
} }
pub fn is_late_bound(self, id: HirId) -> bool { pub fn is_late_bound(self, id: HirId) -> bool {
self.is_late_bound_map(id.owner_local_def_id()) self.is_late_bound_map(id.owner).map(|set| set.contains(&id.local_id)).unwrap_or(false)
.map(|set| set.contains(&id.local_id))
.unwrap_or(false)
} }
pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> { pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {
self.object_lifetime_defaults_map(id.owner_local_def_id()) self.object_lifetime_defaults_map(id.owner)
.and_then(|map| map.get(&id.local_id).map(|v| &**v)) .and_then(|map| map.get(&id.local_id).map(|v| &**v))
} }
} }

View file

@ -384,7 +384,9 @@ impl Visibility {
Res::Err => Visibility::Public, Res::Err => Visibility::Public,
def => Visibility::Restricted(def.def_id()), def => Visibility::Restricted(def.def_id()),
}, },
hir::VisibilityKind::Inherited => Visibility::Restricted(tcx.parent_module(id)), hir::VisibilityKind::Inherited => {
Visibility::Restricted(tcx.parent_module(id).to_def_id())
}
} }
} }
@ -3117,7 +3119,7 @@ impl<'tcx> TyCtxt<'tcx> {
Some(actual_expansion) => { Some(actual_expansion) => {
self.hir().definitions().parent_module_of_macro_def(actual_expansion) self.hir().definitions().parent_module_of_macro_def(actual_expansion)
} }
None => self.parent_module(block), None => self.parent_module(block).to_def_id(),
}; };
(ident, scope) (ident, scope)
} }

View file

@ -11,7 +11,6 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, Once}; use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, Once};
use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
use rustc_serialize::{ use rustc_serialize::{
@ -661,25 +660,6 @@ impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for CacheDecoder<'a, 'tcx> {
} }
} }
impl<'a, 'tcx> SpecializedDecoder<hir::HirId> for CacheDecoder<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<hir::HirId, Self::Error> {
// Load the `DefPathHash` which is what we encoded the `DefIndex` as.
let def_path_hash = DefPathHash::decode(self)?;
// Use the `DefPathHash` to map to the current `DefId`.
let def_id = self.tcx().def_path_hash_to_def_id.as_ref().unwrap()[&def_path_hash];
debug_assert!(def_id.is_local());
// The `ItemLocalId` needs no remapping.
let local_id = hir::ItemLocalId::decode(self)?;
// Reconstruct the `HirId` and look up the corresponding `NodeId` in the
// context of the current session.
Ok(hir::HirId { owner: def_id.index, local_id })
}
}
impl<'a, 'tcx> SpecializedDecoder<Fingerprint> for CacheDecoder<'a, 'tcx> { impl<'a, 'tcx> SpecializedDecoder<Fingerprint> for CacheDecoder<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<Fingerprint, Self::Error> { fn specialized_decode(&mut self) -> Result<Fingerprint, Self::Error> {
Fingerprint::decode_opaque(&mut self.opaque) Fingerprint::decode_opaque(&mut self.opaque)
@ -873,21 +853,6 @@ where
} }
} }
impl<'a, 'tcx, E> SpecializedEncoder<hir::HirId> for CacheEncoder<'a, 'tcx, E>
where
E: 'a + TyEncoder,
{
#[inline]
fn specialized_encode(&mut self, id: &hir::HirId) -> Result<(), Self::Error> {
let hir::HirId { owner, local_id } = *id;
let def_path_hash = self.tcx.hir().definitions().def_path_hash(owner);
def_path_hash.encode(self)?;
local_id.encode(self)
}
}
impl<'a, 'tcx, E> SpecializedEncoder<DefId> for CacheEncoder<'a, 'tcx, E> impl<'a, 'tcx, E> SpecializedEncoder<DefId> for CacheEncoder<'a, 'tcx, E>
where where
E: 'a + TyEncoder, E: 'a + TyEncoder,

View file

@ -425,10 +425,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
UseTreeKind::Nested(ref trees) => { UseTreeKind::Nested(ref trees) => {
for &(ref use_tree, id) in trees { for &(ref use_tree, id) in trees {
let hir_id = self.lctx.allocate_hir_id_counter(id); let hir_id = self.lctx.allocate_hir_id_counter(id);
self.allocate_use_tree_hir_id_counters( self.allocate_use_tree_hir_id_counters(use_tree, hir_id.owner);
use_tree,
hir_id.owner_local_def_id(),
);
} }
} }
} }
@ -479,10 +476,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count); self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count);
} }
ItemKind::Use(ref use_tree) => { ItemKind::Use(ref use_tree) => {
self.allocate_use_tree_hir_id_counters( self.allocate_use_tree_hir_id_counters(use_tree, hir_id.owner);
use_tree,
hir_id.owner_local_def_id(),
);
} }
_ => {} _ => {}
} }
@ -626,14 +620,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// properly. Calling the method twice with the same `NodeId` is fine though. /// properly. Calling the method twice with the same `NodeId` is fine though.
fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId { fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId {
self.lower_node_id_generic(ast_node_id, |this| { self.lower_node_id_generic(ast_node_id, |this| {
let &mut (def_id, ref mut local_id_counter) = let &mut (owner, ref mut local_id_counter) =
this.current_hir_id_owner.last_mut().unwrap(); this.current_hir_id_owner.last_mut().unwrap();
let local_id = *local_id_counter; let local_id = *local_id_counter;
*local_id_counter += 1; *local_id_counter += 1;
hir::HirId { hir::HirId { owner, local_id: hir::ItemLocalId::from_u32(local_id) }
owner: def_id.local_def_index,
local_id: hir::ItemLocalId::from_u32(local_id),
}
}) })
} }
@ -651,12 +642,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
debug_assert!(local_id != HIR_ID_COUNTER_LOCKED); debug_assert!(local_id != HIR_ID_COUNTER_LOCKED);
*local_id_counter += 1; *local_id_counter += 1;
let def_index = this.resolver.definitions().opt_def_index(owner).expect( let owner = this
"you forgot to call `create_def_with_parent` or are lowering node-IDs \ .resolver
that do not belong to the current owner", .definitions()
); .opt_local_def_id(owner)
.expect(
"you forgot to call `create_def_with_parent` or are lowering node-IDs \
that do not belong to the current owner",
)
.expect_local();
hir::HirId { owner: def_index, local_id: hir::ItemLocalId::from_u32(local_id) } hir::HirId { owner, local_id: hir::ItemLocalId::from_u32(local_id) }
}) })
} }

View file

@ -1,9 +1,8 @@
use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
use rustc_serialize::{self, Decodable, Decoder, Encodable, Encoder};
use std::fmt; use std::fmt;
/// Uniquely identifies a node in the HIR of the current crate. It is /// Uniquely identifies a node in the HIR of the current crate. It is
/// composed of the `owner`, which is the `DefIndex` of the directly enclosing /// composed of the `owner`, which is the `LocalDefId` of the directly enclosing
/// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"), /// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"),
/// and the `local_id` which is unique within the given owner. /// and the `local_id` which is unique within the given owner.
/// ///
@ -12,41 +11,12 @@ use std::fmt;
/// the `local_id` part of the `HirId` changing, which is a very useful property in /// the `local_id` part of the `HirId` changing, which is a very useful property in
/// incremental compilation where we have to persist things through changes to /// incremental compilation where we have to persist things through changes to
/// the code base. /// the code base.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, RustcEncodable, RustcDecodable)]
pub struct HirId { pub struct HirId {
pub owner: DefIndex, pub owner: LocalDefId,
pub local_id: ItemLocalId, pub local_id: ItemLocalId,
} }
impl HirId {
pub fn owner_def_id(self) -> DefId {
DefId::local(self.owner)
}
pub fn owner_local_def_id(self) -> LocalDefId {
LocalDefId { local_def_index: self.owner }
}
}
impl rustc_serialize::UseSpecializedEncodable for HirId {
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
let HirId { owner, local_id } = *self;
owner.encode(s)?;
local_id.encode(s)?;
Ok(())
}
}
impl rustc_serialize::UseSpecializedDecodable for HirId {
fn default_decode<D: Decoder>(d: &mut D) -> Result<HirId, D::Error> {
let owner = DefIndex::decode(d)?;
let local_id = ItemLocalId::decode(d)?;
Ok(HirId { owner, local_id })
}
}
impl fmt::Display for HirId { impl fmt::Display for HirId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self) write!(f, "{:?}", self)
@ -70,9 +40,12 @@ rustc_index::newtype_index! {
rustc_data_structures::impl_stable_hash_via_hash!(ItemLocalId); rustc_data_structures::impl_stable_hash_via_hash!(ItemLocalId);
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`. /// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`.
pub const CRATE_HIR_ID: HirId = pub const CRATE_HIR_ID: HirId = HirId {
HirId { owner: CRATE_DEF_INDEX, local_id: ItemLocalId::from_u32(0) }; owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
local_id: ItemLocalId::from_u32(0),
};
pub const DUMMY_HIR_ID: HirId = HirId { owner: CRATE_DEF_INDEX, local_id: DUMMY_ITEM_LOCAL_ID }; pub const DUMMY_HIR_ID: HirId =
HirId { owner: LocalDefId { local_def_index: CRATE_DEF_INDEX }, local_id: DUMMY_ITEM_LOCAL_ID };
pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX; pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;

View file

@ -29,7 +29,7 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
let def_path_hash = hcx.local_def_path_hash(self.owner); let def_path_hash = hcx.local_def_path_hash(self.owner.local_def_index);
(def_path_hash, self.local_id) (def_path_hash, self.local_id)
} }
} }

View file

@ -140,7 +140,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
} }
} }
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Not }) => { TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Not }) => {
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner_def_id()) { if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner.to_def_id()) {
if cx.tcx.impl_trait_ref(impl_did).is_some() { if cx.tcx.impl_trait_ref(impl_did).is_some() {
return; return;
} }

View file

@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
) -> bool { ) -> bool {
if ty.is_unit() if ty.is_unit()
|| cx.tcx.is_ty_uninhabited_from( || cx.tcx.is_ty_uninhabited_from(
cx.tcx.parent_module(expr.hir_id), cx.tcx.parent_module(expr.hir_id).to_def_id(),
ty, ty,
cx.param_env, cx.param_env,
) )

View file

@ -1350,7 +1350,7 @@ impl EncodeContext<'tcx> {
let is_proc_macro = self.tcx.sess.crate_types.borrow().contains(&CrateType::ProcMacro); let is_proc_macro = self.tcx.sess.crate_types.borrow().contains(&CrateType::ProcMacro);
if is_proc_macro { if is_proc_macro {
let tcx = self.tcx; let tcx = self.tcx;
Some(self.lazy(tcx.hir().krate().proc_macros.iter().map(|p| p.owner))) Some(self.lazy(tcx.hir().krate().proc_macros.iter().map(|p| p.owner.local_def_index)))
} else { } else {
None None
} }

View file

@ -776,7 +776,7 @@ fn for_each_late_bound_region_defined_on<'tcx>(
) { ) {
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.expect_local()) { if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
for late_bound in late_bounds.iter() { for late_bound in late_bounds.iter() {
let hir_id = HirId { owner: fn_def_id.index, local_id: *late_bound }; let hir_id = HirId { owner: fn_def_id.expect_local(), local_id: *late_bound };
let name = tcx.hir().name(hir_id); let name = tcx.hir().name(hir_id);
let region_def_id = tcx.hir().local_def_id(hir_id); let region_def_id = tcx.hir().local_def_id(hir_id);
let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion { let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion {

View file

@ -145,7 +145,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
fn check_in_cx(&self, hir_id: HirId, f: impl FnOnce(MatchCheckCtxt<'_, 'tcx>)) { fn check_in_cx(&self, hir_id: HirId, f: impl FnOnce(MatchCheckCtxt<'_, 'tcx>)) {
let module = self.tcx.parent_module(hir_id); let module = self.tcx.parent_module(hir_id);
MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |cx| f(cx)); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module.to_def_id(), |cx| f(cx));
} }
fn check_match( fn check_match(

View file

@ -1128,7 +1128,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
} }
hir::ExprKind::Call(ref f, ref args) => { hir::ExprKind::Call(ref f, ref args) => {
let m = self.ir.tcx.parent_module(expr.hir_id); let m = self.ir.tcx.parent_module(expr.hir_id).to_def_id();
let succ = if self.ir.tcx.is_ty_uninhabited_from( let succ = if self.ir.tcx.is_ty_uninhabited_from(
m, m,
self.tables.expr_ty(expr), self.tables.expr_ty(expr),
@ -1143,7 +1143,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
} }
hir::ExprKind::MethodCall(.., ref args) => { hir::ExprKind::MethodCall(.., ref args) => {
let m = self.ir.tcx.parent_module(expr.hir_id); let m = self.ir.tcx.parent_module(expr.hir_id).to_def_id();
let succ = if self.ir.tcx.is_ty_uninhabited_from( let succ = if self.ir.tcx.is_ty_uninhabited_from(
m, m,
self.tables.expr_ty(expr), self.tables.expr_ty(expr),

View file

@ -46,7 +46,7 @@ fn method_might_be_inlined(
impl_item: &hir::ImplItem<'_>, impl_item: &hir::ImplItem<'_>,
impl_src: DefId, impl_src: DefId,
) -> bool { ) -> bool {
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner_def_id()); let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner.to_def_id());
let generics = tcx.generics_of(tcx.hir().local_def_id(impl_item.hir_id)); let generics = tcx.generics_of(tcx.hir().local_def_id(impl_item.hir_id));
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) { if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
return true; return true;

View file

@ -327,7 +327,7 @@ fn def_id_visibility<'tcx>(
} }
Node::Expr(expr) => { Node::Expr(expr) => {
return ( return (
ty::Visibility::Restricted(tcx.parent_module(expr.hir_id)), ty::Visibility::Restricted(tcx.parent_module(expr.hir_id).to_def_id()),
expr.span, expr.span,
"private", "private",
); );

View file

@ -302,15 +302,15 @@ fn resolve_lifetimes(tcx: TyCtxt<'_>, for_krate: CrateNum) -> &ResolveLifetimes
let mut rl = ResolveLifetimes::default(); let mut rl = ResolveLifetimes::default();
for (hir_id, v) in named_region_map.defs { for (hir_id, v) in named_region_map.defs {
let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default(); let map = rl.defs.entry(hir_id.owner).or_default();
map.insert(hir_id.local_id, v); map.insert(hir_id.local_id, v);
} }
for hir_id in named_region_map.late_bound { for hir_id in named_region_map.late_bound {
let map = rl.late_bound.entry(hir_id.owner_local_def_id()).or_default(); let map = rl.late_bound.entry(hir_id.owner).or_default();
map.insert(hir_id.local_id); map.insert(hir_id.local_id);
} }
for (hir_id, v) in named_region_map.object_lifetime_defaults { for (hir_id, v) in named_region_map.object_lifetime_defaults {
let map = rl.object_lifetime_defaults.entry(hir_id.owner_local_def_id()).or_default(); let map = rl.object_lifetime_defaults.entry(hir_id.owner).or_default();
map.insert(hir_id.local_id, v); map.insert(hir_id.local_id, v);
} }

View file

@ -215,11 +215,22 @@ rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
/// few cases where we know that only DefIds from the local crate are expected /// few cases where we know that only DefIds from the local crate are expected
/// and a DefId from a different crate would signify a bug somewhere. This /// and a DefId from a different crate would signify a bug somewhere. This
/// is when LocalDefId comes in handy. /// is when LocalDefId comes in handy.
#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LocalDefId { pub struct LocalDefId {
pub local_def_index: DefIndex, pub local_def_index: DefIndex,
} }
impl Idx for LocalDefId {
#[inline]
fn new(idx: usize) -> Self {
LocalDefId { local_def_index: Idx::new(idx) }
}
#[inline]
fn index(self) -> usize {
self.local_def_index.index()
}
}
impl LocalDefId { impl LocalDefId {
#[inline] #[inline]
pub fn to_def_id(self) -> DefId { pub fn to_def_id(self) -> DefId {

View file

@ -1287,7 +1287,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let parent = hir.get_parent_node(expr_id); let parent = hir.get_parent_node(expr_id);
if let Some(hir::Node::Expr(e)) = hir.find(parent) { if let Some(hir::Node::Expr(e)) = hir.find(parent) {
let parent_span = hir.span(parent); let parent_span = hir.span(parent);
let parent_did = parent.owner_def_id(); let parent_did = parent.owner.to_def_id();
// ```rust // ```rust
// impl T { // impl T {
// fn foo(&self) -> i32 {} // fn foo(&self) -> i32 {}

View file

@ -185,7 +185,7 @@ fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]>
.filter_map(|pred| { .filter_map(|pred| {
match pred { match pred {
hir::WherePredicate::BoundPredicate(pred) hir::WherePredicate::BoundPredicate(pred)
if pred.bounded_ty.hir_id.owner_def_id() == trait_def_id => if pred.bounded_ty.hir_id.owner.to_def_id() == trait_def_id =>
{ {
// Fetch spans for trait bounds that are Sized: // Fetch spans for trait bounds that are Sized:
// `trait T where Self: Pred` // `trait T where Self: Pred`

View file

@ -1631,7 +1631,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) { fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
let generics = self.tcx.generics_of(self.body_id.owner_def_id()); let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
let generic_param = generics.type_param(&param, self.tcx); let generic_param = generics.type_param(&param, self.tcx);
if let ty::GenericParamDefKind::Type { synthetic: Some(..), .. } = generic_param.kind { if let ty::GenericParamDefKind::Type { synthetic: Some(..), .. } = generic_param.kind {
return; return;

View file

@ -427,7 +427,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}); });
if let Some((field, field_ty)) = field_receiver { if let Some((field, field_ty)) = field_receiver {
let scope = self.tcx.parent_module(self.body_id); let scope = self.tcx.parent_module(self.body_id).to_def_id();
let is_accessible = field.vis.is_accessible_from(scope, self.tcx); let is_accessible = field.vis.is_accessible_from(scope, self.tcx);
if is_accessible { if is_accessible {
@ -828,7 +828,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
candidates: Vec<DefId>, candidates: Vec<DefId>,
) { ) {
let module_did = self.tcx.parent_module(self.body_id); let module_did = self.tcx.parent_module(self.body_id);
let module_id = self.tcx.hir().as_local_hir_id(module_did).unwrap(); let module_id = self.tcx.hir().as_local_hir_id(module_did.to_def_id()).unwrap();
let krate = self.tcx.hir().krate(); let krate = self.tcx.hir().krate();
let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id); let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id);
if let Some(span) = span { if let Some(span) = span {

View file

@ -639,7 +639,7 @@ pub struct InheritedBuilder<'tcx> {
impl Inherited<'_, 'tcx> { impl Inherited<'_, 'tcx> {
pub fn build(tcx: TyCtxt<'tcx>, def_id: DefId) -> InheritedBuilder<'tcx> { pub fn build(tcx: TyCtxt<'tcx>, def_id: DefId) -> InheritedBuilder<'tcx> {
let hir_id_root = if let Some(def_id) = def_id.as_local() { let hir_id_root = if let Some(def_id) = def_id.as_local() {
tcx.hir().local_def_id_to_hir_id(def_id).owner_def_id() tcx.hir().local_def_id_to_hir_id(def_id).owner.to_def_id()
} else { } else {
def_id def_id
}; };
@ -1127,7 +1127,7 @@ fn typeck_tables_of_with_fallback<'tcx>(
// Consistency check our TypeckTables instance can hold all ItemLocalIds // Consistency check our TypeckTables instance can hold all ItemLocalIds
// it will need to hold. // it will need to hold.
assert_eq!(tables.local_id_root, Some(DefId::local(id.owner))); assert_eq!(tables.local_id_root, Some(id.owner.to_def_id()));
tables tables
} }

View file

@ -9,7 +9,7 @@ use rustc::ty::fold::{TypeFoldable, TypeFolder};
use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::{self, Ty, TyCtxt};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, DefIdSet}; use rustc_hir::def_id::DefIdSet;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
@ -107,11 +107,11 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
body: &'tcx hir::Body<'tcx>, body: &'tcx hir::Body<'tcx>,
rustc_dump_user_substs: bool, rustc_dump_user_substs: bool,
) -> WritebackCx<'cx, 'tcx> { ) -> WritebackCx<'cx, 'tcx> {
let owner = body.id().hir_id; let owner = body.id().hir_id.owner;
WritebackCx { WritebackCx {
fcx, fcx,
tables: ty::TypeckTables::empty(Some(DefId::local(owner.owner))), tables: ty::TypeckTables::empty(Some(owner.to_def_id())),
body, body,
rustc_dump_user_substs, rustc_dump_user_substs,
} }
@ -342,7 +342,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let common_local_id_root = fcx_tables.local_id_root.unwrap(); let common_local_id_root = fcx_tables.local_id_root.unwrap();
for (&id, &origin) in fcx_tables.closure_kind_origins().iter() { for (&id, &origin) in fcx_tables.closure_kind_origins().iter() {
let hir_id = hir::HirId { owner: common_local_id_root.index, local_id: id }; let hir_id = hir::HirId { owner: common_local_id_root.expect_local(), local_id: id };
self.tables.closure_kind_origins_mut().insert(hir_id, origin); self.tables.closure_kind_origins_mut().insert(hir_id, origin);
} }
} }
@ -364,7 +364,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let mut errors_buffer = Vec::new(); let mut errors_buffer = Vec::new();
for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() { for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() {
let hir_id = hir::HirId { owner: common_local_id_root.index, local_id }; let hir_id = hir::HirId { owner: common_local_id_root.expect_local(), local_id };
if cfg!(debug_assertions) && c_ty.has_local_value() { if cfg!(debug_assertions) && c_ty.has_local_value() {
span_bug!(hir_id.to_span(self.fcx.tcx), "writeback: `{:?}` is a local value", c_ty); span_bug!(hir_id.to_span(self.fcx.tcx), "writeback: `{:?}` is a local value", c_ty);
@ -557,7 +557,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let common_local_id_root = fcx_tables.local_id_root.unwrap(); let common_local_id_root = fcx_tables.local_id_root.unwrap();
for (&local_id, fn_sig) in fcx_tables.liberated_fn_sigs().iter() { for (&local_id, fn_sig) in fcx_tables.liberated_fn_sigs().iter() {
let hir_id = hir::HirId { owner: common_local_id_root.index, local_id }; let hir_id = hir::HirId { owner: common_local_id_root.expect_local(), local_id };
let fn_sig = self.resolve(fn_sig, &hir_id); let fn_sig = self.resolve(fn_sig, &hir_id);
self.tables.liberated_fn_sigs_mut().insert(hir_id, fn_sig.clone()); self.tables.liberated_fn_sigs_mut().insert(hir_id, fn_sig.clone());
} }
@ -569,7 +569,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let common_local_id_root = fcx_tables.local_id_root.unwrap(); let common_local_id_root = fcx_tables.local_id_root.unwrap();
for (&local_id, ftys) in fcx_tables.fru_field_types().iter() { for (&local_id, ftys) in fcx_tables.fru_field_types().iter() {
let hir_id = hir::HirId { owner: common_local_id_root.index, local_id }; let hir_id = hir::HirId { owner: common_local_id_root.expect_local(), local_id };
let ftys = self.resolve(ftys, &hir_id); let ftys = self.resolve(ftys, &hir_id);
self.tables.fru_field_types_mut().insert(hir_id, ftys); self.tables.fru_field_types_mut().insert(hir_id, ftys);
} }

View file

@ -348,7 +348,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| { let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| {
// FIXME: this fails hard for impls in non-module scope, but is necessary for the // FIXME: this fails hard for impls in non-module scope, but is necessary for the
// current `resolve()` implementation. // current `resolve()` implementation.
match self.cx.as_local_hir_id(self.cx.tcx.parent_module(hir_id)).unwrap() { match self.cx.as_local_hir_id(self.cx.tcx.parent_module(hir_id).to_def_id()).unwrap() {
id if id != hir_id => Some(id), id if id != hir_id => Some(id),
_ => None, _ => None,
} }