Skip to content

Commit f1af5a7

Browse files
committed
rustc: remove TyCtxt::parent_def_id in favor of TyCtxt::parent.
1 parent 6ca6c1a commit f1af5a7

File tree

15 files changed

+37
-47
lines changed

15 files changed

+37
-47
lines changed

src/librustc/infer/error_reporting/nice_region_error/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use crate::hir;
55
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
6-
use crate::ty::{self, Region, Ty};
6+
use crate::ty::{self, DefIdTree, Region, Ty};
77
use crate::hir::def_id::DefId;
88
use syntax_pos::Span;
99

@@ -44,7 +44,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
4444
let (id, bound_region) = match *anon_region {
4545
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
4646
ty::ReEarlyBound(ref ebr) => (
47-
self.tcx().parent_def_id(ebr.def_id).unwrap(),
47+
self.tcx().parent(ebr.def_id).unwrap(),
4848
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
4949
),
5050
_ => return None, // not a free region

src/librustc/middle/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::hir::CodegenFnAttrFlags;
1212
use crate::hir::def_id::{DefId, LOCAL_CRATE};
1313
use crate::lint;
1414
use crate::middle::privacy;
15-
use crate::ty::{self, TyCtxt};
15+
use crate::ty::{self, DefIdTree, TyCtxt};
1616
use crate::util::nodemap::FxHashSet;
1717

1818
use rustc_data_structures::fx::FxHashMap;
@@ -78,7 +78,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7878
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
7979
Def::Local(..) | Def::Upvar(..) => {}
8080
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
81-
if let Some(enum_id) = self.tcx.parent_def_id(variant_id) {
81+
if let Some(enum_id) = self.tcx.parent(variant_id) {
8282
self.check_def_id(enum_id);
8383
}
8484
if !self.ignore_variant_stack.contains(&variant_id) {

src/librustc/middle/mem_categorization.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use crate::hir::Node;
6464
use crate::infer::InferCtxt;
6565
use crate::hir::def::{Def, CtorKind};
6666
use crate::ty::adjustment;
67-
use crate::ty::{self, Ty, TyCtxt};
67+
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
6868
use crate::ty::fold::TypeFoldable;
6969
use crate::ty::layout::VariantIdx;
7070

@@ -1133,7 +1133,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11331133
variant_did: DefId)
11341134
-> cmt<'tcx> {
11351135
// univariant enums do not need downcasts
1136-
let base_did = self.tcx.parent_def_id(variant_did).unwrap();
1136+
let base_did = self.tcx.parent(variant_did).unwrap();
11371137
if self.tcx.adt_def(base_did).variants.len() != 1 {
11381138
let base_ty = base_cmt.ty;
11391139
let ret = Rc::new(cmt_ {
@@ -1275,7 +1275,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12751275
return Err(())
12761276
}
12771277
Def::VariantCtor(def_id, CtorKind::Fn) => {
1278-
let enum_def = self.tcx.parent_def_id(def_id).unwrap();
1278+
let enum_def = self.tcx.parent(def_id).unwrap();
12791279
(self.cat_downcast_if_needed(pat, cmt, def_id),
12801280
self.tcx.adt_def(enum_def).variant_with_id(def_id).fields.len())
12811281
}

src/librustc/middle/region.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_macros::HashStable;
1717
use syntax::source_map;
1818
use syntax::ast;
1919
use syntax_pos::{Span, DUMMY_SP};
20-
use crate::ty::TyCtxt;
20+
use crate::ty::{DefIdTree, TyCtxt};
2121
use crate::ty::query::Providers;
2222

2323
use crate::hir;
@@ -650,7 +650,7 @@ impl<'tcx> ScopeTree {
650650
pub fn early_free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
651651
br: &ty::EarlyBoundRegion)
652652
-> Scope {
653-
let param_owner = tcx.parent_def_id(br.def_id).unwrap();
653+
let param_owner = tcx.parent(br.def_id).unwrap();
654654

655655
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
656656
let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| {
@@ -679,7 +679,7 @@ impl<'tcx> ScopeTree {
679679
-> Scope {
680680
let param_owner = match fr.bound_region {
681681
ty::BoundRegion::BrNamed(def_id, _) => {
682-
tcx.parent_def_id(def_id).unwrap()
682+
tcx.parent(def_id).unwrap()
683683
}
684684
_ => fr.scope
685685
};

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, Subst};
2626
use crate::ty::ReprOptions;
2727
use crate::traits;
2828
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
29-
use crate::ty::{self, Ty, TypeAndMut};
29+
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
3030
use crate::ty::{TyS, TyKind, List};
3131
use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const, LazyConst};
3232
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
@@ -1594,7 +1594,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15941594
let (suitable_region_binding_scope, bound_region) = match *region {
15951595
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
15961596
ty::ReEarlyBound(ref ebr) => (
1597-
self.parent_def_id(ebr.def_id).unwrap(),
1597+
self.parent(ebr.def_id).unwrap(),
15981598
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
15991599
),
16001600
_ => return None, // not a free region

src/librustc/ty/item_path.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
154154
data @ DefPathData::ClosureExpr |
155155
data @ DefPathData::ImplTrait |
156156
data @ DefPathData::GlobalMetaData(..) => {
157-
let parent_did = self.tcx.parent_def_id(def_id).unwrap();
157+
let parent_did = self.tcx.parent(def_id).unwrap();
158158
let path = self.print_item_path(parent_did, None, ns);
159159
self.path_append(path, &data.as_interned_str().as_symbol().as_str())
160160
},
161161

162162
DefPathData::StructCtor => { // present `X` instead of `X::{{constructor}}`
163-
let parent_def_id = self.tcx.parent_def_id(def_id).unwrap();
163+
let parent_def_id = self.tcx.parent(def_id).unwrap();
164164
self.print_item_path(parent_def_id, substs, ns)
165165
}
166166
}
@@ -173,7 +173,7 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
173173
ns: Namespace,
174174
) -> P::Path {
175175
debug!("default_print_impl_path: impl_def_id={:?}", impl_def_id);
176-
let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
176+
let parent_def_id = self.tcx.parent(impl_def_id).unwrap();
177177

178178
// Decide whether to print the parent path for the impl.
179179
// Logically, since impls are global, it's never needed, but
@@ -186,7 +186,7 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
186186
}
187187
let in_self_mod = match characteristic_def_id_of_type(self_ty) {
188188
None => false,
189-
Some(ty_def_id) => self.tcx.parent_def_id(ty_def_id) == Some(parent_def_id),
189+
Some(ty_def_id) => self.tcx.parent(ty_def_id) == Some(parent_def_id),
190190
};
191191

192192
let mut impl_trait_ref = self.tcx.impl_trait_ref(impl_def_id);
@@ -195,7 +195,7 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
195195
}
196196
let in_trait_mod = match impl_trait_ref {
197197
None => false,
198-
Some(trait_ref) => self.tcx.parent_def_id(trait_ref.def_id) == Some(parent_def_id),
198+
Some(trait_ref) => self.tcx.parent(trait_ref.def_id) == Some(parent_def_id),
199199
};
200200

201201
if !in_self_mod && !in_trait_mod {
@@ -248,16 +248,6 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
248248
}
249249
}
250250

251-
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
252-
/// Returns the `DefId` of `def_id`'s parent in the def tree. If
253-
/// this returns `None`, then `def_id` represents a crate root or
254-
/// inlined root.
255-
pub fn parent_def_id(self, def_id: DefId) -> Option<DefId> {
256-
let key = self.def_key(def_id);
257-
key.parent.map(|index| DefId { krate: def_id.krate, index: index })
258-
}
259-
}
260-
261251
/// As a heuristic, when we see an impl, if we see that the
262252
/// 'self type' is a type defined in the same module as the impl,
263253
/// we can omit including the path to the impl itself. This
@@ -531,7 +521,7 @@ impl ItemPathPrinter for LocalPathPrinter {
531521
// pretty printing some span information. This should
532522
// only occur very early in the compiler pipeline.
533523
// FIXME(eddyb) this should just be using `tcx.def_span(impl_def_id)`
534-
let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
524+
let parent_def_id = self.tcx.parent(impl_def_id).unwrap();
535525
let path = self.print_item_path(parent_def_id, None, ns);
536526
let span = self.tcx.def_span(impl_def_id);
537527
return self.path_append(path, &format!("<impl at {:?}>", span));

src/librustc/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,14 +2893,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28932893
pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
28942894
match def {
28952895
Def::Variant(did) | Def::VariantCtor(did, ..) => {
2896-
let enum_did = self.parent_def_id(did).unwrap();
2896+
let enum_did = self.parent(did).unwrap();
28972897
self.adt_def(enum_did).variant_with_id(did)
28982898
}
28992899
Def::Struct(did) | Def::Union(did) => {
29002900
self.adt_def(did).non_enum_variant()
29012901
}
29022902
Def::StructCtor(ctor_did, ..) => {
2903-
let did = self.parent_def_id(ctor_did).expect("struct ctor has no parent");
2903+
let did = self.parent(ctor_did).expect("struct ctor has no parent");
29042904
self.adt_def(did).non_enum_variant()
29052905
}
29062906
_ => bug!("expect_variant_def used with unexpected def {:?}", def)

src/librustc/ty/sty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use polonius_engine::Atom;
99
use rustc_data_structures::indexed_vec::Idx;
1010
use rustc_macros::HashStable;
1111
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef, Kind, UnpackedKind};
12-
use crate::ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
12+
use crate::ty::{self, AdtDef, DefIdTree, TypeFlags, Ty, TyCtxt, TypeFoldable};
1313
use crate::ty::{List, TyS, ParamEnvAnd, ParamEnv};
1414
use crate::util::captures::Captures;
1515
use crate::mir::interpret::{Scalar, Pointer};
@@ -1591,7 +1591,7 @@ impl RegionKind {
15911591
pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_, '_, '_>) -> DefId {
15921592
match self {
15931593
ty::ReEarlyBound(br) => {
1594-
tcx.parent_def_id(br.def_id).unwrap()
1594+
tcx.parent(br.def_id).unwrap()
15951595
}
15961596
ty::ReFree(fr) => fr.scope,
15971597
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),

src/librustc/ty/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::hir::{self, Node};
77
use crate::mir::interpret::{sign_extend, truncate};
88
use crate::ich::NodeIdHashingMode;
99
use crate::traits::{self, ObligationCause};
10-
use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
10+
use crate::ty::{self, DefIdTree, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
1111
use crate::ty::subst::{Subst, InternalSubsts, SubstsRef, UnpackedKind};
1212
use crate::ty::query::TyCtxtAt;
1313
use crate::ty::TyKind::*;
@@ -563,7 +563,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
563563
pub fn closure_base_def_id(self, def_id: DefId) -> DefId {
564564
let mut def_id = def_id;
565565
while self.is_closure(def_id) {
566-
def_id = self.parent_def_id(def_id).unwrap_or_else(|| {
566+
def_id = self.parent(def_id).unwrap_or_else(|| {
567567
bug!("closure {:?} has no parent", def_id);
568568
});
569569
}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::mir::{ClearCrossCrate, Local, Location, Mir, Mutability, Operand, Pla
1212
use rustc::mir::{Field, Projection, ProjectionElem, Rvalue, Statement, StatementKind};
1313
use rustc::mir::{Terminator, TerminatorKind};
1414
use rustc::ty::query::Providers;
15-
use rustc::ty::{self, TyCtxt};
15+
use rustc::ty::{self, DefIdTree, TyCtxt};
1616

1717
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
1818
use rustc_data_structures::bit_set::BitSet;

0 commit comments

Comments
 (0)