Skip to content

Commit d4e0951

Browse files
varkoryodaldevoid
andcommitted
Add CanonicalVarKind::Const
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent 14f906f commit d4e0951

File tree

1 file changed

+32
-4
lines changed
  • src/librustc/infer/canonical

1 file changed

+32
-4
lines changed

src/librustc/infer/canonical/mod.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
//!
2222
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
2323
24-
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
24+
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, ConstVariableOrigin};
25+
use crate::mir::interpret::ConstValue;
2526
use rustc_data_structures::indexed_vec::IndexVec;
2627
use rustc_macros::HashStable;
2728
use serialize::UseSpecializedDecodable;
@@ -30,7 +31,7 @@ use std::ops::Index;
3031
use syntax::source_map::Span;
3132
use crate::ty::fold::TypeFoldable;
3233
use crate::ty::subst::Kind;
33-
use crate::ty::{self, BoundVar, Lift, List, Region, TyCtxt};
34+
use crate::ty::{self, BoundVar, InferConst, Lift, List, Region, TyCtxt};
3435

3536
mod canonicalizer;
3637

@@ -115,6 +116,7 @@ impl CanonicalVarInfo {
115116
CanonicalVarKind::PlaceholderTy(_) => false,
116117
CanonicalVarKind::Region(_) => true,
117118
CanonicalVarKind::PlaceholderRegion(..) => false,
119+
CanonicalVarKind::Const(_) => true,
118120
}
119121
}
120122
}
@@ -137,6 +139,9 @@ pub enum CanonicalVarKind {
137139
/// are solving a goal like `for<'a> T: Foo<'a>` to represent the
138140
/// bound region `'a`.
139141
PlaceholderRegion(ty::PlaceholderRegion),
142+
143+
/// Some kind of const inference variable.
144+
Const(ty::UniverseIndex),
140145
}
141146

142147
impl CanonicalVarKind {
@@ -150,6 +155,7 @@ impl CanonicalVarKind {
150155
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.universe,
151156
CanonicalVarKind::Region(ui) => ui,
152157
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.universe,
158+
CanonicalVarKind::Const(ui) => ui,
153159
}
154160
}
155161
}
@@ -388,6 +394,17 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
388394
};
389395
self.tcx.mk_region(ty::RePlaceholder(placeholder_mapped)).into()
390396
}
397+
398+
CanonicalVarKind::Const(ui) => {
399+
self.next_const_var_in_universe(
400+
self.next_ty_var_in_universe(
401+
TypeVariableOrigin::MiscVariable(span),
402+
universe_map(ui),
403+
),
404+
ConstVariableOrigin::MiscVariable(span),
405+
universe_map(ui),
406+
).into()
407+
}
391408
}
392409
}
393410
}
@@ -443,8 +460,19 @@ impl<'tcx> CanonicalVarValues<'tcx> {
443460
UnpackedKind::Lifetime(..) => tcx.mk_region(
444461
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(i))
445462
).into(),
446-
UnpackedKind::Const(..) => {
447-
unimplemented!() // FIXME(const_generics)
463+
UnpackedKind::Const(ct) => {
464+
let ty = match ct {
465+
ty::LazyConst::Unevaluated(def_id, _) => {
466+
tcx.type_of(*def_id)
467+
}
468+
ty::LazyConst::Evaluated(ty::Const { ty, .. }) => ty,
469+
};
470+
tcx.mk_lazy_const(ty::LazyConst::Evaluated(ty::Const {
471+
ty: ty,
472+
val: ConstValue::Infer(
473+
InferConst::Canonical(ty::INNERMOST, ty::BoundVar::from_u32(i))
474+
),
475+
})).into()
448476
}
449477
})
450478
.collect()

0 commit comments

Comments
 (0)