Skip to content

Commit c50ec78

Browse files
committed
rustc: remove TyCtxt::parent_def_id in favor of TyCtxt::parent.
1 parent 4e280d9 commit c50ec78

File tree

15 files changed

+38
-48
lines changed

15 files changed

+38
-48
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 hir;
55
use infer::error_reporting::nice_region_error::NiceRegionError;
6-
use ty::{self, Region, Ty};
6+
use ty::{self, DefIdTree, Region, Ty};
77
use 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 hir::CodegenFnAttrFlags;
1212
use hir::def_id::{DefId, LOCAL_CRATE};
1313
use lint;
1414
use middle::privacy;
15-
use ty::{self, TyCtxt};
15+
use ty::{self, DefIdTree, TyCtxt};
1616
use 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 hir::Node;
6464
use infer::InferCtxt;
6565
use hir::def::{Def, CtorKind};
6666
use ty::adjustment;
67-
use ty::{self, Ty, TyCtxt};
67+
use ty::{self, DefIdTree, Ty, TyCtxt};
6868
use ty::fold::TypeFoldable;
6969
use 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
@@ -16,7 +16,7 @@ use rustc_data_structures::sync::Lrc;
1616
use syntax::source_map;
1717
use syntax::ast;
1818
use syntax_pos::{Span, DUMMY_SP};
19-
use ty::TyCtxt;
19+
use ty::{DefIdTree, TyCtxt};
2020
use ty::query::Providers;
2121

