match param.kind {
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
GenericParamDefKind::Type(_) => {
- trait_ref.substs.type_for_def(param).into()
+ trait_ref.substs[param.index as usize]
}
}
})
self.mk_ty_param(0, keywords::SelfType.name().as_interned_str())
}
- pub fn mk_ty_param_from_def(self, def: &ty::GenericParamDef) -> Ty<'tcx> {
- self.mk_ty_param(def.index, def.name)
+ pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {
+ match param.kind {
+ GenericParamDefKind::Lifetime => {
+ self.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
+ }
+ GenericParamDefKind::Type(_) => self.mk_ty_param(param.index, param.name).into(),
+ }
}
pub fn mk_anon(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {
// Type substitutions.
use hir::def_id::DefId;
-use ty::{self, Lift, Slice, Region, Ty, TyCtxt, GenericParamDefKind};
+use ty::{self, Lift, Slice, Region, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use serialize::{self, Encodable, Encoder, Decodable, Decoder};
pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId)
-> &'tcx Substs<'tcx> {
Substs::for_item(tcx, def_id, |param, _| {
- match param.kind {
- GenericParamDefKind::Lifetime => {
- tcx.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
- }
- GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
- }
+ tcx.mk_param_from_def(param)
})
}
}
#[inline]
- pub fn type_for_def(&self, ty_param_def: &ty::GenericParamDef) -> Ty<'tcx> {
- self.type_at(ty_param_def.index as usize)
- }
-
- #[inline]
- pub fn region_for_def(&self, def: &ty::GenericParamDef) -> ty::Region<'tcx> {
- self.region_at(def.index as usize)
+ pub fn type_for_def(&self, def: &ty::GenericParamDef) -> Kind<'tcx> {
+ self.type_at(def.index as usize).into()
}
/// Transform from substitutions for a child of `source_ancestor`
match param.kind {
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
GenericParamDefKind::Type(_) => {
- trait_ref.substs.type_for_def(param).into()
+ trait_ref.substs[param.index as usize]
}
}
});
use rustc::traits::query::{CanonicalTyGoal, NoSolution};
use rustc::traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
-use rustc::ty::subst::Subst;
+use rustc::ty::subst::{UnpackedKind, Subst};
use rustc::util::nodemap::FxHashSet;
use rustc_data_structures::sync::Lrc;
use syntax::codemap::{Span, DUMMY_SP};
debug!("dtorck_constraint: {:?}", def);
if def.is_phantom_data() {
- // The first generic parameter here is guaranteed to be a type because it's `PhantomData`.
+ // The first generic parameter here is guaranteed to be a type because it's
+ // `PhantomData`.
let param = &tcx.generics_of(def_id).params[0];
+ let ty = match tcx.mk_param_from_def(param).unpack() {
+ UnpackedKind::Type(ty) => ty,
+ _ => unreachable!(),
+ };
let result = DtorckConstraint {
outlives: vec![],
- dtorck_types: vec![tcx.mk_ty_param_from_def(param)],
+ dtorck_types: vec![ty],
overflows: vec![],
};
debug!("dtorck_constraint: {:?} => {:?}", def, result);
if let Some(parent_id) = generics.parent {
let parent_generics = tcx.generics_of(parent_id);
Substs::fill_item(&mut substs, tcx, parent_generics, &mut |param, _| {
- match param.kind {
- GenericParamDefKind::Lifetime => {
- tcx.mk_region(
- ty::ReEarlyBound(param.to_early_bound_region_data())).into()
- }
- GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
- }
+ tcx.mk_param_from_def(param)
});
// Replace all lifetimes with 'static
match param.kind {
GenericParamDefKind::Lifetime => {
// All regions are identity.
- fcx.tcx.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
+ fcx.tcx.mk_param_from_def(param)
}
GenericParamDefKind::Type(_) => {
// If the param has a default,
use middle::resolve_lifetime as rl;
use rustc::mir::mono::Linkage;
use rustc::ty::subst::Substs;
-use rustc::ty::GenericParamDefKind;
use rustc::ty::{ToPredicate, ReprOptions};
use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
use rustc::ty::maps::Providers;
let substs = ty::ClosureSubsts {
substs: Substs::for_item(tcx, def_id, |param, _| {
- match param.kind {
- GenericParamDefKind::Lifetime => {
- let region = param.to_early_bound_region_data();
- tcx.mk_region(ty::ReEarlyBound(region)).into()
- }
- GenericParamDefKind::Type(_) => tcx.mk_ty_param_from_def(param).into(),
- }
+ tcx.mk_param_from_def(param)
})
};