Skip to content

Commit 2dfde88

Browse files
varkoryodaldevoid
andcommitted
Implement structural_impls for const generics
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent 133e776 commit 2dfde88

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/librustc/ty/structural_impls.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
66
use crate::mir::ProjectionKind;
77
use crate::mir::interpret::ConstValue;
8-
use crate::ty::{self, Lift, Ty, TyCtxt};
8+
use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid, InferConst};
99
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1010
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1111
use smallvec::SmallVec;
1212
use crate::mir::interpret;
1313

14+
use std::marker::PhantomData;
1415
use std::rc::Rc;
1516

1617
///////////////////////////////////////////////////////////////////////////
@@ -49,6 +50,7 @@ CloneTypeFoldableAndLiftImpls! {
4950
crate::ty::BoundRegion,
5051
crate::ty::ClosureKind,
5152
crate::ty::IntVarValue,
53+
crate::ty::ParamConst,
5254
crate::ty::ParamTy,
5355
crate::ty::UniverseIndex,
5456
crate::ty::Variance,
@@ -503,6 +505,14 @@ impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> {
503505
type Lifted = ConstValue<'tcx>;
504506
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
505507
match *self {
508+
ConstValue::Param(param) => Some(ConstValue::Param(param)),
509+
ConstValue::Infer(infer) => {
510+
Some(ConstValue::Infer(match infer {
511+
InferConst::Var(vid) => InferConst::Var(vid.lift_to_tcx(tcx)?),
512+
InferConst::Fresh(i) => InferConst::Fresh(i),
513+
InferConst::Canonical(debrujin, var) => InferConst::Canonical(debrujin, var),
514+
}))
515+
}
506516
ConstValue::Scalar(x) => Some(ConstValue::Scalar(x)),
507517
ConstValue::Slice(x, y) => Some(ConstValue::Slice(x, y)),
508518
ConstValue::ByRef(ptr, alloc) => Some(ConstValue::ByRef(
@@ -512,6 +522,16 @@ impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> {
512522
}
513523
}
514524

525+
impl<'a, 'tcx> Lift<'tcx> for ConstVid<'a> {
526+
type Lifted = ConstVid<'tcx>;
527+
fn lift_to_tcx<'b, 'gcx>(&self, _: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
528+
Some(ConstVid {
529+
index: self.index,
530+
phantom: PhantomData,
531+
})
532+
}
533+
}
534+
515535
///////////////////////////////////////////////////////////////////////////
516536
// TypeFoldable implementations.
517537
//

0 commit comments

Comments
 (0)