From 2dfde8843885aec59c4cf90a424bf56e3658fc9e Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 20 Feb 2019 01:18:43 +0000 Subject: [PATCH] Implement structural_impls for const generics Co-Authored-By: Gabriel Smith --- src/librustc/ty/structural_impls.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index f1a465e1f172..f9eb336a4a3e 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 { 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 { + Some(ConstVid { + index: self.index, + phantom: PhantomData, + }) + } +} + /////////////////////////////////////////////////////////////////////////// // TypeFoldable implementations. //