add TypeRelation and Lift impls for Kind
This commit is contained in:
parent
23837c1901
commit
5ddcd09b53
2 changed files with 35 additions and 11 deletions
|
|
@ -16,7 +16,7 @@
|
|||
use hir::def_id::DefId;
|
||||
use middle::const_val::ConstVal;
|
||||
use traits::Reveal;
|
||||
use ty::subst::{UnpackedKind, Substs};
|
||||
use ty::subst::{Kind, UnpackedKind, Substs};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use ty::error::{ExpectedFound, TypeError};
|
||||
use mir::interpret::{GlobalId, Value, PrimVal};
|
||||
|
|
@ -142,15 +142,7 @@ pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
|||
|
||||
let params = a_subst.iter().zip(b_subst).enumerate().map(|(i, (a, b))| {
|
||||
let variance = variances.map_or(ty::Invariant, |v| v[i]);
|
||||
match (a.unpack(), b.unpack()) {
|
||||
(UnpackedKind::Lifetime(a_lt), UnpackedKind::Lifetime(b_lt)) => {
|
||||
Ok(relation.relate_with_variance(variance, &a_lt, &b_lt)?.into())
|
||||
}
|
||||
(UnpackedKind::Type(a_ty), UnpackedKind::Type(b_ty)) => {
|
||||
Ok(relation.relate_with_variance(variance, &a_ty, &b_ty)?.into())
|
||||
}
|
||||
(UnpackedKind::Lifetime(_), _) | (UnpackedKind::Type(_), _) => bug!()
|
||||
}
|
||||
relation.relate_with_variance(variance, a, b)
|
||||
});
|
||||
|
||||
Ok(tcx.mk_substs(params)?)
|
||||
|
|
@ -693,6 +685,27 @@ impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Box<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Relate<'tcx> for Kind<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(
|
||||
relation: &mut R,
|
||||
a: &Kind<'tcx>,
|
||||
b: &Kind<'tcx>
|
||||
) -> RelateResult<'tcx, Kind<'tcx>>
|
||||
where
|
||||
R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a,
|
||||
{
|
||||
match (a.unpack(), b.unpack()) {
|
||||
(UnpackedKind::Lifetime(a_lt), UnpackedKind::Lifetime(b_lt)) => {
|
||||
Ok(relation.relate(&a_lt, &b_lt)?.into())
|
||||
}
|
||||
(UnpackedKind::Type(a_ty), UnpackedKind::Type(b_ty)) => {
|
||||
Ok(relation.relate(&a_ty, &b_ty)?.into())
|
||||
}
|
||||
(UnpackedKind::Lifetime(_), _) | (UnpackedKind::Type(_), _) => bug!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Error handling
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// Type substitutions.
|
||||
|
||||
use hir::def_id::DefId;
|
||||
use ty::{self, Slice, Region, Ty, TyCtxt};
|
||||
use ty::{self, Lift, Slice, Region, Ty, TyCtxt};
|
||||
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
|
||||
use serialize::{self, Encodable, Encoder, Decodable, Decoder};
|
||||
|
|
@ -113,6 +113,17 @@ impl<'tcx> fmt::Display for Kind<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for Kind<'a> {
|
||||
type Lifted = Kind<'tcx>;
|
||||
|
||||
fn lift_to_tcx<'cx, 'gcx>(&self, tcx: TyCtxt<'cx, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
match self.unpack() {
|
||||
UnpackedKind::Lifetime(a) => a.lift_to_tcx(tcx).map(|a| a.into()),
|
||||
UnpackedKind::Type(a) => a.lift_to_tcx(tcx).map(|a| a.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Kind<'tcx> {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match self.unpack() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue