use crate::hir;
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
-use crate::ty::{self, Region, Ty};
+use crate::ty::{self, DefIdTree, Region, Ty};
use crate::hir::def_id::DefId;
use syntax_pos::Span;
let (id, bound_region) = match *anon_region {
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
ty::ReEarlyBound(ref ebr) => (
- self.tcx().parent_def_id(ebr.def_id).unwrap(),
+ self.tcx().parent(ebr.def_id).unwrap(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
),
_ => return None, // not a free region
use crate::hir::def_id::{DefId, LOCAL_CRATE};
use crate::lint;
use crate::middle::privacy;
-use crate::ty::{self, TyCtxt};
+use crate::ty::{self, DefIdTree, TyCtxt};
use crate::util::nodemap::FxHashSet;
use rustc_data_structures::fx::FxHashMap;
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
Def::Local(..) | Def::Upvar(..) => {}
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
- if let Some(enum_id) = self.tcx.parent_def_id(variant_id) {
+ if let Some(enum_id) = self.tcx.parent(variant_id) {
self.check_def_id(enum_id);
}
if !self.ignore_variant_stack.contains(&variant_id) {
use crate::infer::InferCtxt;
use crate::hir::def::{Def, CtorKind};
use crate::ty::adjustment;
-use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::{self, DefIdTree, Ty, TyCtxt};
use crate::ty::fold::TypeFoldable;
use crate::ty::layout::VariantIdx;
variant_did: DefId)
-> cmt<'tcx> {
// univariant enums do not need downcasts
- let base_did = self.tcx.parent_def_id(variant_did).unwrap();
+ let base_did = self.tcx.parent(variant_did).unwrap();
if self.tcx.adt_def(base_did).variants.len() != 1 {
let base_ty = base_cmt.ty;
let ret = Rc::new(cmt_ {
return Err(())
}
Def::VariantCtor(def_id, CtorKind::Fn) => {
- let enum_def = self.tcx.parent_def_id(def_id).unwrap();
+ let enum_def = self.tcx.parent(def_id).unwrap();
(self.cat_downcast_if_needed(pat, cmt, def_id),
self.tcx.adt_def(enum_def).variant_with_id(def_id).fields.len())
}
use syntax::source_map;
use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
-use crate::ty::TyCtxt;
+use crate::ty::{DefIdTree, TyCtxt};
use crate::ty::query::Providers;
use crate::hir;
pub fn early_free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
br: &ty::EarlyBoundRegion)
-> Scope {
- let param_owner = tcx.parent_def_id(br.def_id).unwrap();
+ let param_owner = tcx.parent(br.def_id).unwrap();
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| {
-> Scope {
let param_owner = match fr.bound_region {
ty::BoundRegion::BrNamed(def_id, _) => {
- tcx.parent_def_id(def_id).unwrap()
+ tcx.parent(def_id).unwrap()
}
_ => fr.scope
};
use crate::ty::ReprOptions;
use crate::traits;
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
-use crate::ty::{self, Ty, TypeAndMut};
+use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
use crate::ty::{TyS, TyKind, List};
use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const, LazyConst};
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
let (suitable_region_binding_scope, bound_region) = match *region {
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
ty::ReEarlyBound(ref ebr) => (
- self.parent_def_id(ebr.def_id).unwrap(),
+ self.parent(ebr.def_id).unwrap(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
),
_ => return None, // not a free region
data @ DefPathData::ClosureExpr |
data @ DefPathData::ImplTrait |
data @ DefPathData::GlobalMetaData(..) => {
- let parent_did = self.tcx.parent_def_id(def_id).unwrap();
+ let parent_did = self.tcx.parent(def_id).unwrap();
let path = self.print_item_path(parent_did, None, ns);
self.path_append(path, &data.as_interned_str().as_symbol().as_str())
},
DefPathData::StructCtor => { // present `X` instead of `X::{{constructor}}`
- let parent_def_id = self.tcx.parent_def_id(def_id).unwrap();
+ let parent_def_id = self.tcx.parent(def_id).unwrap();
self.print_item_path(parent_def_id, substs, ns)
}
}
ns: Namespace,
) -> P::Path {
debug!("default_print_impl_path: impl_def_id={:?}", impl_def_id);
- let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
+ let parent_def_id = self.tcx.parent(impl_def_id).unwrap();
// Decide whether to print the parent path for the impl.
// Logically, since impls are global, it's never needed, but
}
let in_self_mod = match characteristic_def_id_of_type(self_ty) {
None => false,
- Some(ty_def_id) => self.tcx.parent_def_id(ty_def_id) == Some(parent_def_id),
+ Some(ty_def_id) => self.tcx.parent(ty_def_id) == Some(parent_def_id),
};
let mut impl_trait_ref = self.tcx.impl_trait_ref(impl_def_id);
}
let in_trait_mod = match impl_trait_ref {
None => false,
- Some(trait_ref) => self.tcx.parent_def_id(trait_ref.def_id) == Some(parent_def_id),
+ Some(trait_ref) => self.tcx.parent(trait_ref.def_id) == Some(parent_def_id),
};
if !in_self_mod && !in_trait_mod {
}
}
-impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
- /// Returns the `DefId` of `def_id`'s parent in the def tree. If
- /// this returns `None`, then `def_id` represents a crate root or
- /// inlined root.
- pub fn parent_def_id(self, def_id: DefId) -> Option<DefId> {
- let key = self.def_key(def_id);
- key.parent.map(|index| DefId { krate: def_id.krate, index: index })
- }
-}
-
/// As a heuristic, when we see an impl, if we see that the
/// 'self type' is a type defined in the same module as the impl,
/// we can omit including the path to the impl itself. This
// pretty printing some span information. This should
// only occur very early in the compiler pipeline.
// FIXME(eddyb) this should just be using `tcx.def_span(impl_def_id)`
- let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
+ let parent_def_id = self.tcx.parent(impl_def_id).unwrap();
let path = self.print_item_path(parent_def_id, None, ns);
let span = self.tcx.def_span(impl_def_id);
return self.path_append(path, &format!("<impl at {:?}>", span));
pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
match def {
Def::Variant(did) | Def::VariantCtor(did, ..) => {
- let enum_did = self.parent_def_id(did).unwrap();
+ let enum_did = self.parent(did).unwrap();
self.adt_def(enum_did).variant_with_id(did)
}
Def::Struct(did) | Def::Union(did) => {
self.adt_def(did).non_enum_variant()
}
Def::StructCtor(ctor_did, ..) => {
- let did = self.parent_def_id(ctor_did).expect("struct ctor has no parent");
+ let did = self.parent(ctor_did).expect("struct ctor has no parent");
self.adt_def(did).non_enum_variant()
}
_ => bug!("expect_variant_def used with unexpected def {:?}", def)
use rustc_data_structures::indexed_vec::Idx;
use rustc_macros::HashStable;
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef, Kind, UnpackedKind};
-use crate::ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
+use crate::ty::{self, AdtDef, DefIdTree, TypeFlags, Ty, TyCtxt, TypeFoldable};
use crate::ty::{List, TyS, ParamEnvAnd, ParamEnv};
use crate::util::captures::Captures;
use crate::mir::interpret::{Scalar, Pointer};
pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_, '_, '_>) -> DefId {
match self {
ty::ReEarlyBound(br) => {
- tcx.parent_def_id(br.def_id).unwrap()
+ tcx.parent(br.def_id).unwrap()
}
ty::ReFree(fr) => fr.scope,
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
use crate::mir::interpret::{sign_extend, truncate};
use crate::ich::NodeIdHashingMode;
use crate::traits::{self, ObligationCause};
-use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
+use crate::ty::{self, DefIdTree, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
use crate::ty::subst::{Subst, InternalSubsts, SubstsRef, UnpackedKind};
use crate::ty::query::TyCtxtAt;
use crate::ty::TyKind::*;
pub fn closure_base_def_id(self, def_id: DefId) -> DefId {
let mut def_id = def_id;
while self.is_closure(def_id) {
- def_id = self.parent_def_id(def_id).unwrap_or_else(|| {
+ def_id = self.parent(def_id).unwrap_or_else(|| {
bug!("closure {:?} has no parent", def_id);
});
}
use rustc::mir::{Field, Projection, ProjectionElem, Rvalue, Statement, StatementKind};
use rustc::mir::{Terminator, TerminatorKind};
use rustc::ty::query::Providers;
-use rustc::ty::{self, TyCtxt};
+use rustc::ty::{self, DefIdTree, TyCtxt};
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
use rustc_data_structures::bit_set::BitSet;
use rustc::mir::{fmt_const_val, Field, BorrowKind, Mutability};
use rustc::mir::{UserTypeProjection};
use rustc::mir::interpret::{Scalar, GlobalId, ConstValue, sign_extend};
-use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty, Lift, UserType};
+use rustc::ty::{self, DefIdTree, Region, TyCtxt, AdtDef, Ty, Lift, UserType};
use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations};
use rustc::ty::subst::{SubstsRef, Kind};
use rustc::ty::layout::VariantIdx;
) -> PatternKind<'tcx> {
let mut kind = match def {
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
- let enum_id = self.tcx.parent_def_id(variant_id).unwrap();
+ let enum_id = self.tcx.parent(variant_id).unwrap();
let adt_def = self.tcx.adt_def(enum_id);
if adt_def.is_enum() {
let substs = match ty.sty {
use rustc::hir::def_id::DefId;
use rustc::session::config::Input;
use rustc::span_bug;
-use rustc::ty::{self, TyCtxt};
+use rustc::ty::{self, DefIdTree, TyCtxt};
use rustc_data_structures::fx::FxHashSet;
use std::path::Path;
// The parent def id of a given use tree is always the enclosing item.
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(id)
- .and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
+ .and_then(|id| self.save_ctxt.tcx.parent(id))
.map(id_from_def_id);
match use_tree.kind {
if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span);
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(item.id)
- .and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
+ .and_then(|id| self.save_ctxt.tcx.parent(id))
.map(id_from_def_id);
self.dumper.import(
&Access {
use rustc::middle::privacy::AccessLevels;
use rustc::middle::cstore::ExternCrate;
use rustc::session::config::{CrateType, Input, OutputType};
-use rustc::ty::{self, TyCtxt};
+use rustc::ty::{self, DefIdTree, TyCtxt};
use rustc::{bug, span_bug};
use rustc_typeck::hir_ty_to_ty;
use rustc_codegen_utils::link::{filename_for_metadata, out_filename};
// This is a reference to a tuple struct where the def_id points
// to an invisible constructor function. That is not a very useful
// def, so adjust to point to the tuple struct itself.
- let parent_def_id = self.tcx.parent_def_id(def_id).unwrap();
+ let parent_def_id = self.tcx.parent(def_id).unwrap();
Some(Ref {
kind: RefKind::Type,
span,
use crate::namespace::Namespace;
use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
use rustc::traits;
-use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
+use rustc::ty::{self, DefIdTree, Ty, TyCtxt, ToPredicate, TypeFoldable};
use rustc::ty::{GenericParamDef, GenericParamDefKind};
use rustc::ty::subst::{Kind, Subst, InternalSubsts, SubstsRef};
use rustc::ty::wf::object_region_bounds;
-> Ty<'tcx>
{
let tcx = self.tcx();
- let trait_def_id = tcx.parent_def_id(item_def_id).unwrap();
+ let trait_def_id = tcx.parent(item_def_id).unwrap();
self.prohibit_generics(slice::from_ref(item_segment));
} else if last >= 1 && segments[last - 1].args.is_some() {
// Everything but the penultimate segment should have no
// parameters at all.
- let enum_def_id = tcx.parent_def_id(def_id).unwrap();
+ let enum_def_id = tcx.parent(def_id).unwrap();
(enum_def_id, last - 1)
} else {
// FIXME: lint here recommending `Enum::<...>::Variant` form
use rustc::hir::def::{self, Def, CtorKind, Namespace};
use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::ty::subst::{InternalSubsts, SubstsRef};
-use rustc::ty::{self, TyCtxt, Region, RegionVid, Ty, AdtKind};
+use rustc::ty::{self, DefIdTree, TyCtxt, Region, RegionVid, Ty, AdtKind};
use rustc::ty::fold::TypeFolder;
use rustc::ty::layout::VariantIdx;
use rustc::util::nodemap::{FxHashMap, FxHashSet};
Def::ForeignTy(i) => (i, TypeKind::Foreign),
Def::Const(i) => (i, TypeKind::Const),
Def::Static(i, _) => (i, TypeKind::Static),
- Def::Variant(i) => (cx.tcx.parent_def_id(i).expect("cannot get parent def id"),
+ Def::Variant(i) => (cx.tcx.parent(i).expect("cannot get parent def id"),
TypeKind::Enum),
Def::Macro(i, mac_kind) => match mac_kind {
MacroKind::Bang => (i, TypeKind::Macro),