Rollup merge of #75448 - lcnr:rn-as_local_hir_id, r=davidtwco

merge `as_local_hir_id` with `local_def_id_to_hir_id`

`as_local_hir_id` was defined as just calling `local_def_id_to_hir_id` and I think that having two different ways to call the same method is somewhat confusing.

Don't really care about which of these 2 methods we want to keep.

Does this require an MCP, considering that these methods are fairly frequently used?
This commit is contained in:
Tyler Mandry 2020-08-14 20:07:11 -07:00 committed by GitHub
commit 28b11abc2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
82 changed files with 241 additions and 237 deletions

View File

@ -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) {

View File

@ -361,7 +361,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)
}

View File

@ -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()

View File

@ -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),
@ -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:
@ -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();
@ -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 {

View File

@ -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 {

View File

@ -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);

View File

@ -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);

View File

@ -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 {
@ -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));
}
}
});

View File

@ -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,
};

View File

@ -707,7 +707,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)));
@ -754,7 +754,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 {
@ -793,11 +793,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(),
@ -829,7 +829,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);
@ -857,7 +857,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 {
@ -919,7 +919,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);
@ -1008,7 +1008,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);
@ -1412,7 +1412,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 {
@ -1439,7 +1439,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);

View File

@ -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
}

View File

@ -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)
@ -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),
@ -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>> {
@ -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> {

View File

@ -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 {

View File

@ -2134,7 +2134,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!(
@ -2162,7 +2162,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);

View File

@ -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),
}
@ -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(..)
@ -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),
},

View File

@ -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)
}}
}

View File

@ -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());

View File

