Skip to content

merge as_local_hir_id with local_def_id_to_hir_id #75448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl CodegenCx<'ll, 'tcx> {
debug!("get_static: sym={} instance={:?}", sym, instance);

let g = if let Some(def_id) = def_id.as_local() {
let id = self.tcx.hir().as_local_hir_id(def_id);
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let llty = self.layout_of(ty).llvm_type(self);
// FIXME: refactor this to work without accessing the HIR
let (g, attrs) = match self.tcx.hir().get(id) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ fn upstream_drop_glue_for_provider<'tcx>(

fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(def_id) = def_id.as_local() {
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id))
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().local_def_id_to_hir_id(def_id))
} else {
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
}
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,6 @@ impl Definitions {
})
}

#[inline]
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId {
self.local_def_id_to_hir_id(def_id)
}

#[inline]
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
self.def_id_to_hir_id[id].unwrap()
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn msg_span_from_early_bound_and_free_regions(
let sm = tcx.sess.source_map();

let scope = region.free_region_binding_scope(tcx);
let node = tcx.hir().as_local_hir_id(scope.expect_local());
let node = tcx.hir().local_def_id_to_hir_id(scope.expect_local());
let tag = match tcx.hir().find(node) {
Some(Node::Block(_) | Node::Expr(_)) => "body",
Some(Node::Item(it)) => item_scope_tag(&it),
Expand Down Expand Up @@ -1707,7 +1707,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.in_progress_typeck_results
.map(|typeck_results| typeck_results.borrow().hir_owner)
.map(|owner| {
let hir_id = hir.as_local_hir_id(owner);
let hir_id = hir.local_def_id_to_hir_id(owner);
let parent_id = hir.get_parent_item(hir_id);
(
// Parent item could be a `mod`, so we check the HIR before calling:
Expand All @@ -1733,7 +1733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
// instead we suggest `T: 'a + 'b` in that case.
let id = hir.as_local_hir_id(def_id);
let id = hir.local_def_id_to_hir_id(def_id);
let mut has_bounds = false;
if let Node::GenericParam(param) = hir.get(id) {
has_bounds = !param.bounds.is_empty();
Expand Down Expand Up @@ -1786,7 +1786,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.and_then(|(_, g)| g.params.first())
.and_then(|param| param.def_id.as_local())
.map(|def_id| {
(hir.span(hir.as_local_hir_id(def_id)).shrink_to_lo(), format!("{}, ", new_lt))
(
hir.span(hir.local_def_id_to_hir_id(def_id)).shrink_to_lo(),
format!("{}, ", new_lt),
)
});

let labeled_user_string = match bound_kind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
br: &ty::BoundRegion,
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let hir_id = self.tcx().hir().as_local_hir_id(anon_reg.def_id);
let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id);
let fndecl = match self.tcx().hir().get(hir_id) {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
| Node::TraitItem(&hir::TraitItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
match assoc_item.kind {
ty::AssocKind::Fn => {
let hir = self.tcx().hir();
if let Some(hir_id) = assoc_item.def_id.as_local().map(|id| hir.as_local_hir_id(id))
if let Some(hir_id) =
assoc_item.def_id.as_local().map(|id| hir.local_def_id_to_hir_id(id))
{
if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) {
visitor.visit_fn_decl(decl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
};

let hir = &self.tcx().hir();
let hir_id = hir.as_local_hir_id(id.as_local()?);
let hir_id = hir.local_def_id_to_hir_id(id.as_local()?);
let body_id = hir.maybe_body_owned_by(hir_id)?;
let body = hir.body(body_id);
let owner_id = hir.body_owner(body_id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
// reported for missing docs.
let real_trait = trait_ref.path.res.def_id();
if let Some(def_id) = real_trait.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id);
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in items {
Expand Down Expand Up @@ -614,7 +614,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
cx.tcx.for_each_impl(debug, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
if let Some(def_id) = ty_def.did.as_local() {
impls.insert(cx.tcx.hir().as_local_hir_id(def_id));
impls.insert(cx.tcx.hir().local_def_id_to_hir_id(def_id));
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
param_env: ty::ParamEnv::empty(),
access_levels,
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id),
last_node_with_lint_attrs: tcx.hir().local_def_id_to_hir_id(module_def_id),
generics: None,
only_module: true,
};
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ impl EncodeContext<'a, 'tcx> {
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};

let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
let enum_vis = &tcx.hir().expect_item(enum_id).vis;

record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
Expand Down Expand Up @@ -780,7 +780,7 @@ impl EncodeContext<'a, 'tcx> {

// Variant constructors have the same visibility as the parent enums, unless marked as
// non-exhaustive, in which case they are lowered to `pub(crate)`.
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx);
if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public {
Expand Down Expand Up @@ -819,11 +819,11 @@ impl EncodeContext<'a, 'tcx> {
let data = ModData {
reexports: match tcx.module_exports(local_def_id) {
Some(exports) => {
let hir_map = self.tcx.hir();
let hir = self.tcx.hir();
self.lazy(
exports
.iter()
.map(|export| export.map_id(|id| hir_map.as_local_hir_id(id))),
.map(|export| export.map_id(|id| hir.local_def_id_to_hir_id(id))),
)
}
_ => Lazy::empty(),
Expand Down Expand Up @@ -855,7 +855,7 @@ impl EncodeContext<'a, 'tcx> {
let def_id = field.did;
debug!("EncodeContext::encode_field({:?})", def_id);

let variant_id = tcx.hir().as_local_hir_id(variant.def_id.expect_local());
let variant_id = tcx.hir().local_def_id_to_hir_id(variant.def_id.expect_local());
let variant_data = tcx.hir().expect_variant_data(variant_id);

record!(self.tables.kind[def_id] <- EntryKind::Field);
Expand Down Expand Up @@ -883,7 +883,7 @@ impl EncodeContext<'a, 'tcx> {
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};

let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local());
let struct_id = tcx.hir().local_def_id_to_hir_id(adt_def.did.expect_local());
let struct_vis = &tcx.hir().expect_item(struct_id).vis;
let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx);
for field in &variant.fields {
Expand Down Expand Up @@ -945,7 +945,7 @@ impl EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
let tcx = self.tcx;

let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let ast_item = tcx.hir().expect_trait_item(hir_id);
let trait_item = tcx.associated_item(def_id);

Expand Down Expand Up @@ -1034,7 +1034,7 @@ impl EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
let tcx = self.tcx;

let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let ast_item = self.tcx.hir().expect_impl_item(hir_id);
let impl_item = self.tcx.associated_item(def_id);

Expand Down Expand Up @@ -1438,7 +1438,7 @@ impl EncodeContext<'a, 'tcx> {

// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
// including on the signature, which is inferred in `typeck.
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let ty = self.tcx.typeck(def_id).node_type(hir_id);

record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
Expand All @@ -1465,7 +1465,7 @@ impl EncodeContext<'a, 'tcx> {

fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) {
debug!("EncodeContext::encode_info_for_anon_const({:?})", def_id);
let id = self.tcx.hir().as_local_hir_id(def_id);
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let body_id = self.tcx.hir().body_owned_by(id);
let const_data = self.encode_rendered_const_for_body(body_id);
let qualifs = self.tcx.mir_const_qualif(def_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
}

fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
def_id == hir_id.owner
}
11 changes: 3 additions & 8 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ impl<'hir> Map<'hir> {
self.tcx.definitions.opt_hir_id_to_local_def_id(hir_id)
}

#[inline]
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.as_local_hir_id(def_id)
}

#[inline]
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.local_def_id_to_hir_id(def_id)
Expand Down Expand Up @@ -450,7 +445,7 @@ impl<'hir> Map<'hir> {
}

pub fn get_module(&self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
let hir_id = self.as_local_hir_id(module);
let hir_id = self.local_def_id_to_hir_id(module);
match self.get_entry(hir_id).node {
Node::Item(&Item { span, kind: ItemKind::Mod(ref m), .. }) => (m, span, hir_id),
Node::Crate(item) => (&item.module, item.span, hir_id),
Expand Down Expand Up @@ -483,7 +478,7 @@ impl<'hir> Map<'hir> {
}

pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
id.as_local().map(|id| self.get(self.as_local_hir_id(id)))
id.as_local().map(|id| self.get(self.local_def_id_to_hir_id(id)))
}

pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
Expand Down Expand Up @@ -872,7 +867,7 @@ impl<'hir> Map<'hir> {
}

pub fn span_if_local(&self, id: DefId) -> Option<Span> {
id.as_local().map(|id| self.span(self.as_local_hir_id(id)))
id.as_local().map(|id| self.span(self.local_def_id_to_hir_id(id)))
}

pub fn res_span(&self, res: Res) -> Option<Span> {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_middle/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn provide(providers: &mut Providers) {
providers.parent_module_from_def_id = |tcx, id| {
let hir = tcx.hir();
hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id)))
hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)))
};
providers.hir_crate = |tcx, _| tcx.untracked_crate;
providers.index_hir = map::index_hir;
providers.hir_module_items = |tcx, id| {
let hir = tcx.hir();
let module = hir.as_local_hir_id(id);
let module = hir.local_def_id_to_hir_id(id);
&tcx.untracked_crate.modules[&module]
};
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
providers.fn_arg_names = |tcx, id| {
let hir = tcx.hir();
let hir_id = hir.as_local_hir_id(id.expect_local());
let hir_id = hir.local_def_id_to_hir_id(id.expect_local());
if let Some(body_id) = hir.maybe_body_owned_by(hir_id) {
tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
} else if let Node::TraitItem(&TraitItem {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {

AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
let substs = tcx.lift(&substs).unwrap();
format!(
Expand Down Expand Up @@ -2155,7 +2155,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {

AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
let mut struct_fmt = fmt.debug_struct(&name);

Expand Down
13 changes: 7 additions & 6 deletions src/librustc_middle/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ impl<'tcx> MonoItem<'tcx> {
pub fn local_span(&self, tcx: TyCtxt<'tcx>) -> Option<Span> {
match *self {
MonoItem::Fn(Instance { def, .. }) => {
def.def_id().as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
def.def_id().as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
}
MonoItem::Static(def_id) => {
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
}
MonoItem::GlobalAsm(hir_id) => Some(hir_id),
}
Expand Down Expand Up @@ -346,9 +346,10 @@ impl<'tcx> CodegenUnit<'tcx> {
// instances into account. The others don't matter for
// the codegen tests and can even make item order
// unstable.
InstanceDef::Item(def) => {
def.did.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
}
InstanceDef::Item(def) => def
.did
.as_local()
.map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)),
InstanceDef::VtableShim(..)
| InstanceDef::ReifyShim(..)
| InstanceDef::Intrinsic(..)
Expand All @@ -360,7 +361,7 @@ impl<'tcx> CodegenUnit<'tcx> {
}
}
MonoItem::Static(def_id) => {
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
}
MonoItem::GlobalAsm(hir_id) => Some(hir_id),
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ rustc_queries! {
/// per-type-parameter predicates for resolving `T::AssocTy`.
query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing the bounds for type parameter `{}`", {
let id = tcx.hir().as_local_hir_id(key.1);
let id = tcx.hir().local_def_id_to_hir_id(key.1);
tcx.hir().ty_param_name(id)
}}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'tcx> Const<'tcx> {
ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => {
// Find the name and index of the const parameter by indexing the generics of
// the parent item and construct a `ParamConst`.
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let item_id = tcx.hir().get_parent_node(hir_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id.to_def_id());
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ impl<'tcx> TyCtxt<'tcx> {
_ => return None, // not a free region
};

let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope);
let hir_id = self.hir().local_def_id_to_hir_id(suitable_region_binding_scope);
let is_impl_item = match self.hir().find(hir_id) {
Some(Node::Item(..) | Node::TraitItem(..)) => false,
Some(Node::ImplItem(..)) => {
Expand All @@ -1441,7 +1441,7 @@ impl<'tcx> TyCtxt<'tcx> {
&self,
scope_def_id: LocalDefId,
) -> Vec<&'tcx hir::Ty<'tcx>> {
let hir_id = self.hir().as_local_hir_id(scope_def_id);
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
let hir_output = match self.hir().get(hir_id) {
Node::Item(hir::Item {
kind:
Expand Down Expand Up @@ -1486,7 +1486,7 @@ impl<'tcx> TyCtxt<'tcx> {

pub fn return_type_impl_trait(&self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx>, Span)> {
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
let hir_id = self.hir().as_local_hir_id(scope_def_id);
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
match self.hir().get(hir_id) {
Node::Item(item) => {
match item.kind {
Expand Down
Loading