Skip to content

Commit

Permalink
rename hir::map::local_def_id to local_def_id_from_node_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Jul 4, 2019
1 parent 7987719 commit 4f7ba51
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/dep_tracking_map.rs
Expand Up @@ -55,7 +55,7 @@ impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
///
/// ```
/// fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
/// let item_def_id = ccx.tcx.hir().local_def_id(it.id);
/// let item_def_id = ccx.tcx.hir().local_def_id_from_node_id(it.id);
/// ccx.tcx.item_types.memoized(item_def_id, || {
/// ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
/// compute_type_of_item(ccx, item)
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/hir/map/hir_id_validator.rs
Expand Up @@ -10,7 +10,8 @@ pub fn check_crate(hir_map: &hir::map::Map<'_>) {
let errors = Lock::new(Vec::new());

par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
hir_map.visit_item_likes_in_module(hir_map.local_def_id(*module_id), &mut OuterVisitor {
let local_def_id = hir_map.local_def_id_from_node_id(*module_id);
hir_map.visit_item_likes_in_module(local_def_id, &mut OuterVisitor {
hir_map,
errors: &errors,
});
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -231,10 +231,10 @@ impl<'hir> Map<'hir> {
}

#[inline]
pub fn local_def_id(&self, node: NodeId) -> DefId {
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
self.opt_local_def_id(node).unwrap_or_else(|| {
let hir_id = self.node_to_hir_id(node);
bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`",
bug!("local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
node, self.find_entry(hir_id))
})
}
Expand Down
Expand Up @@ -140,7 +140,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
// region at the right depth with the same index
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
debug!(
"EarlyBound self.infcx.tcx.hir().local_def_id(id)={:?} \
"EarlyBound self.infcx.tcx.hir().local_def_id_from_node_id(id)={:?} \
def_id={:?}",
id,
def_id
Expand All @@ -162,7 +162,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
debruijn_index
);
debug!("self.infcx.tcx.hir().local_def_id(id)={:?}", id);
debug!("self.infcx.tcx.hir().local_def_id_from_node_id(id)={:?}", id);
debug!("def_id={:?}", def_id);
if debruijn_index == self.current_index && id == def_id {
self.found_type = Some(arg);
Expand Down Expand Up @@ -232,7 +232,7 @@ impl Visitor<'tcx> for TyPathVisitor<'tcx> {

(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
debug!(
"EarlyBound self.infcx.tcx.hir().local_def_id(id)={:?} \
"EarlyBound self.infcx.tcx.hir().local_def_id_from_node_id(id)={:?} \
def_id={:?}",
id,
def_id
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/context.rs
Expand Up @@ -1500,7 +1500,7 @@ pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
time(tcx.sess, "module lints", || {
// Run per-module lints
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().lint_mod(tcx.hir().local_def_id(module));
tcx.ensure().lint_mod(tcx.hir().local_def_id_from_node_id(module));
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/context.rs
Expand Up @@ -1304,15 +1304,15 @@ impl<'tcx> TyCtxt<'tcx> {
maybe_unused_trait_imports:
resolutions.maybe_unused_trait_imports
.into_iter()
.map(|id| hir.local_def_id(id))
.map(|id| hir.local_def_id_from_node_id(id))
.collect(),
maybe_unused_extern_crates:
resolutions.maybe_unused_extern_crates
.into_iter()
.map(|(id, sp)| (hir.local_def_id(id), sp))
.map(|(id, sp)| (hir.local_def_id_from_node_id(id), sp))
.collect(),
glob_map: resolutions.glob_map.into_iter().map(|(id, names)| {
(hir.local_def_id(id), names)
(hir.local_def_id_from_node_id(id), names)
}).collect(),
extern_prelude: resolutions.extern_prelude,
hir_map: hir,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/pretty.rs
Expand Up @@ -887,7 +887,7 @@ fn print_with_analysis(
let mut print = || match ppm {
PpmMir | PpmMirCFG => {
if let Some(nodeid) = nodeid {
let def_id = tcx.hir().local_def_id(nodeid);
let def_id = tcx.hir().local_def_id_from_node_id(nodeid);
match ppm {
PpmMir => write_mir_pretty(tcx, Some(def_id), &mut out),
PpmMirCFG => write_mir_graphviz(tcx, Some(def_id), &mut out),
Expand Down
13 changes: 7 additions & 6 deletions src/librustc_interface/passes.rs
Expand Up @@ -899,9 +899,10 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
});
}, {
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().check_mod_loops(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_attrs(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_unstable_api_usage(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_loops(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_attrs(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_unstable_api_usage(
tcx.hir().local_def_id_from_node_id(module));
});
});
});
Expand All @@ -924,9 +925,9 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
// "not all control paths return a value" is reported here.
//
// maybe move the check to a MIR pass?
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id_from_node_id(module));

tcx.ensure().check_mod_intrinsics(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_intrinsics(tcx.hir().local_def_id_from_node_id(module));
});
});
});
Expand Down Expand Up @@ -986,7 +987,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
}, {
time(sess, "privacy checking modules", || {
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id_from_node_id(module));
});
});
});
Expand Down
22 changes: 11 additions & 11 deletions src/librustc_save_analysis/dump_visitor.rs
Expand Up @@ -123,7 +123,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
where
F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>),
{
let item_def_id = self.tcx.hir().local_def_id(item_id);
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id);
if self.tcx.has_typeck_tables(item_def_id) {
let tables = self.tcx.typeck_tables_of(item_def_id);
let old_tables = self.save_ctxt.tables;
Expand Down Expand Up @@ -436,7 +436,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
attrs: &'l [Attribute],
) {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));

if !self.span.filter_generated(ident.span) {
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
Expand Down Expand Up @@ -481,7 +481,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
debug!("process_struct {:?} {:?}", item, item.span);
let name = item.ident.to_string();
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));

let kind = match item.node {
ast::ItemKind::Struct(_, _) => DefKind::Struct,
Expand Down Expand Up @@ -683,7 +683,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
self.process_generic_params(generics, "", item.id);
for impl_item in impl_items {
let map = &self.tcx.hir();
self.process_impl_item(impl_item, map.local_def_id(item.id));
self.process_impl_item(impl_item, map.local_def_id_from_node_id(item.id));
}
}

Expand All @@ -696,7 +696,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
) {
let name = item.ident.to_string();
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
let mut val = name.clone();
if !generics.params.is_empty() {
val.push_str(&generic_params_to_string(&generics.params));
Expand Down Expand Up @@ -764,7 +764,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
self.process_generic_params(generics, &qualname, item.id);
for method in methods {
let map = &self.tcx.hir();
self.process_trait_item(method, map.local_def_id(item.id))
self.process_trait_item(method, map.local_def_id_from_node_id(item.id))
}
}

Expand Down Expand Up @@ -1109,7 +1109,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
// FIXME do something with _bounds (for type refs)
let name = trait_item.ident.name.to_string();
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(trait_item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(trait_item.id)));

if !self.span.filter_generated(trait_item.ident.span) {
let span = self.span_from_span(trait_item.ident.span);
Expand Down Expand Up @@ -1261,7 +1261,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
};

// Make a comma-separated list of names of imported modules.
let def_id = self.tcx.hir().local_def_id(id);
let def_id = self.tcx.hir().local_def_id_from_node_id(id);
let names = self.tcx.names_imported_by_glob_use(def_id);
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();

Expand Down Expand Up @@ -1318,7 +1318,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, '
assert_eq!(id, ast::CRATE_NODE_ID);

let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));

let cm = self.tcx.sess.source_map();
let filename = cm.span_to_filename(span);
Expand Down Expand Up @@ -1408,7 +1408,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, '
}
Ty(ref ty, ref ty_params) => {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
let value = ty_to_string(&ty);
if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span);
Expand Down Expand Up @@ -1439,7 +1439,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, '
}
Existential(ref _bounds, ref ty_params) => {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
// FIXME do something with _bounds
let value = String::new();
if !self.span.filter_generated(item.ident.span) {
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_save_analysis/lib.rs
Expand Up @@ -135,7 +135,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {

pub fn get_extern_item_data(&self, item: &ast::ForeignItem) -> Option<Data> {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
match item.node {
ast::ForeignItemKind::Fn(ref decl, ref generics) => {
filter!(self.span_utils, item.ident.span);
Expand Down Expand Up @@ -186,7 +186,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
match item.node {
ast::ItemKind::Fn(ref decl, .., ref generics, _) => {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
filter!(self.span_utils, item.ident.span);
Some(Data::DefData(Def {
kind: DefKind::Function,
Expand All @@ -205,7 +205,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
}
ast::ItemKind::Static(ref typ, ..) => {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));

filter!(self.span_utils, item.ident.span);

Expand All @@ -229,7 +229,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
}
ast::ItemKind::Const(ref typ, _) => {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
filter!(self.span_utils, item.ident.span);

let id = id_from_node_id(item.id, self);
Expand All @@ -252,7 +252,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
}
ast::ItemKind::Mod(ref m) => {
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));

let cm = self.tcx.sess.source_map();
let filename = cm.span_to_filename(m.inner);
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
ast::ItemKind::Enum(ref def, _) => {
let name = item.ident.to_string();
let qualname = format!("::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
filter!(self.span_utils, item.ident.span);
let variants_str = def.variants
.iter()
Expand Down Expand Up @@ -365,10 +365,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
if let Some(ident) = field.ident {
let name = ident.to_string();
let qualname = format!("::{}::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id(scope)),
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(scope)),
ident);
filter!(self.span_utils, ident.span);
let def_id = self.tcx.hir().local_def_id(field.id);
let def_id = self.tcx.hir().local_def_id_from_node_id(field.id);
let typ = self.tcx.type_of(def_id).to_string();


Expand Down Expand Up @@ -400,7 +400,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
// The qualname for a method is the trait name or name of the struct in an impl in
// which the method is declared in, followed by the method's name.
let (qualname, parent_scope, decl_id, docs, attributes) =
match self.tcx.impl_of_method(self.tcx.hir().local_def_id(id)) {
match self.tcx.impl_of_method(self.tcx.hir().local_def_id_from_node_id(id)) {
Some(impl_id) => match self.tcx.hir().get_if_local(impl_id) {
Some(Node::Item(item)) => match item.node {
hir::ItemKind::Impl(.., ref ty, _) => {
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
);
}
},
None => match self.tcx.trait_of_item(self.tcx.hir().local_def_id(id)) {
None => match self.tcx.trait_of_item(self.tcx.hir().local_def_id_from_node_id(id)) {
Some(def_id) => {
let mut docs = String::new();
let mut attrs = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/impl_wf_check.rs
Expand Up @@ -54,7 +54,7 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
// but it's one that we must perform earlier than the rest of
// WfCheck.
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id_from_node_id(module));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/lib.rs
Expand Up @@ -310,7 +310,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
tcx.sess.track_errors(|| {
time(tcx.sess, "type collecting", || {
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
}
});
})?;
Expand Down Expand Up @@ -345,7 +345,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {

time(tcx.sess, "item-types checking", || {
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
}
});

Expand Down
7 changes: 4 additions & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -654,7 +654,7 @@ impl Clean<Item> for doctree::Module<'_> {
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
def_id: cx.tcx.hir().local_def_id_from_node_id(self.id),
inner: ModuleItem(Module {
is_crate: self.is_crate,
items,
Expand Down Expand Up @@ -2982,10 +2982,11 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
ty::FnPtr(_) => {
let ty = cx.tcx.lift(self).expect("FnPtr lift failed");
let sig = ty.fn_sig(cx.tcx);
let local_def_id = cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID);
BareFunction(box BareFunctionDecl {
unsafety: sig.unsafety(),
generic_params: Vec::new(),
decl: (cx.tcx.hir().local_def_id(ast::CRATE_NODE_ID), sig).clean(cx),
decl: (local_def_id, sig).clean(cx),
abi: sig.abi(),
})
}
Expand Down Expand Up @@ -3991,7 +3992,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
name: None,
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
def_id: cx.tcx.hir().local_def_id(ast::CRATE_NODE_ID),
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID),
visibility: self.vis.clean(cx),
stability: None,
deprecation: None,
Expand Down

0 comments on commit 4f7ba51

Please sign in to comment.