@ -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(..)) => {
@ -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:
@ -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 {

View File

@ -403,7 +403,7 @@ impl<'tcx> TyCtxt<'tcx> {
.type_param(p, self)
.def_id
.as_local()
.map(|id| hir.as_local_hir_id(id))
.map(|id| hir.local_def_id_to_hir_id(id))
.and_then(|id| self.hir().find(self.hir().get_parent_node(id)))
.as_ref()
.and_then(|node| node.generics())
@ -791,10 +791,11 @@ fn foo(&self) -> Self::T { String::new() }
body_owner_def_id: DefId,
found: Ty<'tcx>,
) -> bool {
let hir_id = match body_owner_def_id.as_local().map(|id| self.hir().as_local_hir_id(id)) {
Some(hir_id) => hir_id,
None => return false,
};
let hir_id =
match body_owner_def_id.as_local().map(|id| self.hir().local_def_id_to_hir_id(id)) {
Some(hir_id) => hir_id,
None => return false,
};
// When `body_owner` is an `impl` or `trait` item, look in its associated types for
// `expected` and point at it.
let parent_id = self.hir().get_parent_item(hir_id);

View File

@ -2835,12 +2835,12 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn opt_item_name(self, def_id: DefId) -> Option<Ident> {
def_id
.as_local()
.and_then(|def_id| self.hir().get(self.hir().as_local_hir_id(def_id)).ident())
.and_then(|def_id| self.hir().get(self.hir().local_def_id_to_hir_id(def_id)).ident())
}
pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> {
let is_associated_item = if let Some(def_id) = def_id.as_local() {
match self.hir().get(self.hir().as_local_hir_id(def_id)) {
match self.hir().get(self.hir().local_def_id_to_hir_id(def_id)) {
Node::TraitItem(_) | Node::ImplItem(_) => true,
_ => false,
}
@ -2999,7 +2999,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Gets the attributes of a definition.
pub fn get_attrs(self, did: DefId) -> Attributes<'tcx> {
if let Some(did) = did.as_local() {
self.hir().attrs(self.hir().as_local_hir_id(did))
self.hir().attrs(self.hir().local_def_id_to_hir_id(did))
} else {
self.item_attrs(did)
}
@ -3038,7 +3038,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// with the name of the crate containing the impl.
pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {
if let Some(impl_did) = impl_did.as_local() {
let hir_id = self.hir().as_local_hir_id(impl_did);
let hir_id = self.hir().local_def_id_to_hir_id(impl_did);
Ok(self.hir().span(hir_id))
} else {
Err(self.crate_name(impl_did.krate))
@ -3099,7 +3099,7 @@ pub struct AdtSizedConstraint<'tcx>(pub &'tcx [Ty<'tcx>]);
/// Yields the parent function's `DefId` if `def_id` is an `impl Trait` definition.
pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
if let Some(def_id) = def_id.as_local() {
if let Node::Item(item) = tcx.hir().get(tcx.hir().as_local_hir_id(def_id)) {
if let Node::Item(item) = tcx.hir().get(tcx.hir().local_def_id_to_hir_id(def_id)) {
if let hir::ItemKind::OpaqueTy(ref opaque_ty) = item.kind {
return opaque_ty.impl_trait_fn;
}

View File

@ -610,7 +610,7 @@ pub trait PrettyPrinter<'tcx>:
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
let hir_id = self.tcx().hir().as_local_hir_id(did);
let hir_id = self.tcx().hir().local_def_id_to_hir_id(did);
let span = self.tcx().hir().span(hir_id);
p!(write("@{}", self.tcx().sess.source_map().span_to_string(span)));
@ -656,7 +656,7 @@ pub trait PrettyPrinter<'tcx>:
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
let hir_id = self.tcx().hir().as_local_hir_id(did);
let hir_id = self.tcx().hir().local_def_id_to_hir_id(did);
if self.tcx().sess.opts.debugging_opts.span_free_formats {
p!(write("@"), print_def_path(did.to_def_id(), substs));
} else {

View File

@ -879,7 +879,7 @@ impl<'tcx> ty::TyS<'tcx> {
let span = match field
.did
.as_local()
.map(|id| tcx.hir().as_local_hir_id(id))
.map(|id| tcx.hir().local_def_id_to_hir_id(id))
.and_then(|id| tcx.hir().find(id))
{
Some(hir::Node::Field(field)) => field.ty.span,

View File

@ -263,7 +263,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let needs_note = match ty.kind {
ty::Closure(id, _) => {
let tables = self.infcx.tcx.typeck(id.expect_local());
let hir_id = self.infcx.tcx.hir().as_local_hir_id(id.expect_local());
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(id.expect_local());
tables.closure_kind_origins().get(hir_id).is_none()
}
@ -954,7 +954,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
format!("`{}` would have to be valid for `{}`...", name, region_name),
);
let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id);
let fn_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
err.span_label(
drop_span,
format!(
@ -1863,7 +1863,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
let is_closure = self.infcx.tcx.is_closure(did);
let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(did.as_local()?);
let fn_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did.as_local()?);
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
// We need to work out which arguments to highlight. We do this by looking

View File

@ -104,7 +104,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind {
let did = did.expect_local();
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did);
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);
if let Some((span, name)) =
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
@ -127,7 +127,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if let Some(target) = target {
if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind {
let did = did.expect_local();
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did);
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);
if let Some((span, name)) =
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
@ -937,7 +937,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
"closure_span: def_id={:?} target_place={:?} places={:?}",
def_id, target_place, places
);
let hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id.as_local()?);
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(def_id.as_local()?);
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr);
if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr {

View File

@ -492,7 +492,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_label(sp, format!("cannot {}", act));
let hir = self.infcx.tcx.hir();
let closure_id = hir.as_local_hir_id(self.mir_def_id);
let closure_id = hir.local_def_id_to_hir_id(self.mir_def_id);
let fn_call_id = hir.get_parent_node(closure_id);
let node = hir.get(fn_call_id);
let item_id = hir.enclosing_body_owner(fn_call_id);
@ -691,7 +691,7 @@ fn annotate_struct_field(
if let ty::Adt(def, _) = ty.kind {
let field = def.all_fields().nth(field.index())?;
// Use the HIR types to construct the diagnostic message.
let hir_id = tcx.hir().as_local_hir_id(field.did.as_local()?);
let hir_id = tcx.hir().local_def_id_to_hir_id(field.did.as_local()?);
let node = tcx.hir().find(hir_id)?;
// Now we're dealing with the actual struct that we're going to suggest a change to,
// we can expect a field that is an immutable reference to a type.

View File

@ -266,7 +266,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
}
ty::BoundRegion::BrEnv => {
let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id);
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let def_ty = self.regioncx.universal_regions().defining_ty;
if let DefiningTy::Closure(_, substs) = def_ty {
@ -361,7 +361,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
&self,
argument_index: usize,
) -> Option<&hir::Ty<'tcx>> {
let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id);
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
match argument_hir_ty.kind {
@ -648,7 +648,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
let type_name = self.infcx.extract_type_name(&return_ty, Some(highlight)).0;
let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id);
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) {
hir::Node::Expr(hir::Expr {
@ -700,7 +700,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
let type_name = self.infcx.extract_type_name(&yield_ty, Some(highlight)).0;
let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id);
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let yield_span = match tcx.hir().get(mir_hir_id) {
hir::Node::Expr(hir::Expr {

View File

@ -129,7 +129,7 @@ fn do_mir_borrowck<'a, 'tcx>(
let tcx = infcx.tcx;
let param_env = tcx.param_env(def.did);
let id = tcx.hir().as_local_hir_id(def.did);
let id = tcx.hir().local_def_id_to_hir_id(def.did);
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
for var_debug_info in &input_body.var_debug_info {

View File

@ -231,7 +231,7 @@ impl<'tcx> UniversalRegions<'tcx> {
param_env: ty::ParamEnv<'tcx>,
) -> Self {
let tcx = infcx.tcx;
let mir_hir_id = tcx.hir().as_local_hir_id(mir_def.did);
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(mir_def.did);
UniversalRegionsBuilder { infcx, mir_def, mir_hir_id, param_env }.build()
}

View File

@ -353,7 +353,7 @@ pub fn const_eval_raw_provider<'tcx>(
// validation thus preventing such a hard error from being a backwards
// compatibility hazard
DefKind::Const | DefKind::AssocConst => {
let hir_id = tcx.hir().as_local_hir_id(def.did);
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
err.report_as_lint(
tcx.at(tcx.def_span(def.did)),
"any use of this value will cause an error",
@ -376,7 +376,7 @@ pub fn const_eval_raw_provider<'tcx>(
err.report_as_lint(
tcx.at(span),
"reaching this expression at runtime will panic or abort",
tcx.hir().as_local_hir_id(def.did),
tcx.hir().local_def_id_to_hir_id(def.did),
Some(err.span),
)
}

View File

@ -90,7 +90,7 @@ pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
/// Checks whether the function has a `const` modifier or, in case it is an intrinsic, whether
/// said intrinsic has a `rustc_const_{un,}stable` attribute.
fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
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 node = tcx.hir().get(hir_id);

View File

@ -215,7 +215,7 @@ impl Validator<'mir, 'tcx> {
&& !tcx.is_thread_local_static(def_id.to_def_id());
if should_check_for_sync {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
check_return_ty_is_sync(tcx, &body, hir_id);
}
}

View File

@ -483,7 +483,7 @@ fn check_unused_unsafe(
used_unsafe: &FxHashSet<hir::HirId>,
unsafe_blocks: &mut Vec<(hir::HirId, bool)>,
) {
let body_id = tcx.hir().maybe_body_owned_by(tcx.hir().as_local_hir_id(def_id));
let body_id = tcx.hir().maybe_body_owned_by(tcx.hir().local_def_id_to_hir_id(def_id));
let body_id = match body_id {
Some(body) => body,
@ -511,7 +511,7 @@ fn unsafety_check_result<'tcx>(
let param_env = tcx.param_env(def.did);
let id = tcx.hir().as_local_hir_id(def.did);
let id = tcx.hir().local_def_id_to_hir_id(def.did);
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
hir::BodyOwnerKind::Closure => (false, false),
hir::BodyOwnerKind::Fn => {
@ -532,7 +532,7 @@ fn unsafety_check_result<'tcx>(
}
fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let lint_hir_id = tcx.hir().as_local_hir_id(def_id);
let lint_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
tcx.struct_span_lint_hir(SAFE_PACKED_BORROWS, lint_hir_id, tcx.def_span(def_id), |lint| {
// FIXME: when we make this a hard error, this should have its

View File

@ -67,7 +67,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
}
use rustc_middle::hir::map::blocks::FnLikeNode;
let hir_id = tcx.hir().as_local_hir_id(source.def_id().expect_local());
let hir_id = tcx.hir().local_def_id_to_hir_id(source.def_id().expect_local());
let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some();
let is_assoc_const = tcx.def_kind(source.def_id()) == DefKind::AssocConst;

View File

@ -75,7 +75,7 @@ impl Inliner<'tcx> {
let param_env = self.tcx.param_env_reveal_all_normalized(self.source.def_id());
// Only do inlining into fn bodies.
let id = self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local());
let id = self.tcx.hir().local_def_id_to_hir_id(self.source.def_id().expect_local());
if self.tcx.hir().body_owner_kind(id).is_fn_or_closure() && self.source.promoted.is_none() {
for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated() {
if let Some(callsite) =
@ -101,9 +101,9 @@ impl Inliner<'tcx> {
}
let callee_body = if let Some(callee_def_id) = callsite.callee.as_local() {
let callee_hir_id = self.tcx.hir().as_local_hir_id(callee_def_id);
let callee_hir_id = self.tcx.hir().local_def_id_to_hir_id(callee_def_id);
let self_hir_id =
self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local());
self.tcx.hir().local_def_id_to_hir_id(self.source.def_id().expect_local());
// Avoid a cycle here by only using `optimized_mir` only if we have
// a lower `HirId` than the callee. This ensures that the callee will
// not inline us. This trick only works without incremental compilation.

View File

@ -14,7 +14,7 @@ type McfResult = Result<(), (Span, Cow<'static, str>)>;
pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult {
// Prevent const trait methods from being annotated as `stable`.
if tcx.features().staged_api {
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());
if crate::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
return Err((body.span, "trait methods cannot be stable const fn".into()));
}

View File

@ -34,7 +34,7 @@ crate fn mir_built<'tcx>(
/// Construct the MIR for a given `DefId`.
fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_> {
let id = tcx.hir().as_local_hir_id(def.did);
let id = tcx.hir().local_def_id_to_hir_id(def.did);
// Figure out what primary body this item has.
let (body_id, return_ty_span) = match tcx.hir().get(id) {

View File

@ -11,7 +11,7 @@ use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
use rustc_span::Span;
crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: LocalDefId) {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) {
if let FnKind::Closure(_) = fn_like_node.kind() {
@ -37,7 +37,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: LocalDefId) {
vis.reachable_recursive_calls.sort();
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 sp = tcx.sess.source_map().guess_head_span(tcx.hir().span(hir_id));
tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| {
let mut db = lint.build("function cannot return without recursing");

View File

@ -781,7 +781,7 @@ fn convert_path_expr<'a, 'tcx>(
}
Res::Def(DefKind::ConstParam, def_id) => {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let item_id = cx.tcx.hir().get_parent_node(hir_id);
let item_def_id = cx.tcx.hir().local_def_id(item_id);
let generics = cx.tcx.generics_of(item_def_id);

View File

@ -23,7 +23,7 @@ use std::slice;
crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) {
let body_id = match def_id.as_local() {
None => return,
Some(id) => tcx.hir().body_owned_by(tcx.hir().as_local_hir_id(id)),
Some(id) => tcx.hir().body_owned_by(tcx.hir().local_def_id_to_hir_id(id)),
};
let mut visitor = MatchVisitor {

View File

@ -62,7 +62,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
fn check_def_id(&mut self, def_id: DefId) {
if let Some(def_id) = def_id.as_local() {
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);
if should_explore(self.tcx, hir_id) || self.struct_constructors.contains_key(&hir_id) {
self.worklist.push(hir_id);
}
@ -72,7 +72,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
fn insert_def_id(&mut self, def_id: DefId) {
if let Some(def_id) = def_id.as_local() {
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);
debug_assert!(!should_explore(self.tcx, hir_id));
self.live_symbols.insert(hir_id);
}
@ -461,7 +461,7 @@ fn create_and_seed_worklist<'tcx>(
)
.chain(
// Seed entry point
tcx.entry_fn(LOCAL_CRATE).map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id)),
tcx.entry_fn(LOCAL_CRATE).map(|(def_id, _)| tcx.hir().local_def_id_to_hir_id(def_id)),
)
.collect::<Vec<_>>();
@ -546,7 +546,7 @@ impl DeadVisitor<'tcx> {
for &impl_did in inherent_impls.iter() {
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
if let Some(did) = item_did.as_local() {
let item_hir_id = self.tcx.hir().as_local_hir_id(did);
let item_hir_id = self.tcx.hir().local_def_id_to_hir_id(did);
if self.live_symbols.contains(&item_hir_id) {
return true;
}

View File

@ -53,7 +53,7 @@ fn method_might_be_inlined(
return true;
}
}
match tcx.hir().find(tcx.hir().as_local_hir_id(impl_src)) {
match tcx.hir().find(tcx.hir().local_def_id_to_hir_id(impl_src)) {
Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs),
Some(..) | None => span_bug!(impl_item.span, "impl did is not an item"),
}
@ -106,7 +106,9 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
}
Some(res) => {
if let Some((hir_id, def_id)) = res.opt_def_id().and_then(|def_id| {
def_id.as_local().map(|def_id| (self.tcx.hir().as_local_hir_id(def_id), def_id))
def_id
.as_local()
.map(|def_id| (self.tcx.hir().local_def_id_to_hir_id(def_id), def_id))
}) {
if self.def_id_represents_local_inlined_item(def_id.to_def_id()) {
self.worklist.push(hir_id);
@ -149,7 +151,7 @@ impl<'tcx> ReachableContext<'tcx> {
// eligible for inlining and false otherwise.
fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool {
let hir_id = match def_id.as_local() {
Some(def_id) => self.tcx.hir().as_local_hir_id(def_id),
Some(def_id) => self.tcx.hir().local_def_id_to_hir_id(def_id),
None => {
return false;
}
@ -181,7 +183,7 @@ impl<'tcx> ReachableContext<'tcx> {
// Check the impl. If the generics on the self
// type of the impl require inlining, this method
// does too.
let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did);
let impl_hir_id = self.tcx.hir().local_def_id_to_hir_id(impl_did);
match self.tcx.hir().expect_item(impl_hir_id).kind {
hir::ItemKind::Impl { .. } => {
let generics = self.tcx.generics_of(impl_did);
@ -366,10 +368,10 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
// FIXME(#53488) remove `let`
let tcx = self.tcx;
self.worklist.extend(
tcx.provided_trait_methods(trait_def_id)
.map(|assoc| tcx.hir().as_local_hir_id(assoc.def_id.expect_local())),
);
self.worklist
.extend(tcx.provided_trait_methods(trait_def_id).map(|assoc| {
tcx.hir().local_def_id_to_hir_id(assoc.def_id.expect_local())
}));
}
}
}
@ -406,7 +408,7 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> &'tcx HirIdSet
reachable_context.worklist.extend(access_levels.map.iter().map(|(id, _)| *id));
for item in tcx.lang_items().items().iter() {
if let Some(did) = *item {
if let Some(hir_id) = did.as_local().map(|did| tcx.hir().as_local_hir_id(did)) {
if let Some(hir_id) = did.as_local().map(|did| tcx.hir().local_def_id_to_hir_id(did)) {
reachable_context.worklist.push(hir_id);
}
}

View File

@ -807,7 +807,7 @@ fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
return tcx.region_scope_tree(closure_base_def_id);
}
let id = tcx.hir().as_local_hir_id(def_id.expect_local());
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) {
let mut visitor = RegionResolutionVisitor {
tcx,

View File

@ -15,7 +15,7 @@ pub fn provide(providers: &mut Providers) {
return None;
}
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 body = tcx.hir().body(tcx.hir().maybe_body_owned_by(hir_id)?);
let mut local_collector = LocalCollector::default();

View File

@ -226,7 +226,7 @@ fn def_id_visibility<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
) -> (ty::Visibility, Span, &'static str) {
match def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) {
match def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) {
Some(hir_id) => {
let vis = match tcx.hir().get(hir_id) {
Node::Item(item) => &item.vis,
@ -431,7 +431,7 @@ impl VisibilityLike for Option<AccessLevel> {
fn new_min(find: &FindMin<'_, '_, Self>, def_id: DefId) -> Self {
cmp::min(
if let Some(def_id) = def_id.as_local() {
let hir_id = find.tcx.hir().as_local_hir_id(def_id);
let hir_id = find.tcx.hir().local_def_id_to_hir_id(def_id);
find.access_levels.map.get(&hir_id).cloned()
} else {
Self::MAX
@ -533,7 +533,7 @@ impl EmbargoVisitor<'tcx> {
if let Res::Def(def_kind, def_id) = export.res {
let vis = def_id_visibility(self.tcx, def_id).0;
if let Some(def_id) = def_id.as_local() {
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);
self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
}
}
@ -650,7 +650,7 @@ impl EmbargoVisitor<'tcx> {
// there will be no corresponding item.
.filter(|def_id| def_id.index != CRATE_DEF_INDEX || def_id.krate != LOCAL_CRATE)
.and_then(|def_id| {
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
def_id.as_local().map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id))
})
.map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id))
{
@ -913,7 +913,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
if export.vis == ty::Visibility::Public {
if let Some(def_id) = export.res.opt_def_id() {
if let Some(def_id) = def_id.as_local() {
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);
self.update(hir_id, Some(AccessLevel::Exported));
}
}
@ -1004,7 +1004,7 @@ impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
}
fn visit_def_id(&mut self, def_id: DefId, _kind: &str, _descr: &dyn fmt::Display) -> bool {
if let Some(def_id) = def_id.as_local() {
let hir_id = self.ev.tcx.hir().as_local_hir_id(def_id);
let hir_id = self.ev.tcx.hir().local_def_id_to_hir_id(def_id);
if let ((ty::Visibility::Public, ..), _)
| (_, Some(AccessLevel::ReachableFromImplTrait)) =
(def_id_visibility(self.tcx(), def_id.to_def_id()), self.access_level)
@ -1437,7 +1437,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
if let Some(did) = did.as_local() {
// .. and it corresponds to a private type in the AST (this returns
// `None` for type parameters).
match self.tcx.hir().find(self.tcx.hir().as_local_hir_id(did)) {
match self.tcx.hir().find(self.tcx.hir().local_def_id_to_hir_id(did)) {
Some(Node::Item(ref item)) => !item.vis.node.is_pub(),
Some(_) | None => false,
}
@ -1556,7 +1556,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
let did = tr.path.res.def_id();
if let Some(did) = did.as_local() {
self.trait_is_public(self.tcx.hir().as_local_hir_id(did))
self.trait_is_public(self.tcx.hir().local_def_id_to_hir_id(did))
} else {
true // external traits must be public
}
@ -1815,7 +1815,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> {
}
let hir_id = match def_id.as_local() {
Some(def_id) => self.tcx.hir().as_local_hir_id(def_id),
Some(def_id) => self.tcx.hir().local_def_id_to_hir_id(def_id),
None => return false,
};

View File

@ -607,7 +607,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
let def = self.map.defs.get(&lifetime.hir_id).cloned();
if let Some(Region::LateBound(_, def_id, _)) = def {
if let Some(def_id) = def_id.as_local() {
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);
// Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().get_parent_node(hir_id);
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
@ -1154,7 +1154,8 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
if let Some(def) =
lifetimes.get(&hir::ParamName::Plain(label.normalize_to_macros_2_0()))
{
let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap().expect_local());
let hir_id =
tcx.hir().local_def_id_to_hir_id(def.id().unwrap().expect_local());
signal_shadowing_problem(
tcx,
@ -1525,7 +1526,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
match lifetimeuseset {
Some(LifetimeUseSet::One(lifetime)) => {
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());
debug!("hir id first={:?}", hir_id);
if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) {
Node::Lifetime(hir_lifetime) => Some((
@ -1545,7 +1546,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if let Some(parent_def_id) = self.tcx.parent(def_id) {
if let Some(def_id) = parent_def_id.as_local() {
let parent_hir_id = self.tcx.hir().as_local_hir_id(def_id);
let parent_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
// lifetimes in `derive` expansions don't count (Issue #53738)
if self.tcx.hir().attrs(parent_hir_id).iter().any(|attr| {
self.tcx.sess.check_name(attr, sym::automatically_derived)
@ -1583,7 +1584,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
debug!("not one use lifetime");
}
None => {
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());
if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) {
Node::Lifetime(hir_lifetime) => Some((
hir_lifetime.hir_id,
@ -1939,7 +1940,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let map = &self.map;
let unsubst = 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);
&map.object_lifetime_defaults[&id]
} else {
let tcx = self.tcx;
@ -2637,7 +2638,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
Scope::Binder { ref lifetimes, s, .. } => {
if let Some(&def) = lifetimes.get(&param.name.normalize_to_macros_2_0()) {
let hir_id =
self.tcx.hir().as_local_hir_id(def.id().unwrap().expect_local());
self.tcx.hir().local_def_id_to_hir_id(def.id().unwrap().expect_local());
signal_shadowing_problem(
self.tcx,

View File

@ -173,7 +173,7 @@ fn compute_symbol_name(
let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
}
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
match tcx.hir().get(hir_id) {
Node::ForeignItem(_) => true,
_ => false,

View File

@ -1039,7 +1039,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
// }
// ```
if let Some(def_id) = def_id.as_local() {
let opaque_hir_id = tcx.hir().as_local_hir_id(def_id);
let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let parent_def_id = self.parent_def_id;
let def_scope_default = || {
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
@ -1205,7 +1205,7 @@ pub fn may_define_opaque_type(
def_id: LocalDefId,
opaque_hir_id: hir::HirId,
) -> bool {
let mut hir_id = tcx.hir().as_local_hir_id(def_id);
let mut hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
// Named opaque types can be defined by any siblings or children of siblings.
let scope = tcx.hir().get_defining_scope(opaque_hir_id);

View File

@ -41,7 +41,7 @@ fn environment<'tcx>(
let clauses = predicates.into_iter().map(ChalkEnvironmentClause::Predicate);
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 node = tcx.hir().get(hir_id);
enum NodeKind {

View File

@ -568,7 +568,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
self.tcx.sess.source_map().guess_head_span(
self.tcx.hir().span_if_local(closure_def_id).unwrap(),
);
let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id.expect_local());
let hir_id =
self.tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
let mut err = struct_span_err!(
self.tcx.sess,
closure_span,

View File

@ -535,7 +535,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
};
let hir = self.tcx.hir();
let hir_id = hir.as_local_hir_id(def_id.as_local()?);
let hir_id = hir.local_def_id_to_hir_id(def_id.as_local()?);
let parent_node = hir.get_parent_node(hir_id);
match hir.find(parent_node) {
Some(hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(local), .. })) => {
@ -1383,7 +1383,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let generator_body = generator_did
.as_local()
.map(|def_id| hir.as_local_hir_id(def_id))
.map(|def_id| hir.local_def_id_to_hir_id(def_id))
.and_then(|hir_id| hir.maybe_body_owned_by(hir_id))
.map(|body_id| hir.body(body_id));
let mut visitor = AwaitsVisitor::default();
@ -1535,7 +1535,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
.tcx
.parent(generator_did)
.and_then(|parent_did| parent_did.as_local())
.map(|parent_did| hir.as_local_hir_id(parent_did))
.map(|parent_did| hir.local_def_id_to_hir_id(parent_did))
.and_then(|parent_hir_id| hir.opt_name(parent_hir_id))
.map(|name| {
format!("future returned by `{}` is not {}", name, trait_name)

View File

@ -451,7 +451,7 @@ fn report_conflicting_impls(
};
tcx.struct_span_lint_hir(
lint,
tcx.hir().as_local_hir_id(impl_def_id),
tcx.hir().local_def_id_to_hir_id(impl_def_id),
impl_span,
decorate,
)

View File

@ -126,7 +126,7 @@ fn associated_item_from_impl_item_ref(
}
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
let id = tcx.hir().as_local_hir_id(def_id.expect_local());
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let parent_id = tcx.hir().get_parent_item(id);
let parent_def_id = tcx.hir().local_def_id(parent_id);
let parent_item = tcx.hir().expect_item(parent_id);
@ -164,7 +164,7 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
}
fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness {
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 = tcx.hir().expect_item(hir_id);
if let hir::ItemKind::Impl { defaultness, .. } = item.kind {
defaultness
@ -198,7 +198,7 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtSizedConstrain
}
fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
let id = tcx.hir().as_local_hir_id(def_id.expect_local());
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let item = tcx.hir().expect_item(id);
match item.kind {
hir::ItemKind::Trait(.., ref trait_item_refs) => tcx.arena.alloc_from_iter(
@ -268,7 +268,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
let body_id = def_id
.as_local()
.map(|def_id| tcx.hir().as_local_hir_id(def_id))
.map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
.map_or(hir::CRATE_HIR_ID, |id| {
tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id)
});
@ -360,7 +360,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
/// Check if a function is async.
fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
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 node = tcx.hir().get(hir_id);

View File

@ -170,7 +170,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
def: Option<&ty::GenericParamDef>,
) -> ty::Region<'tcx> {
let tcx = self.tcx();
let lifetime_name = |def_id| tcx.hir().name(tcx.hir().as_local_hir_id(def_id));
let lifetime_name = |def_id| tcx.hir().name(tcx.hir().local_def_id_to_hir_id(def_id));
let r = match tcx.named_region(lifetime.hir_id) {
Some(rl::Region::Static) => tcx.lifetimes.re_static,
@ -2105,7 +2105,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("find_bound_for_assoc_item: predicates={:#?}", predicates);
let param_hir_id = tcx.hir().as_local_hir_id(ty_param_def_id);
let param_hir_id = tcx.hir().local_def_id_to_hir_id(ty_param_def_id);
let param_name = tcx.hir().ty_param_name(param_hir_id);
self.one_bound_for_assoc_type(
|| {
@ -2489,7 +2489,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let parent_def_id = def_id
.and_then(|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))
})
.map(|hir_id| tcx.hir().get_parent_did(hir_id).to_def_id());
@ -2825,7 +2825,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
assert_eq!(opt_self_ty, None);
self.prohibit_generics(path.segments);
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);

View File

@ -1502,7 +1502,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
let ty = AstConv::ast_ty_to_ty(fcx, ty);
// Get the `impl Trait`'s `DefId`.
if let ty::Opaque(def_id, _) = ty.kind {
let hir_id = fcx.tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = fcx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
// Get the `impl Trait`'s `Item` so that we can get its trait bounds and
// get the `Trait`'s `DefId`.
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) =

View File

@ -77,7 +77,7 @@ fn compare_predicate_entailment<'tcx>(
// This node-id should be used for the `body_id` field on each
// `ObligationCause` (and the `FnCtxt`). This is what
// `regionck_item` expects.
let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local());
let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.expect_local());
// We sometimes modify the span further down.
let mut cause = ObligationCause::new(
@ -401,7 +401,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
trait_sig: ty::FnSig<'tcx>,
) -> (Span, Option<Span>) {
let tcx = infcx.tcx;
let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local());
let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.expect_local());
let (impl_m_output, impl_m_iter) = match tcx.hir().expect_impl_item(impl_m_hir_id).kind {
ImplItemKind::Fn(ref impl_m_sig, _) => {
(&impl_m_sig.decl.output, impl_m_sig.decl.inputs.iter())
@ -412,7 +412,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
match *terr {
TypeError::Mutability => {
if let Some(def_id) = trait_m.def_id.as_local() {
let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id);
let trait_m_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let trait_m_iter = match tcx.hir().expect_trait_item(trait_m_hir_id).kind {
TraitItemKind::Fn(ref trait_m_sig, _) => trait_m_sig.decl.inputs.iter(),
_ => bug!("{:?} is not a TraitItemKind::Fn", trait_m),
@ -440,7 +440,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
}
TypeError::Sorts(ExpectedFound { .. }) => {
if let Some(def_id) = trait_m.def_id.as_local() {
let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id);
let trait_m_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let (trait_m_output, trait_m_iter) =
match tcx.hir().expect_trait_item(trait_m_hir_id).kind {
TraitItemKind::Fn(ref trait_m_sig, _) => {
@ -589,7 +589,7 @@ fn compare_number_of_generics<'tcx>(
err_occurred = true;
let (trait_spans, impl_trait_spans) = if let Some(def_id) = trait_.def_id.as_local() {
let trait_hir_id = tcx.hir().as_local_hir_id(def_id);
let trait_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let trait_item = tcx.hir().expect_trait_item(trait_hir_id);
if trait_item.generics.params.is_empty() {
(Some(vec![trait_item.generics.span]), vec![])
@ -614,7 +614,7 @@ fn compare_number_of_generics<'tcx>(
(trait_span.map(|s| vec![s]), vec![])
};
let impl_hir_id = tcx.hir().as_local_hir_id(impl_.def_id.expect_local());
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_.def_id.expect_local());
let impl_item = tcx.hir().expect_impl_item(impl_hir_id);
let impl_item_impl_trait_spans: Vec<Span> = impl_item
.generics
@ -706,7 +706,7 @@ fn compare_number_of_method_arguments<'tcx>(
let impl_number_args = impl_m_fty.inputs().skip_binder().len();
if trait_number_args != impl_number_args {
let trait_span = if let Some(def_id) = trait_m.def_id.as_local() {
let trait_id = tcx.hir().as_local_hir_id(def_id);
let trait_id = tcx.hir().local_def_id_to_hir_id(def_id);
match tcx.hir().expect_trait_item(trait_id).kind {
TraitItemKind::Fn(ref trait_m_sig, _) => {
let pos = if trait_number_args > 0 { trait_number_args - 1 } else { 0 };
@ -729,7 +729,7 @@ fn compare_number_of_method_arguments<'tcx>(
} else {
trait_item_span
};
let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id.expect_local());
let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.expect_local());
let impl_span = match tcx.hir().expect_impl_item(impl_m_hir_id).kind {
ImplItemKind::Fn(ref impl_m_sig, _) => {
let pos = if impl_number_args > 0 { impl_number_args - 1 } else { 0 };
@ -811,7 +811,7 @@ fn compare_synthetic_generics<'tcx>(
impl_m_type_params.zip(trait_m_type_params)
{
if impl_synthetic != trait_synthetic {
let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id.expect_local());
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_def_id.expect_local());
let impl_span = tcx.hir().span(impl_hir_id);
let trait_span = tcx.def_span(trait_def_id);
let mut err = struct_span_err!(
@ -832,10 +832,10 @@ fn compare_synthetic_generics<'tcx>(
// FIXME: this is obviously suboptimal since the name can already be used
// as another generic argument
let new_name = tcx.sess.source_map().span_to_snippet(trait_span).ok()?;
let trait_m = tcx.hir().as_local_hir_id(trait_m.def_id.as_local()?);
let trait_m = tcx.hir().local_def_id_to_hir_id(trait_m.def_id.as_local()?);
let trait_m = tcx.hir().trait_item(hir::TraitItemId { hir_id: trait_m });
let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id.as_local()?);
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?);
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
// in case there are no generics, take the spot between the function name
@ -869,7 +869,7 @@ fn compare_synthetic_generics<'tcx>(
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
(|| {
let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id.as_local()?);
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?);
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
let input_tys = match impl_m.kind {
hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs,
@ -962,7 +962,7 @@ crate fn compare_const_impl<'tcx>(
// Create a parameter environment that represents the implementation's
// method.
let impl_c_hir_id = tcx.hir().as_local_hir_id(impl_c.def_id.expect_local());
let impl_c_hir_id = tcx.hir().local_def_id_to_hir_id(impl_c.def_id.expect_local());
// Compute placeholder form of impl and trait const tys.
let impl_ty = tcx.type_of(impl_c.def_id);
@ -1011,7 +1011,7 @@ crate fn compare_const_impl<'tcx>(
);
let trait_c_hir_id =
trait_c.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id));
trait_c.def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id));
let trait_c_span = trait_c_hir_id.map(|trait_c_hir_id| {
// Add a label to the Span containing just the type of the const
match tcx.hir().expect_trait_item(trait_c_hir_id).kind {
@ -1101,7 +1101,7 @@ fn compare_type_predicate_entailment<'tcx>(
// This `HirId` should be used for the `body_id` field on each
// `ObligationCause` (and the `FnCtxt`). This is what
// `regionck_item` expects.
let impl_ty_hir_id = tcx.hir().as_local_hir_id(impl_ty.def_id.expect_local());
let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local());
let cause = ObligationCause::new(
impl_ty_span,
impl_ty_hir_id,
@ -1240,7 +1240,7 @@ fn compare_projection_bounds<'tcx>(
let infcx = &inh.infcx;
let mut selcx = traits::SelectionContext::new(&infcx);
let impl_ty_hir_id = tcx.hir().as_local_hir_id(impl_ty.def_id.expect_local());
let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local());
let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_hir_id);
let cause = ObligationCause::new(
impl_ty_span,

View File

@ -70,7 +70,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
drop_impl_ty: Ty<'tcx>,
self_type_did: DefId,
) -> Result<(), ErrorReported> {
let drop_impl_hir_id = tcx.hir().as_local_hir_id(drop_impl_did);
let drop_impl_hir_id = tcx.hir().local_def_id_to_hir_id(drop_impl_did);
// check that the impl type can be made to match the trait type.
@ -183,7 +183,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
// absent. So we report an error that the Drop impl injected a
// predicate that is not present on the struct definition.
let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did);
let self_type_hir_id = tcx.hir().local_def_id_to_hir_id(self_type_did);
// We can assume the predicates attached to struct/enum definition
// hold.

View File

@ -1606,7 +1606,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
let param_def_id = generic_param.def_id;
let param_hir_id = match param_def_id.as_local() {
Some(x) => self.tcx.hir().as_local_hir_id(x),
Some(x) => self.tcx.hir().local_def_id_to_hir_id(x),
None => return,
};
let param_span = self.tcx.hir().span(param_hir_id);

View File

@ -579,7 +579,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
if let ty::Adt(def, _) = p.trait_ref.self_ty().kind {
let node = def.did.as_local().map(|def_id| {
self.tcx.hir().get(self.tcx.hir().as_local_hir_id(def_id))
self.tcx
.hir()
.get(self.tcx.hir().local_def_id_to_hir_id(def_id))
});
if let Some(hir::Node::Item(hir::Item { kind, .. })) = node {
if let Some(g) = kind.generics() {
@ -859,7 +861,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
candidates: Vec<DefId>,
) {
let module_did = self.tcx.parent_module(self.body_id);
let module_id = self.tcx.hir().as_local_hir_id(module_did);
let module_id = self.tcx.hir().local_def_id_to_hir_id(module_did);
let krate = self.tcx.hir().krate();
let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id);
if let Some(span) = span {
@ -975,7 +977,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let id = item
.def_id
.as_local()
.map(|def_id| self.tcx.hir().as_local_hir_id(def_id));
.map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id));
if let Some(hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(fn_sig, method),
..
@ -1062,7 +1064,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let type_param = generics.type_param(param, self.tcx);
let hir = &self.tcx.hir();
if let Some(def_id) = type_param.def_id.as_local() {
let id = hir.as_local_hir_id(def_id);
let id = hir.local_def_id_to_hir_id(def_id);
// Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: FooBar`,
// instead we suggest `T: Foo + Bar` in that case.

View File

@ -974,7 +974,7 @@ fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tc
/// Currently only used for type inference of `static`s and `const`s to avoid type cycle errors.
fn diagnostic_only_typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tcx> {
let fallback = move || {
let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id));
let span = tcx.hir().span(tcx.hir().local_def_id_to_hir_id(def_id));
tcx.ty_error_with_message(span, "diagnostic only typeck table used")
};
typeck_with_fallback(tcx, def_id, fallback)
@ -992,7 +992,7 @@ fn typeck_with_fallback<'tcx>(
return tcx.typeck(outer_def_id);
}
let id = tcx.hir().as_local_hir_id(def_id);
let id = tcx.hir().local_def_id_to_hir_id(def_id);
let span = tcx.hir().span(id);
// Figure out what primary body this item has.
@ -1333,7 +1333,7 @@ fn check_fn<'a, 'tcx>(
}
let outer_def_id = tcx.closure_base_def_id(hir.local_def_id(fn_id).to_def_id()).expect_local();
let outer_hir_id = hir.as_local_hir_id(outer_def_id);
let outer_hir_id = hir.local_def_id_to_hir_id(outer_def_id);
GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id }.visit_body(body);
// C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
@ -1444,7 +1444,7 @@ fn check_fn<'a, 'tcx>(
// Check that the main return type implements the termination trait.
if let Some(term_id) = tcx.lang_items().termination() {
if let Some((def_id, EntryFnType::Main)) = tcx.entry_fn(LOCAL_CRATE) {
let main_id = hir.as_local_hir_id(def_id);
let main_id = hir.local_def_id_to_hir_id(def_id);
if main_id == fn_id {
let substs = tcx.mk_substs_trait(declared_ret_ty, &[]);
let trait_ref = ty::TraitRef::new(term_id, substs);
@ -1622,7 +1622,7 @@ fn check_opaque<'tcx>(
/// Checks that an opaque type does not use `Self` or `T::Foo` projections that would result
/// in "inheriting lifetimes".
fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) {
let item = tcx.hir().expect_item(tcx.hir().as_local_hir_id(def_id));
let item = tcx.hir().expect_item(tcx.hir().local_def_id_to_hir_id(def_id));
debug!(
"check_opaque_for_inheriting_lifetimes: def_id={:?} span={:?} item={:?}",
def_id, span, item
@ -1729,7 +1729,7 @@ fn get_owner_return_paths(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
) -> Option<(hir::HirId, ReturnsVisitor<'tcx>)> {
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 id = tcx.hir().get_parent_item(hir_id);
tcx.hir()
.find(id)
@ -1833,7 +1833,7 @@ fn binding_opaque_type_cycle_error(
let mut err = struct_span_err!(tcx.sess, span, E0720, "cannot resolve opaque type");
err.span_label(span, "cannot resolve opaque type");
// Find the the owner that declared this `impl Trait` type.
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 mut prev_hir_id = hir_id;
let mut hir_id = tcx.hir().get_parent_node(hir_id);
while let Some(node) = tcx.hir().find(hir_id) {
@ -1858,7 +1858,7 @@ fn binding_opaque_type_cycle_error(
source: hir::LocalSource::Normal,
..
}) => {
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 typeck_results =
tcx.typeck(tcx.hir().local_def_id(tcx.hir().get_parent_item(hir_id)));
if let Some(ty) = typeck_results.node_type_opt(expr.hir_id) {
@ -2874,7 +2874,7 @@ pub fn check_enum<'tcx>(
// Check for duplicate discriminant values
if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) {
let variant_did = def.variants[VariantIdx::new(i)].def_id;
let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did.expect_local());
let variant_i_hir_id = tcx.hir().local_def_id_to_hir_id(variant_did.expect_local());
let variant_i = tcx.hir().expect_variant(variant_i_hir_id);
let i_span = match variant_i.disr_expr {
Some(ref expr) => tcx.hir().span(expr.hir_id),
@ -2935,7 +2935,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
fn get_type_parameter_bounds(&self, _: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> {
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 item_id = tcx.hir().ty_param_owner(hir_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id);

View File

@ -933,7 +933,7 @@ fn suggest_constraining_param(
let param_def_id = generics.type_param(&p, tcx).def_id;
if let Some(generics) = param_def_id
.as_local()
.map(|id| hir.as_local_hir_id(id))
.map(|id| hir.local_def_id_to_hir_id(id))
.and_then(|id| hir.find(hir.get_parent_item(id)))
.as_ref()
.and_then(|node| node.generics())

View File

@ -71,7 +71,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check
/// the types first.
pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
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 item = tcx.hir().expect_item(hir_id);
debug!(
@ -190,7 +190,7 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
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 trait_item = tcx.hir().expect_trait_item(hir_id);
let method_sig = match trait_item.kind {
@ -264,7 +264,7 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
}
pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
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 impl_item = tcx.hir().expect_impl_item(hir_id);
let method_sig = match impl_item.kind {
@ -902,7 +902,7 @@ fn check_opaque_types<'fcx, 'tcx>(
let generics = tcx.generics_of(def_id);
let opaque_hir_id = if let Some(local_id) = def_id.as_local() {
tcx.hir().as_local_hir_id(local_id)
tcx.hir().local_def_id_to_hir_id(local_id)
} else {
// Opaque types from other crates won't have defining uses in this crate.
return ty;

View File

@ -433,7 +433,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
fn visit_opaque_types(&mut self, span: Span) {
for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
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 instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id);
debug_assert!(!instantiated_ty.has_escaping_bound_vars());

View File

@ -88,7 +88,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
// Note that if we carry through to the `extern_mod_stmt_cnum` query
// below it'll cause a panic because `def_id` is actually bogus at this
// point in time otherwise.
if tcx.hir().find(tcx.hir().as_local_hir_id(def_id)).is_none() {
if tcx.hir().find(tcx.hir().local_def_id_to_hir_id(def_id)).is_none() {
return false;
}
true
@ -113,7 +113,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
for extern_crate in &crates_to_lint {
let def_id = extern_crate.def_id.expect_local();
let id = tcx.hir().as_local_hir_id(def_id);
let id = tcx.hir().local_def_id_to_hir_id(def_id);
let item = tcx.hir().expect_item(id);
// If the crate is fully unused, we suggest removing it altogether.

View File

@ -54,7 +54,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
return;
}
let impl_hir_id = tcx.hir().as_local_hir_id(impl_did);
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did);
let sp = match tcx.hir().expect_item(impl_hir_id).kind {
ItemKind::Impl { self_ty, .. } => self_ty.span,
_ => bug!("expected Drop impl item"),
@ -73,7 +73,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
let impl_hir_id = tcx.hir().as_local_hir_id(impl_did);
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did);
let self_type = tcx.type_of(impl_did);
debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type);
@ -146,7 +146,7 @@ fn visit_implementation_of_coerce_unsized(tcx: TyCtxt<'tcx>, impl_did: LocalDefI
fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
let impl_hir_id = tcx.hir().as_local_hir_id(impl_did);
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did);
let span = tcx.hir().span(impl_hir_id);
let dispatch_from_dyn_trait = tcx.require_lang_item(DispatchFromDynTraitLangItem, Some(span));
@ -315,7 +315,7 @@ pub fn coerce_unsized_info(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedI
debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did);
// this provider should only get invoked for local def-ids
let impl_hir_id = tcx.hir().as_local_hir_id(impl_did.expect_local());
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did.expect_local());
let span = tcx.hir().span(impl_hir_id);
let coerce_unsized_trait = tcx.require_lang_item(CoerceUnsizedTraitLangItem, Some(span));

View File

@ -275,7 +275,7 @@ impl ItemCtxt<'tcx> {
}
pub fn hir_id(&self) -> hir::HirId {
self.tcx.hir().as_local_hir_id(self.item_def_id.expect_local())
self.tcx.hir().local_def_id_to_hir_id(self.item_def_id.expect_local())
}
pub fn node(&self) -> hir::Node<'tcx> {
@ -490,7 +490,7 @@ fn type_param_predicates(
// written inline like `<T: Foo>` or in a where-clause like
// `where T: Foo`.
let param_id = tcx.hir().as_local_hir_id(def_id);
let param_id = tcx.hir().local_def_id_to_hir_id(def_id);
let param_owner = tcx.hir().ty_param_owner(param_id);
let param_owner_def_id = tcx.hir().local_def_id(param_owner);
let generics = tcx.generics_of(param_owner_def_id);
@ -512,7 +512,7 @@ fn type_param_predicates(
.unwrap_or_default();
let mut extend = None;
let item_hir_id = tcx.hir().as_local_hir_id(item_def_id.expect_local());
let item_hir_id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
let ast_generics = match tcx.hir().get(item_hir_id) {
Node::TraitItem(item) => &item.generics,
@ -824,7 +824,7 @@ fn convert_variant(
parent_did: LocalDefId,
) -> ty::VariantDef {
let mut seen_fields: FxHashMap<Ident, Span> = Default::default();
let hir_id = tcx.hir().as_local_hir_id(variant_did.unwrap_or(parent_did));
let hir_id = tcx.hir().local_def_id_to_hir_id(variant_did.unwrap_or(parent_did));
let fields = def
.fields()
.iter()
@ -878,7 +878,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::AdtDef {
use rustc_hir::*;
let def_id = def_id.expect_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 item = match tcx.hir().get(hir_id) {
Node::Item(item) => item,
_ => bug!(),
@ -965,7 +965,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::AdtDef {
/// the transitive super-predicates are converted.
fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredicates<'_> {
debug!("super_predicates(trait_def_id={:?})", trait_def_id);
let trait_hir_id = tcx.hir().as_local_hir_id(trait_def_id.expect_local());
let trait_hir_id = tcx.hir().local_def_id_to_hir_id(trait_def_id.expect_local());
let item = match tcx.hir().get(trait_hir_id) {
Node::Item(item) => item,
@ -1016,7 +1016,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi
}
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
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 = tcx.hir().expect_item(hir_id);
let (is_auto, unsafety) = match item.kind {
@ -1194,7 +1194,7 @@ impl<'v> Visitor<'v> for AnonConstInParamListDetector {
fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
use rustc_hir::*;
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 node = tcx.hir().get(hir_id);
let parent_def_id = match node {
@ -1499,7 +1499,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
use rustc_hir::*;
let def_id = def_id.expect_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 icx = ItemCtxt::new(tcx, def_id.to_def_id());
@ -1597,7 +1597,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::TraitRef<'_>> {
let icx = ItemCtxt::new(tcx, def_id);
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());
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.as_ref().map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id);
@ -1608,7 +1608,7 @@ fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::TraitRef<'_>> {
}
fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity {
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 is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl);
let item = tcx.hir().expect_item(hir_id);
match &item.kind {
@ -1738,7 +1738,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
}
}
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 node = tcx.hir().get(hir_id);
let mut is_trait = None;
@ -2590,7 +2590,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
if !codegen_fn_attrs.no_sanitize.is_empty() {
if codegen_fn_attrs.inline == InlineAttr::Always {
if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) {
let hir_id = tcx.hir().as_local_hir_id(id.expect_local());
let hir_id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
tcx.struct_span_lint_hir(
lint::builtin::INLINE_NO_SANITIZE,
hir_id,
@ -2718,7 +2718,7 @@ fn check_target_feature_safe_fn(tcx: TyCtxt<'_>, id: DefId, attr_span: Span) {
/// Checks the function annotated with `#[target_feature]` is not a safe
/// trait method implementation, reporting an error if it is.
fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {
let hir_id = tcx.hir().as_local_hir_id(id);
let hir_id = tcx.hir().local_def_id_to_hir_id(id);
let node = tcx.hir().get(hir_id);
if let Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) = node {
let parent_id = tcx.hir().get_parent_item(hir_id);

View File

@ -23,7 +23,7 @@ use super::{bad_placeholder_type, is_suggestable_infer_ty};
pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<DefId> {
use hir::*;
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
if let Node::AnonConst(_) = tcx.hir().get(hir_id) {
let parent_node_id = tcx.hir().get_parent_node(hir_id);
@ -138,7 +138,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
let def_id = def_id.expect_local();
use rustc_hir::*;
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 icx = ItemCtxt::new(tcx, def_id.to_def_id());
@ -564,7 +564,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
}
}
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 scope = tcx.hir().get_defining_scope(hir_id);
let mut locator = ConstraintLocator { def_id: def_id.to_def_id(), tcx, found: None };
@ -617,7 +617,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
/// by the time we borrow check, and it's not clear how we should handle
/// those.
fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty<'_> {
let scope = tcx.hir().get_defining_scope(tcx.hir().as_local_hir_id(opaque_ty_id));
let scope = tcx.hir().get_defining_scope(tcx.hir().local_def_id_to_hir_id(opaque_ty_id));
let scope_def_id = tcx.hir().local_def_id(scope);
let opaque_ty_def_id = opaque_ty_id.to_def_id();
@ -653,7 +653,7 @@ fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty
if concrete_ty.has_erased_regions() {
// FIXME(impl_trait_in_bindings) Handle this case.
tcx.sess.span_fatal(
tcx.hir().span(tcx.hir().as_local_hir_id(opaque_ty_id)),
tcx.hir().span(tcx.hir().local_def_id_to_hir_id(opaque_ty_id)),
"lifetimes in impl Trait types in bindings are not currently supported",
);
}

View File

@ -336,7 +336,7 @@ fn check_predicates<'tcx>(
if let Some(obligations) = wf::obligations(
infcx,
tcx.param_env(impl1_def_id),
tcx.hir().as_local_hir_id(impl1_def_id),
tcx.hir().local_def_id_to_hir_id(impl1_def_id),
arg,
span,
) {

View File

@ -153,7 +153,7 @@ fn require_same_types<'tcx>(
}
fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
let main_id = tcx.hir().as_local_hir_id(main_def_id);
let main_id = tcx.hir().local_def_id_to_hir_id(main_def_id);
let main_span = tcx.def_span(main_def_id);
let main_t = tcx.type_of(main_def_id);
match main_t.kind {
@ -249,7 +249,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
}
fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
let start_id = tcx.hir().as_local_hir_id(start_def_id);
let start_id = tcx.hir().local_def_id_to_hir_id(start_def_id);
let start_span = tcx.def_span(start_def_id);
let start_t = tcx.type_of(start_def_id);
match start_t.kind {

View File

@ -57,7 +57,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> {
debug!("InferVisitor::visit_item(item={:?})", item_did);
let hir_id = self.tcx.hir().as_local_hir_id(item_did);
let hir_id = self.tcx.hir().local_def_id_to_hir_id(item_did);
let item = match self.tcx.hir().get(hir_id) {
Node::Item(item) => item,
_ => bug!(),

View File

@ -18,7 +18,7 @@ pub fn provide(providers: &mut Providers) {
}
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate<'_>, Span)] {
let id = tcx.hir().as_local_hir_id(item_def_id.expect_local());
let id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
match tcx.hir().get(id) {
Node::Item(item) => match item.kind {

View File

@ -137,7 +137,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
return;
}
let id = tcx.hir().as_local_hir_id(def_id);
let id = tcx.hir().local_def_id_to_hir_id(def_id);
let inferred_start = self.terms_cx.inferred_starts[&id];
let current_item = &CurrentItem { inferred_start };
match tcx.type_of(def_id).kind {
@ -375,7 +375,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
}
let (local, remote) = 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);
(Some(self.terms_cx.inferred_starts[&id]), None)
} else {
(None, Some(self.tcx().variances_of(def_id)))

View File

@ -39,7 +39,7 @@ fn crate_variances(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateVariancesMap<'_
}
fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
let id = tcx.hir().as_local_hir_id(item_def_id.expect_local());
let id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
let unsupported = || {
// Variance not relevant.
span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item")

View File

@ -94,7 +94,9 @@ fn lang_items(tcx: TyCtxt<'_>) -> Vec<(hir::HirId, Vec<ty::Variance>)> {
all.into_iter() // iterating over (Option<DefId>, Variance)
.filter(|&(ref d, _)| d.is_some())
.map(|(d, v)| (d.unwrap(), v)) // (DefId, Variance)
.filter_map(|(d, v)| d.as_local().map(|d| tcx.hir().as_local_hir_id(d)).map(|n| (n, v))) // (HirId, Variance)
.filter_map(|(d, v)| {
d.as_local().map(|d| tcx.hir().local_def_id_to_hir_id(d)).map(|n| (n, v))
}) // (HirId, Variance)
.collect()
}

View File

@ -356,7 +356,7 @@ pub fn build_impl(
}
let for_ = if let Some(did) = did.as_local() {
let hir_id = tcx.hir().as_local_hir_id(did);
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx),
_ => panic!("did given to build_impl was not an impl"),
@ -377,7 +377,7 @@ pub fn build_impl(
let predicates = tcx.explicit_predicates_of(did);
let (trait_items, generics) = if let Some(did) = did.as_local() {
let hir_id = tcx.hir().as_local_hir_id(did);
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl { ref generics, ref items, .. } => (
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
@ -500,7 +500,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
pub fn print_inlined_const(cx: &DocContext<'_>, did: DefId) -> String {
if let Some(did) = did.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(did);
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(did);
rustc_hir_pretty::id_to_string(&cx.tcx.hir(), hir_id)
} else {
cx.tcx.rendered_const(did)
@ -513,7 +513,7 @@ fn build_const(cx: &DocContext<'_>, did: DefId) -> clean::Constant {
expr: print_inlined_const(cx, did),
value: clean::utils::print_evaluated_const(cx, did),
is_literal: did.as_local().map_or(false, |did| {
clean::utils::is_literal_expr(cx, cx.tcx.hir().as_local_hir_id(did))
clean::utils::is_literal_expr(cx, cx.tcx.hir().local_def_id_to_hir_id(did))
}),
}
}

View File

@ -1382,7 +1382,7 @@ impl Clean<Type> for hir::Ty<'_> {
if let Res::Def(DefKind::TyAlias, def_id) = path.res {
// Substitute private type aliases
if let Some(def_id) = def_id.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 !cx.renderinfo.borrow().access_levels.is_exported(def_id.to_def_id()) {
alias = Some(&cx.tcx.hir().expect_item(hir_id).kind);
}

View File

@ -471,7 +471,7 @@ pub fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
match n.val {
ty::ConstKind::Unevaluated(def, _, promoted) => {
let mut s = if let Some(def) = def.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(def.did);
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did);
print_const_expr(cx, cx.tcx.hir().body_owned_by(hir_id))
} else {
inline::print_inlined_const(cx, def.did)

View File

@ -143,13 +143,13 @@ impl<'tcx> DocContext<'tcx> {
def_id
}
/// Like the function of the same name on the HIR map, but skips calling it on fake DefIds.
/// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds.
/// (This avoids a slice-index-out-of-bounds panic.)
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<HirId> {
if self.all_fake_def_ids.borrow().contains(&def_id) {
None
} else {
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
def_id.as_local().map(|def_id| self.tcx.hir().local_def_id_to_hir_id(def_id))
}
}
@ -400,7 +400,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
}
let hir = tcx.hir();
let body = hir.body(hir.body_owned_by(hir.as_local_hir_id(def_id)));
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(def_id)));
debug!("visiting body for {:?}", def_id);
EmitIgnoredResolutionErrors::new(tcx).visit_body(body);
(rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id)

View File

@ -655,7 +655,7 @@ impl<'a, 'b> ExtraInfo<'a, 'b> {
(Some(h), _) => h,
(None, Some(item_did)) => {
match item_did.as_local() {
Some(item_did) => self.tcx.hir().as_local_hir_id(item_did),
Some(item_did) => self.tcx.hir().local_def_id_to_hir_id(item_did),
None => {
// If non-local, no need to check anything.
return;

View File

@ -813,8 +813,8 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
{
use rustc_hir::def_id::LOCAL_CRATE;
let hir_src = self.cx.tcx.hir().as_local_hir_id(src_id);
let hir_dst = self.cx.tcx.hir().as_local_hir_id(dst_id);
let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id);
let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id);
if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src)
&& !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst)

View File

@ -323,7 +323,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
}
let res_hir_id = match res_did.as_local() {
Some(n) => tcx.hir().as_local_hir_id(n),
Some(n) => tcx.hir().local_def_id_to_hir_id(n),
None => return false,
};

View File

@ -224,7 +224,7 @@ fn check_hash_peq<'tcx>(
mess,
|diag| {
if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
diag.span_note(
cx.tcx.hir().span(hir_id),
"`PartialEq` implemented here"
@ -278,7 +278,7 @@ fn check_ord_partial_ord<'tcx>(
mess,
|diag| {
if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
diag.span_note(
cx.tcx.hir().span(hir_id),
"`PartialOrd` implemented here"
@ -341,7 +341,7 @@ fn check_unsafe_derive_deserialize<'tcx>(
ty: Ty<'tcx>,
) {
fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
cx.tcx.hir().expect_item(hir_id)
}
@ -355,7 +355,7 @@ fn check_unsafe_derive_deserialize<'tcx>(
if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE);
if let ty::Adt(def, _) = ty.kind;
if let Some(local_def_id) = def.did.as_local();
let adt_hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
let adt_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
if !is_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
if cx.tcx.inherent_impls(def.did)
.iter()

View File

@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
cx.tcx.for_each_impl(default_trait_id, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
if let Some(local_def_id) = ty_def.did.as_local() {
impls.insert(cx.tcx.hir().as_local_hir_id(local_def_id));
impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id));
}
}
});