@@ -274,8 +274,9 @@ impl<I: Interner, T: IntoIterator> Binder<I, T> {
274274pub struct ValidateBoundVars < I : Interner > {
275275 bound_vars : I :: BoundVarKinds ,
276276 binder_index : ty:: DebruijnIndex ,
277- // We may encounter the same variable at different levels of binding, so
278- // this can't just be `Ty`
277+ // We only cache types because any complex const will have to step through
278+ // a type at some point anyways. We may encounter the same variable at
279+ // different levels of binding, so this can't just be `Ty`.
279280 visited : SsoHashSet < ( ty:: DebruijnIndex , I :: Ty ) > ,
280281}
281282
@@ -319,6 +320,24 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
319320 t. super_visit_with ( self )
320321 }
321322
323+ fn visit_const ( & mut self , c : I :: Const ) -> Self :: Result {
324+ if c. outer_exclusive_binder ( ) < self . binder_index {
325+ return ControlFlow :: Break ( ( ) ) ;
326+ }
327+ match c. kind ( ) {
328+ ty:: ConstKind :: Bound ( debruijn, bound_const) if debruijn == self . binder_index => {
329+ let idx = bound_const. var ( ) . as_usize ( ) ;
330+ if self . bound_vars . len ( ) <= idx {
331+ panic ! ( "Not enough bound vars: {:?} not found in {:?}" , c, self . bound_vars) ;
332+ }
333+ bound_const. assert_eq ( self . bound_vars . get ( idx) . unwrap ( ) ) ;
334+ }
335+ _ => { }
336+ } ;
337+
338+ c. super_visit_with ( self )
339+ }
340+
322341 fn visit_region ( & mut self , r : I :: Region ) -> Self :: Result {
323342 match r. kind ( ) {
324343 ty:: ReBound ( index, br) if index == self . binder_index => {
0 commit comments