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