Skip to content

Commit 0a9371a

Browse files
committed
Add mk_param_from_def
1 parent e9c28b2 commit 0a9371a

File tree

8 files changed

+24
-37
lines changed

8 files changed

+24
-37
lines changed

src/librustc/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ fn vtable_methods<'a, 'tcx>(
845845
match param.kind {
846846
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
847847
GenericParamDefKind::Type(_) => {
848-
trait_ref.substs.type_for_def(param).into()
848+
trait_ref.substs[param.index as usize]
849849
}
850850
}
851851
})

src/librustc/ty/context.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,8 +2472,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24722472
self.mk_ty_param(0, keywords::SelfType.name().as_interned_str())
24732473
}
24742474

2475-
pub fn mk_ty_param_from_def(self, def: &ty::GenericParamDef) -> Ty<'tcx> {
2476-
self.mk_ty_param(def.index, def.name)
2475+
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {
2476+
match param.kind {
2477+
GenericParamDefKind::Lifetime => {
2478+
self.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
2479+
}
2480+
GenericParamDefKind::Type(_) => self.mk_ty_param(param.index, param.name).into(),
2481+
}
24772482
}
24782483

24792484
pub fn mk_anon(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {

src/librustc/ty/subst.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Type substitutions.
1212

1313
use hir::def_id::DefId;
14-
use ty::{self, Lift, Slice, Region, Ty, TyCtxt, GenericParamDefKind};
14+
use ty::{self, Lift, Slice, Region, Ty, TyCtxt};
1515
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1616

1717
use serialize::{self, Encodable, Encoder, Decodable, Decoder};
@@ -182,12 +182,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
182182
pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId)
183183
-> &'tcx Substs<'tcx> {
184184
Substs::for_item(tcx, def_id, |param, _| {
185-
match param.kind {
186-
GenericParamDefKind::Lifetime => {
187-
tcx.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
188-
}
189-
GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
190-
}
185+
tcx.mk_param_from_def(param)
191186
})
192187
}
193188

@@ -293,13 +288,8 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
293288
}
294289

295290
#[inline]
296-
pub fn type_for_def(&self, ty_param_def: &ty::GenericParamDef) -> Ty<'tcx> {
297-
self.type_at(ty_param_def.index as usize)
298-
}
299-
300-
#[inline]
301-
pub fn region_for_def(&self, def: &ty::GenericParamDef) -> ty::Region<'tcx> {
302-
self.region_at(def.index as usize)
291+
pub fn type_for_def(&self, def: &ty::GenericParamDef) -> Kind<'tcx> {
292+
self.type_at(def.index as usize).into()
303293
}
304294

305295
/// Transform from substitutions for a child of `source_ancestor`

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11161116
match param.kind {
11171117
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
11181118
GenericParamDefKind::Type(_) => {
1119-
trait_ref.substs.type_for_def(param).into()
1119+
trait_ref.substs[param.index as usize]
11201120
}
11211121
}
11221122
});

src/librustc_traits/dropck_outlives.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc::traits::{FulfillmentContext, Normalized, ObligationCause};
1414
use rustc::traits::query::{CanonicalTyGoal, NoSolution};
1515
use rustc::traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
1616
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
17-
use rustc::ty::subst::Subst;
17+
use rustc::ty::subst::{UnpackedKind, Subst};
1818
use rustc::util::nodemap::FxHashSet;
1919
use rustc_data_structures::sync::Lrc;
2020
use syntax::codemap::{Span, DUMMY_SP};
@@ -278,11 +278,16 @@ crate fn adt_dtorck_constraint<'a, 'tcx>(
278278
debug!("dtorck_constraint: {:?}", def);
279279

280280
if def.is_phantom_data() {
281-
// The first generic parameter here is guaranteed to be a type because it's `PhantomData`.
281+
// The first generic parameter here is guaranteed to be a type because it's
282+
// `PhantomData`.
282283
let param = &tcx.generics_of(def_id).params[0];
284+
let ty = match tcx.mk_param_from_def(param).unpack() {
285+
UnpackedKind::Type(ty) => ty,
286+
_ => unreachable!(),
287+
};
283288
let result = DtorckConstraint {
284289
outlives: vec![],
285-
dtorck_types: vec![tcx.mk_ty_param_from_def(param)],
290+
dtorck_types: vec![ty],
286291
overflows: vec![],
287292
};
288293
debug!("dtorck_constraint: {:?} => {:?}", def, result);

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,13 +1158,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11581158
if let Some(parent_id) = generics.parent {
11591159
let parent_generics = tcx.generics_of(parent_id);
11601160
Substs::fill_item(&mut substs, tcx, parent_generics, &mut |param, _| {
1161-
match param.kind {
1162-
GenericParamDefKind::Lifetime => {
1163-
tcx.mk_region(
1164-
ty::ReEarlyBound(param.to_early_bound_region_data())).into()
1165-
}
1166-
GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
1167-
}
1161+
tcx.mk_param_from_def(param)
11681162
});
11691163

11701164
// Replace all lifetimes with 'static

src/librustc_typeck/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
409409
match param.kind {
410410
GenericParamDefKind::Lifetime => {
411411
// All regions are identity.
412-
fcx.tcx.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
412+
fcx.tcx.mk_param_from_def(param)
413413
}
414414
GenericParamDefKind::Type(_) => {
415415
// If the param has a default,

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use middle::lang_items::SizedTraitLangItem;
3131
use middle::resolve_lifetime as rl;
3232
use rustc::mir::mono::Linkage;
3333
use rustc::ty::subst::Substs;
34-
use rustc::ty::GenericParamDefKind;
3534
use rustc::ty::{ToPredicate, ReprOptions};
3635
use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
3736
use rustc::ty::maps::Providers;
@@ -1098,13 +1097,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10981097

10991098
let substs = ty::ClosureSubsts {
11001099
substs: Substs::for_item(tcx, def_id, |param, _| {
1101-
match param.kind {
1102-
GenericParamDefKind::Lifetime => {
1103-
let region = param.to_early_bound_region_data();
1104-
tcx.mk_region(ty::ReEarlyBound(region)).into()
1105-
}
1106-
GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
1107-
}
1100+
tcx.mk_param_from_def(param)
11081101
})
11091102
};
11101103

0 commit comments

Comments
 (0)