@@ -274,8 +274,9 @@ impl<I: Interner, T: IntoIterator> Binder<I, T> {
274
274
pub struct ValidateBoundVars < I : Interner > {
275
275
bound_vars : I :: BoundVarKinds ,
276
276
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`.
279
280
visited : SsoHashSet < ( ty:: DebruijnIndex , I :: Ty ) > ,
280
281
}
281
282
@@ -319,6 +320,24 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
319
320
t. super_visit_with ( self )
320
321
}
321
322
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
+
322
341
fn visit_region ( & mut self , r : I :: Region ) -> Self :: Result {
323
342
match r. kind ( ) {
324
343
ty:: ReBound ( index, br) if index == self . binder_index => {
0 commit comments