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 {
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
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};
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));
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"),
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.
}
}
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)) {
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);
// 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));
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 {
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);
}
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(
}
}
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);
}
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);
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(..), .. })