diff options
| author | varkor <github@varkor.com> | 2019-02-20 01:18:43 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-03-05 22:17:42 +0000 |
| commit | 2dfde8843885aec59c4cf90a424bf56e3658fc9e (patch) | |
| tree | 89a892654cb7ec689024539e55ddf78acac72733 | |
| parent | 133e776bf007c78c36c85d790fcd7c62f1d58ce0 (diff) | |
| download | rust-2dfde8843885aec59c4cf90a424bf56e3658fc9e.tar.gz rust-2dfde8843885aec59c4cf90a424bf56e3658fc9e.zip | |
Implement structural_impls for const generics
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
| -rw-r--r-- | src/librustc/ty/structural_impls.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index f1a465e1f17..f9eb336a4a3 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -5,12 +5,13 @@ use crate::mir::ProjectionKind; use crate::mir::interpret::ConstValue; -use crate::ty::{self, Lift, Ty, TyCtxt}; +use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid, InferConst}; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use smallvec::SmallVec; use crate::mir::interpret; +use std::marker::PhantomData; use std::rc::Rc; /////////////////////////////////////////////////////////////////////////// @@ -49,6 +50,7 @@ CloneTypeFoldableAndLiftImpls! { crate::ty::BoundRegion, crate::ty::ClosureKind, crate::ty::IntVarValue, + crate::ty::ParamConst, crate::ty::ParamTy, crate::ty::UniverseIndex, crate::ty::Variance, @@ -503,6 +505,14 @@ impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> { type Lifted = ConstValue<'tcx>; fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { match *self { + ConstValue::Param(param) => Some(ConstValue::Param(param)), + ConstValue::Infer(infer) => { + Some(ConstValue::Infer(match infer { + InferConst::Var(vid) => InferConst::Var(vid.lift_to_tcx(tcx)?), + InferConst::Fresh(i) => InferConst::Fresh(i), + InferConst::Canonical(debrujin, var) => InferConst::Canonical(debrujin, var), + })) + } ConstValue::Scalar(x) => Some(ConstValue::Scalar(x)), ConstValue::Slice(x, y) => Some(ConstValue::Slice(x, y)), ConstValue::ByRef(ptr, alloc) => Some(ConstValue::ByRef( @@ -512,6 +522,16 @@ impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> { } } +impl<'a, 'tcx> Lift<'tcx> for ConstVid<'a> { + type Lifted = ConstVid<'tcx>; + fn lift_to_tcx<'b, 'gcx>(&self, _: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { + Some(ConstVid { + index: self.index, + phantom: PhantomData, + }) + } +} + /////////////////////////////////////////////////////////////////////////// // TypeFoldable implementations. // |
