//!
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
-use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
+use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, ConstVariableOrigin};
+use crate::mir::interpret::ConstValue;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_macros::HashStable;
use serialize::UseSpecializedDecodable;
use syntax::source_map::Span;
use crate::ty::fold::TypeFoldable;
use crate::ty::subst::Kind;
-use crate::ty::{self, BoundVar, Lift, List, Region, TyCtxt};
+use crate::ty::{self, BoundVar, InferConst, Lift, List, Region, TyCtxt};
mod canonicalizer;
CanonicalVarKind::PlaceholderTy(_) => false,
CanonicalVarKind::Region(_) => true,
CanonicalVarKind::PlaceholderRegion(..) => false,
+ CanonicalVarKind::Const(_) => true,
}
}
}
/// are solving a goal like `for<'a> T: Foo<'a>` to represent the
/// bound region `'a`.
PlaceholderRegion(ty::PlaceholderRegion),
+
+ /// Some kind of const inference variable.
+ Const(ty::UniverseIndex),
}
impl CanonicalVarKind {
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.universe,
CanonicalVarKind::Region(ui) => ui,
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.universe,
+ CanonicalVarKind::Const(ui) => ui,
}
}
}
};
self.tcx.mk_region(ty::RePlaceholder(placeholder_mapped)).into()
}
+
+ CanonicalVarKind::Const(ui) => {
+ self.next_const_var_in_universe(
+ self.next_ty_var_in_universe(
+ TypeVariableOrigin::MiscVariable(span),
+ universe_map(ui),
+ ),
+ ConstVariableOrigin::MiscVariable(span),
+ universe_map(ui),
+ ).into()
+ }
}
}
}
UnpackedKind::Lifetime(..) => tcx.mk_region(
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(i))
).into(),
- UnpackedKind::Const(..) => {
- unimplemented!() // FIXME(const_generics)
+ UnpackedKind::Const(ct) => {
+ let ty = match ct {
+ ty::LazyConst::Unevaluated(def_id, _) => {
+ tcx.type_of(*def_id)
+ }
+ ty::LazyConst::Evaluated(ty::Const { ty, .. }) => ty,
+ };
+ tcx.mk_lazy_const(ty::LazyConst::Evaluated(ty::Const {
+ ty: ty,
+ val: ConstValue::Infer(
+ InferConst::Canonical(ty::INNERMOST, ty::BoundVar::from_u32(i))
+ ),
+ })).into()
}
})
.collect()