Skip to content

Commit

Permalink
hir: remove NodeId from Item
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Mar 2, 2019
1 parent 3c25193 commit 77fa041
Show file tree
Hide file tree
Showing 42 changed files with 208 additions and 212 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/check_attr.rs
Expand Up @@ -94,7 +94,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
/// Checks any attribute.
fn check_attributes(&self, item: &hir::Item, target: Target) {
if target == Target::Fn || target == Target::Const {
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(item.id));
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id_from_hir_id(item.hir_id));
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
.span_label(item.span, "not a function")
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/hir/lowering.rs
Expand Up @@ -1414,7 +1414,6 @@ impl<'a> LoweringContext<'a> {

trace!("exist ty def index: {:#?}", exist_ty_def_index);
let exist_ty_item = hir::Item {
id: exist_ty_id.node_id,
hir_id: exist_ty_id.hir_id,
ident: keywords::Invalid.ident(),
attrs: Default::default(),
Expand Down Expand Up @@ -3128,7 +3127,6 @@ impl<'a> LoweringContext<'a> {
this.insert_item(
new_id.node_id,
hir::Item {
id: new_id.node_id,
hir_id: new_id.hir_id,
ident,
attrs: attrs.clone(),
Expand Down Expand Up @@ -3234,7 +3232,6 @@ impl<'a> LoweringContext<'a> {
this.insert_item(
new_id,
hir::Item {
id: new_id,
hir_id: new_hir_id,
ident,
attrs: attrs.clone(),
Expand Down Expand Up @@ -3534,10 +3531,9 @@ impl<'a> LoweringContext<'a> {

let node = self.lower_item_kind(i.id, &mut ident, &attrs, &mut vis, &i.node);

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(i.id);

Some(hir::Item {
id: node_id,
hir_id,
ident,
attrs,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Expand Up @@ -356,7 +356,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_item(&mut self, i: &'hir Item) {
debug!("visit_item: {:?}", i);
debug_assert_eq!(i.hir_id.owner,
self.definitions.opt_def_index(i.id).unwrap());
self.definitions.opt_def_index(self.hir_to_node_id[&i.hir_id]).unwrap());
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
this.insert(i.span, i.hir_id, Node::Item(i));
this.with_parent(i.hir_id, |this| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Expand Up @@ -319,7 +319,7 @@ impl<'hir> Map<'hir> {

match node {
Node::Item(item) => {
let def_id = || self.local_def_id(item.id);
let def_id = || self.local_def_id_from_hir_id(item.hir_id);

match item.node {
ItemKind::Static(_, m, _) => Some(Def::Static(def_id(), m == MutMutable)),
Expand Down
1 change: 0 additions & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -2221,7 +2221,6 @@ pub struct ItemId {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Item {
pub ident: Ident,
pub id: NodeId,
pub hir_id: HirId,
pub attrs: HirVec<Attribute>,
pub node: ItemKind,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ich/impls_hir.rs
Expand Up @@ -856,7 +856,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
let hir::Item {
ident,
ref attrs,
id: _,
hir_id: _,
ref node,
ref vis,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -152,7 +152,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
Node::Item(item) => {
match item.node {
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
let def_id = self.tcx.hir().local_def_id(item.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let def = self.tcx.adt_def(def_id);
self.repr_has_repr_c = def.repr.c();

Expand Down
33 changes: 16 additions & 17 deletions src/librustc/middle/entry.rs
Expand Up @@ -2,11 +2,10 @@ use crate::hir::map as hir_map;
use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
use crate::session::{config, Session};
use crate::session::config::EntryFnType;
use syntax::ast::NodeId;
use syntax::attr;
use syntax::entry::EntryPointType;
use syntax_pos::Span;
use crate::hir::{Item, ItemKind, ImplItem, TraitItem};
use crate::hir::{HirId, Item, ItemKind, ImplItem, TraitItem};
use crate::hir::itemlikevisit::ItemLikeVisitor;
use crate::ty::TyCtxt;
use crate::ty::query::Providers;
Expand All @@ -17,22 +16,22 @@ struct EntryContext<'a, 'tcx: 'a> {
map: &'a hir_map::Map<'tcx>,

// The top-level function called 'main'
main_fn: Option<(NodeId, Span)>,
main_fn: Option<(HirId, Span)>,

// The function that has attribute named 'main'
attr_main_fn: Option<(NodeId, Span)>,
attr_main_fn: Option<(HirId, Span)>,

// The function that has the attribute 'start' on it
start_fn: Option<(NodeId, Span)>,
start_fn: Option<(HirId, Span)>,

// The functions that one might think are 'main' but aren't, e.g.
// main functions not defined at the top level. For diagnostics.
non_main_fns: Vec<(NodeId, Span)> ,
non_main_fns: Vec<(HirId, Span)> ,
}

impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
fn visit_item(&mut self, item: &'tcx Item) {
let def_id = self.map.local_def_id(item.id);
let def_id = self.map.local_def_id_from_hir_id(item.hir_id);
let def_key = self.map.def_key(def_id);
let at_root = def_key.parent == Some(CRATE_DEF_INDEX);
find_item(item, self, at_root);
Expand Down Expand Up @@ -106,18 +105,18 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
match entry_point_type(item, at_root) {
EntryPointType::MainNamed => {
if ctxt.main_fn.is_none() {
ctxt.main_fn = Some((item.id, item.span));
ctxt.main_fn = Some((item.hir_id, item.span));
} else {
span_err!(ctxt.session, item.span, E0136,
"multiple 'main' functions");
}
},
EntryPointType::OtherMain => {
ctxt.non_main_fns.push((item.id, item.span));
ctxt.non_main_fns.push((item.hir_id, item.span));
},
EntryPointType::MainAttr => {
if ctxt.attr_main_fn.is_none() {
ctxt.attr_main_fn = Some((item.id, item.span));
ctxt.attr_main_fn = Some((item.hir_id, item.span));
} else {
struct_span_err!(ctxt.session, item.span, E0137,
"multiple functions with a #[main] attribute")
Expand All @@ -128,7 +127,7 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
},
EntryPointType::Start => {
if ctxt.start_fn.is_none() {
ctxt.start_fn = Some((item.id, item.span));
ctxt.start_fn = Some((item.hir_id, item.span));
} else {
struct_span_err!(ctxt.session, item.span, E0138, "multiple 'start' functions")
.span_label(ctxt.start_fn.unwrap().1, "previous `start` function here")
Expand All @@ -144,12 +143,12 @@ fn configure_main(
tcx: TyCtxt<'_, '_, '_>,
visitor: &EntryContext<'_, '_>,
) -> Option<(DefId, EntryFnType)> {
if let Some((node_id, _)) = visitor.start_fn {
Some((tcx.hir().local_def_id(node_id), EntryFnType::Start))
} else if let Some((node_id, _)) = visitor.attr_main_fn {
Some((tcx.hir().local_def_id(node_id), EntryFnType::Main))
} else if let Some((node_id, _)) = visitor.main_fn {
Some((tcx.hir().local_def_id(node_id), EntryFnType::Main))
if let Some((hir_id, _)) = visitor.start_fn {
Some((tcx.hir().local_def_id_from_hir_id(hir_id), EntryFnType::Start))
} else if let Some((hir_id, _)) = visitor.attr_main_fn {
Some((tcx.hir().local_def_id_from_hir_id(hir_id), EntryFnType::Main))
} else if let Some((hir_id, _)) = visitor.main_fn {
Some((tcx.hir().local_def_id_from_hir_id(hir_id), EntryFnType::Main))
} else {
// No main function
let mut err = struct_err!(tcx.sess, E0601,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lang_items.rs
Expand Up @@ -98,7 +98,7 @@ impl<'a, 'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'a, 'tcx> {
match self.item_refs.get(&*value.as_str()).cloned() {
// Known lang item with attribute on correct target.
Some((item_index, expected_target)) if actual_target == expected_target => {
let def_id = self.tcx.hir().local_def_id(item.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
self.collect_item(item_index, def_id);
},
// Known lang item with attribute on incorrect target.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/reachable.rs
Expand Up @@ -36,7 +36,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'a, 'tcx, 'tcx>,
match item.node {
hir::ItemKind::Impl(..) |
hir::ItemKind::Fn(..) => {
let generics = tcx.generics_of(tcx.hir().local_def_id(item.id));
let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(item.hir_id));
generics.requires_monomorphization(tcx)
}
_ => false,
Expand Down Expand Up @@ -344,7 +344,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
// Anything which has custom linkage gets thrown on the worklist no
// matter where it is in the crate, along with "special std symbols"
// which are currently akin to allocator symbols.
let def_id = self.tcx.hir().local_def_id(item.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
if codegen_attrs.contains_extern_indicator() ||
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) {
Expand Down
15 changes: 7 additions & 8 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -13,7 +13,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};

use crate::rustc::lint;
use crate::session::Session;
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet, NodeMap};
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet};
use errors::{Applicability, DiagnosticBuilder};
use rustc_data_structures::sync::Lrc;
use std::borrow::Cow;
Expand Down Expand Up @@ -204,7 +204,7 @@ struct NamedRegionMap {

// For each type and trait definition, maps type parameters
// to the trait object lifetime defaults computed from them.
pub object_lifetime_defaults: NodeMap<Vec<ObjectLifetimeDefault>>,
pub object_lifetime_defaults: HirIdMap<Vec<ObjectLifetimeDefault>>,
}

/// See [`NamedRegionMap`].
Expand Down Expand Up @@ -395,8 +395,7 @@ fn resolve_lifetimes<'tcx>(
.or_default();
Lrc::get_mut(map).unwrap().insert(hir_id.local_id);
}
for (k, v) in named_region_map.object_lifetime_defaults {
let hir_id = tcx.hir().node_to_hir_id(k);
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();
Expand Down Expand Up @@ -1266,8 +1265,8 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {

fn compute_object_lifetime_defaults(
tcx: TyCtxt<'_, '_, '_>,
) -> NodeMap<Vec<ObjectLifetimeDefault>> {
let mut map = NodeMap::default();
) -> HirIdMap<Vec<ObjectLifetimeDefault>> {
let mut map = HirIdMap::default();
for item in tcx.hir().krate().items.values() {
match item.node {
hir::ItemKind::Struct(_, ref generics)
Expand Down Expand Up @@ -1311,7 +1310,7 @@ fn compute_object_lifetime_defaults(
tcx.sess.span_err(item.span, &object_lifetime_default_reprs);
}

map.insert(item.id, result);
map.insert(item.hir_id, result);
}
_ => {}
}
Expand Down Expand Up @@ -1959,7 +1958,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
};

let map = &self.map;
let unsubst = if let Some(id) = self.tcx.hir().as_local_node_id(def_id) {
let unsubst = if let Some(id) = self.tcx.hir().as_local_hir_id(def_id) {
&map.object_lifetime_defaults[&id]
} else {
let tcx = self.tcx;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Expand Up @@ -761,7 +761,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
// compiler-generated `extern crate` items have a dummy span.
if item.span.is_dummy() { return }

let def_id = self.tcx.hir().local_def_id(item.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
Some(cnum) => cnum,
None => return,
Expand Down Expand Up @@ -791,7 +791,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
// There's no good place to insert stability check for non-Copy unions,
// so semi-randomly perform it here in stability.rs
hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => {
let def_id = self.tcx.hir().local_def_id(item.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let adt_def = self.tcx.adt_def(def_id);
let ty = self.tcx.type_of(def_id);

Expand Down
12 changes: 8 additions & 4 deletions src/librustc/ty/mod.rs
Expand Up @@ -260,7 +260,7 @@ impl<'a, 'gcx, 'tcx> DefIdTree for TyCtxt<'a, 'gcx, 'tcx> {
}

impl Visibility {
pub fn from_hir(visibility: &hir::Visibility, id: NodeId, tcx: TyCtxt<'_, '_, '_>) -> Self {
pub fn from_hir(visibility: &hir::Visibility, id: hir::HirId, tcx: TyCtxt<'_, '_, '_>) -> Self {
match visibility.node {
hir::VisibilityKind::Public => Visibility::Public,
hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
Expand All @@ -271,7 +271,7 @@ impl Visibility {
def => Visibility::Restricted(def.def_id()),
},
hir::VisibilityKind::Inherited => {
Visibility::Restricted(tcx.hir().get_module_parent(id))
Visibility::Restricted(tcx.hir().get_module_parent_by_hir_id(id))
}
}
}
Expand Down Expand Up @@ -2737,11 +2737,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
hir::AssociatedItemKind::Existential => bug!("only impls can have existentials"),
};

let hir_id = self.hir().node_to_hir_id(trait_item_ref.id.node_id);

AssociatedItem {
ident: trait_item_ref.ident,
kind,
// Visibility of trait items is inherited from their traits.
vis: Visibility::from_hir(parent_vis, trait_item_ref.id.node_id, self),
vis: Visibility::from_hir(parent_vis, hir_id, self),
defaultness: trait_item_ref.defaultness,
def_id,
container: TraitContainer(parent_def_id),
Expand All @@ -2763,11 +2765,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
hir::AssociatedItemKind::Existential => (ty::AssociatedKind::Existential, false),
};

let hir_id = self.hir().node_to_hir_id(impl_item_ref.id.node_id);

AssociatedItem {
ident: impl_item_ref.ident,
kind,
// Visibility of trait impl items doesn't matter.
vis: ty::Visibility::from_hir(&impl_item_ref.vis, impl_item_ref.id.node_id, self),
vis: ty::Visibility::from_hir(&impl_item_ref.vis, hir_id, self),
defaultness: impl_item_ref.defaultness,
def_id,
container: ImplContainer(parent_def_id),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/pretty.rs
Expand Up @@ -408,8 +408,8 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
pprust_hir::AnnNode::Name(_) => Ok(()),
pprust_hir::AnnNode::Item(item) => {
s.s.space()?;
s.synth_comment(format!("node_id: {} hir local_id: {}",
item.id, item.hir_id.local_id.as_u32()))
s.synth_comment(format!("hir_id: {} hir local_id: {}",
item.hir_id, item.hir_id.local_id.as_u32()))
}
pprust_hir::AnnNode::SubItem(id) => {
s.s.space()?;
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_interface/proc_macro_decls.rs
Expand Up @@ -3,7 +3,6 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc::hir;
use rustc::ty::TyCtxt;
use rustc::ty::query::Providers;
use syntax::ast;
use syntax::attr;

pub fn find<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option<DefId> {
Expand All @@ -19,17 +18,17 @@ fn proc_macro_decls_static<'tcx>(
let mut finder = Finder { decls: None };
tcx.hir().krate().visit_all_item_likes(&mut finder);

finder.decls.map(|id| tcx.hir().local_def_id(id))
finder.decls.map(|id| tcx.hir().local_def_id_from_hir_id(id))
}

struct Finder {
decls: Option<ast::NodeId>,
decls: Option<hir::HirId>,
}

impl<'v> ItemLikeVisitor<'v> for Finder {
fn visit_item(&mut self, item: &hir::Item) {
if attr::contains_name(&item.attrs, "rustc_proc_macro_decls") {
self.decls = Some(item.id);
self.decls = Some(item.hir_id);
}
}

Expand Down

0 comments on commit 77fa041

Please sign in to comment.