librustc_middle: return LocalDefId instead of DefId in get_parent_did
This commit is contained in:
parent
555e024abc
commit
b6b00578db
@ -720,9 +720,8 @@ impl<'hir> Map<'hir> {
|
||||
scope
|
||||
}
|
||||
|
||||
// FIXME(eddyb) this function can and should return `LocalDefId`.
|
||||
pub fn get_parent_did(&self, id: HirId) -> DefId {
|
||||
self.local_def_id(self.get_parent_item(id))
|
||||
pub fn get_parent_did(&self, id: HirId) -> LocalDefId {
|
||||
self.local_def_id(self.get_parent_item(id)).expect_local()
|
||||
}
|
||||
|
||||
pub fn get_foreign_abi(&self, hir_id: HirId) -> Abi {
|
||||
|
@ -84,11 +84,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
|
||||
pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
||||
let parent_id = tcx.hir().get_parent_did(hir_id);
|
||||
if !parent_id.is_top_level_module() {
|
||||
is_const_impl_raw(tcx, parent_id.expect_local())
|
||||
} else {
|
||||
false
|
||||
}
|
||||
if !parent_id.is_top_level_module() { is_const_impl_raw(tcx, parent_id) } else { false }
|
||||
}
|
||||
|
||||
/// Checks whether the function has a `const` modifier or, in case it is an intrinsic, whether
|
||||
|
@ -10,7 +10,7 @@ use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::{HirIdSet, Node};
|
||||
@ -42,7 +42,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: Codegen
|
||||
fn method_might_be_inlined(
|
||||
tcx: TyCtxt<'_>,
|
||||
impl_item: &hir::ImplItem<'_>,
|
||||
impl_src: DefId,
|
||||
impl_src: LocalDefId,
|
||||
) -> bool {
|
||||
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner.to_def_id());
|
||||
let generics = tcx.generics_of(tcx.hir().local_def_id(impl_item.hir_id));
|
||||
@ -54,7 +54,7 @@ fn method_might_be_inlined(
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) {
|
||||
if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src.to_def_id()) {
|
||||
match tcx.hir().find(impl_hir_id) {
|
||||
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"),
|
||||
@ -171,7 +171,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
||||
if generics.requires_monomorphization(self.tcx) || attrs.requests_inline() {
|
||||
true
|
||||
} else {
|
||||
let impl_did = self.tcx.hir().get_parent_did(hir_id);
|
||||
let impl_did = self.tcx.hir().get_parent_did(hir_id).to_def_id();
|
||||
// Check the impl. If the generics on the self
|
||||
// type of the impl require inlining, this method
|
||||
// does too.
|
||||
|
@ -248,7 +248,7 @@ fn def_id_visibility<'tcx>(
|
||||
}
|
||||
}
|
||||
Node::TraitItem(..) | Node::Variant(..) => {
|
||||
return def_id_visibility(tcx, tcx.hir().get_parent_did(hir_id));
|
||||
return def_id_visibility(tcx, tcx.hir().get_parent_did(hir_id).to_def_id());
|
||||
}
|
||||
Node::ImplItem(impl_item) => {
|
||||
match tcx.hir().get(tcx.hir().get_parent_item(hir_id)) {
|
||||
@ -270,7 +270,7 @@ fn def_id_visibility<'tcx>(
|
||||
let (mut ctor_vis, mut span, mut descr) =
|
||||
def_id_visibility(tcx, parent_did);
|
||||
|
||||
let adt_def = tcx.adt_def(tcx.hir().get_parent_did(hir_id));
|
||||
let adt_def = tcx.adt_def(tcx.hir().get_parent_did(hir_id).to_def_id());
|
||||
let ctor_did = tcx.hir().local_def_id(vdata.ctor_hir_id().unwrap());
|
||||
let variant = adt_def.variant_with_ctor_id(ctor_did);
|
||||
|
||||
@ -309,7 +309,8 @@ fn def_id_visibility<'tcx>(
|
||||
// If the structure is marked as non_exhaustive then lower the
|
||||
// visibility to within the crate.
|
||||
if ctor_vis == ty::Visibility::Public {
|
||||
let adt_def = tcx.adt_def(tcx.hir().get_parent_did(hir_id));
|
||||
let adt_def =
|
||||
tcx.adt_def(tcx.hir().get_parent_did(hir_id).to_def_id());
|
||||
if adt_def.non_enum_variant().is_field_list_non_exhaustive() {
|
||||
ctor_vis =
|
||||
ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
|
||||
|
@ -224,6 +224,11 @@ impl LocalDefId {
|
||||
pub fn to_def_id(self) -> DefId {
|
||||
DefId { krate: LOCAL_CRATE, index: self.local_def_index }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_top_level_module(self) -> bool {
|
||||
self.local_def_index == CRATE_DEF_INDEX
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for LocalDefId {
|
||||
|
@ -2371,7 +2371,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
|
||||
let parent_def_id = def_id
|
||||
.and_then(|def_id| tcx.hir().as_local_hir_id(def_id))
|
||||
.map(|hir_id| tcx.hir().get_parent_did(hir_id));
|
||||
.map(|hir_id| tcx.hir().get_parent_did(hir_id).to_def_id());
|
||||
|
||||
debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id);
|
||||
|
||||
|
@ -1513,7 +1513,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
|
||||
}
|
||||
|
||||
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor_hir_id().is_some() => {
|
||||
let ty = tcx.type_of(tcx.hir().get_parent_did(hir_id));
|
||||
let ty = tcx.type_of(tcx.hir().get_parent_did(hir_id).to_def_id());
|
||||
let inputs =
|
||||
data.fields().iter().map(|f| tcx.type_of(tcx.hir().local_def_id(f.hir_id)));
|
||||
ty::Binder::bind(tcx.mk_fn_sig(
|
||||
|
@ -59,14 +59,14 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
}
|
||||
}
|
||||
ImplItemKind::OpaqueTy(_) => {
|
||||
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id)).is_none() {
|
||||
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id).to_def_id()).is_none() {
|
||||
report_assoc_ty_on_inherent_impl(tcx, item.span);
|
||||
}
|
||||
|
||||
find_opaque_ty_constraints(tcx, def_id)
|
||||
}
|
||||
ImplItemKind::TyAlias(ref ty) => {
|
||||
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id)).is_none() {
|
||||
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id).to_def_id()).is_none() {
|
||||
report_assoc_ty_on_inherent_impl(tcx, item.span);
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
|
||||
Node::Ctor(&ref def) | Node::Variant(Variant { data: ref def, .. }) => match *def {
|
||||
VariantData::Unit(..) | VariantData::Struct(..) => {
|
||||
tcx.type_of(tcx.hir().get_parent_did(hir_id))
|
||||
tcx.type_of(tcx.hir().get_parent_did(hir_id).to_def_id())
|
||||
}
|
||||
VariantData::Tuple(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
@ -207,9 +207,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
tcx.types.usize
|
||||
}
|
||||
|
||||
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => {
|
||||
tcx.adt_def(tcx.hir().get_parent_did(hir_id)).repr.discr_type().to_ty(tcx)
|
||||
}
|
||||
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx
|
||||
.adt_def(tcx.hir().get_parent_did(hir_id).to_def_id())
|
||||
.repr
|
||||
.discr_type()
|
||||
.to_ty(tcx),
|
||||
|
||||
Node::Ty(&Ty { kind: TyKind::Path(_), .. })
|
||||
| Node::Expr(&Expr { kind: ExprKind::Struct(..), .. })
|
||||
|
Loading…
Reference in New Issue
Block a user