2222
use hir;
@@ -648,7 +648,7 @@ impl<'tcx> ScopeTree {
648648
pub fn early_free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
649649
br: &ty::EarlyBoundRegion)
650650
-> Scope {
651-
let param_owner = tcx.parent_def_id(br.def_id).unwrap();
651+
let param_owner = tcx.parent(br.def_id).unwrap();
652652

653653
let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap();
654654
let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| {
@@ -677,7 +677,7 @@ impl<'tcx> ScopeTree {
677677
-> Scope {
678678
let param_owner = match fr.bound_region {
679679
ty::BoundRegion::BrNamed(def_id, _) => {
680-
tcx.parent_def_id(def_id).unwrap()
680+
tcx.parent(def_id).unwrap()
681681
}
682682
_ => fr.scope
683683
};

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use ty::subst::{Kind, Substs, Subst};
2727
use ty::ReprOptions;
2828
use traits;
2929
use traits::{Clause, Clauses, GoalKind, Goal, Goals};
30-
use ty::{self, Ty, TypeAndMut};
30+
use ty::{self, DefIdTree, Ty, TypeAndMut};
3131
use ty::{TyS, TyKind, List};
3232
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const, LazyConst};
3333
use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
@@ -1599,7 +1599,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15991599
let (suitable_region_binding_scope, bound_region) = match *region {
16001600
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
16011601
ty::ReEarlyBound(ref ebr) => (
1602-
self.parent_def_id(ebr.def_id).unwrap(),
1602+
self.parent(ebr.def_id).unwrap(),
16031603
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
16041604
),
16051605
_ => 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
@@ -153,13 +153,13 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
153153
data @ DefPathData::ClosureExpr |
154154
data @ DefPathData::ImplTrait |
155155
data @ DefPathData::GlobalMetaData(..) => {
156-
let parent_did = self.tcx.parent_def_id(def_id).unwrap();
156+
let parent_did = self.tcx.parent(def_id).unwrap();
157157
let path = self.print_item_path(parent_did, None, ns);
158158
self.path_append(path, &data.as_interned_str().as_symbol().as_str())
159159
},
160160

161161
DefPathData::StructCtor => { // present `X` instead of `X::{{constructor}}`
162-
let parent_def_id = self.tcx.parent_def_id(def_id).unwrap();
162+
let parent_def_id = self.tcx.parent(def_id).unwrap();
163163
self.print_item_path(parent_def_id, substs, ns)
164164
}
165165
}
@@ -172,7 +172,7 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
172172
ns: Namespace,
173173
) -> P::Path {
174174
debug!("default_print_impl_path: impl_def_id={:?}", impl_def_id);
175-
let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
175+
let parent_def_id = self.tcx.parent(impl_def_id).unwrap();
176176

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

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

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

250-
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
251-
/// Returns the def-id of `def_id`'s parent in the def tree. If
252-
/// this returns `None`, then `def_id` represents a crate root or
253-
/// inlined root.
254-
pub fn parent_def_id(self, def_id: DefId) -> Option<DefId> {
255-
let key = self.def_key(def_id);
256-
key.parent.map(|index| DefId { krate: def_id.krate, index: index })
257-
}
258-
}
259-
260250
/// As a heuristic, when we see an impl, if we see that the
261251
/// 'self-type' is a type defined in the same module as the impl,
262252
/// we can omit including the path to the impl itself. This
@@ -533,7 +523,7 @@ impl ItemPathPrinter for LocalPathPrinter {
533523
// pretty printing some span information. This should
534524
// only occur very early in the compiler pipeline.
535525
// FIXME(eddyb) this should just be using `tcx.def_span(impl_def_id)`
536-
let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
526+
let parent_def_id = self.tcx.parent(impl_def_id).unwrap();
537527
let path = self.print_item_path(parent_def_id, None, ns);
538528
let span = self.tcx.def_span(impl_def_id);
539529
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
@@ -2871,14 +2871,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28712871
pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
28722872
match def {
28732873
Def::Variant(did) | Def::VariantCtor(did, ..) => {
2874-
let enum_did = self.parent_def_id(did).unwrap();
2874+
let enum_did = self.parent(did).unwrap();
28752875
self.adt_def(enum_did).variant_with_id(did)
28762876
}
28772877
Def::Struct(did) | Def::Union(did) => {
28782878
self.adt_def(did).non_enum_variant()
28792879
}
28802880
Def::StructCtor(ctor_did, ..) => {
2881-
let did = self.parent_def_id(ctor_did).expect("struct ctor has no parent");
2881+
let did = self.parent(ctor_did).expect("struct ctor has no parent");
28822882
self.adt_def(did).non_enum_variant()
28832883
}
28842884
_ => 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
@@ -8,7 +8,7 @@ use middle::region;
88
use polonius_engine::Atom;
99
use rustc_data_structures::indexed_vec::Idx;
1010
use ty::subst::{Substs, Subst, Kind, UnpackedKind};
11-
use ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
11+
use ty::{self, AdtDef, DefIdTree, TypeFlags, Ty, TyCtxt, TypeFoldable};
1212
use ty::{List, TyS, ParamEnvAnd, ParamEnv};
1313
use util::captures::Captures;
1414
use mir::interpret::{Scalar, Pointer};
@@ -1550,7 +1550,7 @@ impl RegionKind {
15501550
pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_, '_, '_>) -> DefId {
15511551
match self {
15521552
ty::ReEarlyBound(br) => {
1553-
tcx.parent_def_id(br.def_id).unwrap()
1553+
tcx.parent(br.def_id).unwrap()
15541554
}
15551555
ty::ReFree(fr) => fr.scope,
15561556
_ => 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
@@ -6,7 +6,7 @@ use hir::map::DefPathData;
66
use hir::{self, Node};
77
use ich::NodeIdHashingMode;
88
use traits::{self, ObligationCause};
9-
use ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
9+
use ty::{self, DefIdTree, Ty, TyCtxt, GenericParamDefKind, TypeFoldable};
1010
use ty::subst::{Subst, Substs, UnpackedKind};
1111
use ty::query::TyCtxtAt;
1212
use ty::TyKind::*;
@@ -551,7 +551,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
551551
pub fn closure_base_def_id(self, def_id: DefId) -> DefId {
552552
let mut def_id = def_id;
553553
while self.is_closure(def_id) {
554-
def_id = self.parent_def_id(def_id).unwrap_or_else(|| {
554+
def_id = self.parent(def_id).unwrap_or_else(|| {
555555
bug!("closure {:?} has no parent", def_id);
556556
});
557557
}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 2 additions & 2 deletions
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;
@@ -345,7 +345,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
345345
}
346346

347347
if tcx.is_closure(curr_def_id) {
348-
curr_def_id = tcx.parent_def_id(curr_def_id)
348+
curr_def_id = tcx.parent(curr_def_id)
349349
.expect("a closure must have a parent_def_id");
350350
} else {
351351
break SignalledError::NoErrorsSeen;

0 commit comments

Comments
 (0)