@@ -274,17 +274,17 @@ 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`
279
- visited : SsoHashSet < ( ty:: DebruijnIndex , I :: Ty ) > ,
277
+ // A cache for types. We may encounter the same variable at different levels of binding, so
278
+ // this can't just be `Ty`.
279
+ visited_tys : SsoHashSet < ( ty:: DebruijnIndex , I :: Ty ) > ,
280
280
}
281
281
282
282
impl < I : Interner > ValidateBoundVars < I > {
283
283
pub fn new ( bound_vars : I :: BoundVarKinds ) -> Self {
284
284
ValidateBoundVars {
285
285
bound_vars,
286
286
binder_index : ty:: INNERMOST ,
287
- visited : SsoHashSet :: default ( ) ,
287
+ visited_tys : SsoHashSet :: default ( ) ,
288
288
}
289
289
}
290
290
}
@@ -301,7 +301,7 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
301
301
302
302
fn visit_ty ( & mut self , t : I :: Ty ) -> Self :: Result {
303
303
if t. outer_exclusive_binder ( ) < self . binder_index
304
- || !self . visited . insert ( ( self . binder_index , t) )
304
+ || !self . visited_tys . insert ( ( self . binder_index , t) )
305
305
{
306
306
return ControlFlow :: Break ( ( ) ) ;
307
307
}
@@ -319,6 +319,24 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
319
319
t. super_visit_with ( self )
320
320
}
321
321
322
+ fn visit_const ( & mut self , c : I :: Const ) -> Self :: Result {
323
+ if c. outer_exclusive_binder ( ) < self . binder_index {
324
+ return ControlFlow :: Break ( ( ) ) ;
325
+ }
326
+ match c. kind ( ) {
327
+ ty:: ConstKind :: Bound ( debruijn, bound_const) if debruijn == self . binder_index => {
328
+ let idx = bound_const. var ( ) . as_usize ( ) ;
329
+ if self . bound_vars . len ( ) <= idx {
330
+ panic ! ( "Not enough bound vars: {:?} not found in {:?}" , c, self . bound_vars) ;
331
+ }
332
+ bound_const. assert_eq ( self . bound_vars . get ( idx) . unwrap ( ) ) ;
333
+ }
334
+ _ => { }
335
+ } ;
336
+
337
+ c. super_visit_with ( self )
338
+ }
339
+
322
340
fn visit_region ( & mut self , r : I :: Region ) -> Self :: Result {
323
341
match r. kind ( ) {
324
342
ty:: ReBound ( index, br) if index == self . binder_index => {
0 commit comments