Check consts in ValidateBoundVars.
Alongside the existing type and region checking.
This commit is contained in:
@@ -977,8 +977,8 @@ impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundConst {
|
|||||||
self.var
|
self.var
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_eq(self, _var: ty::BoundVariableKind) {
|
fn assert_eq(self, var: ty::BoundVariableKind) {
|
||||||
unreachable!()
|
var.expect_const()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -274,8 +274,9 @@ impl<I: Interner, T: IntoIterator> Binder<I, T> {
|
|||||||
pub struct ValidateBoundVars<I: Interner> {
|
pub struct ValidateBoundVars<I: Interner> {
|
||||||
bound_vars: I::BoundVarKinds,
|
bound_vars: I::BoundVarKinds,
|
||||||
binder_index: ty::DebruijnIndex,
|
binder_index: ty::DebruijnIndex,
|
||||||
// We may encounter the same variable at different levels of binding, so
|
// We only cache types because any complex const will have to step through
|
||||||
// this can't just be `Ty`
|
// a type at some point anyways. We may encounter the same variable at
|
||||||
|
// different levels of binding, so this can't just be `Ty`.
|
||||||
visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
|
visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +320,24 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
|
|||||||
t.super_visit_with(self)
|
t.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_const(&mut self, c: I::Const) -> Self::Result {
|
||||||
|
if c.outer_exclusive_binder() < self.binder_index {
|
||||||
|
return ControlFlow::Break(());
|
||||||
|
}
|
||||||
|
match c.kind() {
|
||||||
|
ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.binder_index => {
|
||||||
|
let idx = bound_const.var().as_usize();
|
||||||
|
if self.bound_vars.len() <= idx {
|
||||||
|
panic!("Not enough bound vars: {:?} not found in {:?}", c, self.bound_vars);
|
||||||
|
}
|
||||||
|
bound_const.assert_eq(self.bound_vars.get(idx).unwrap());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
|
||||||
|
c.super_visit_with(self)
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_region(&mut self, r: I::Region) -> Self::Result {
|
fn visit_region(&mut self, r: I::Region) -> Self::Result {
|
||||||
match r.kind() {
|
match r.kind() {
|
||||||
ty::ReBound(index, br) if index == self.binder_index => {
|
ty::ReBound(index, br) if index == self.binder_index => {
|
||||||
|
|||||||
Reference in New Issue
Block a user