@@ -276,15 +276,17 @@ pub struct ValidateBoundVars<I: Interner> {
276276 binder_index : ty:: DebruijnIndex ,
277277 // We may encounter the same variable at different levels of binding, so
278278 // 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 ) > ,
280281}
281282
282283impl < I : Interner > ValidateBoundVars < I > {
283284 pub fn new ( bound_vars : I :: BoundVarKinds ) -> Self {
284285 ValidateBoundVars {
285286 bound_vars,
286287 binder_index : ty:: INNERMOST ,
287- visited : SsoHashSet :: default ( ) ,
288+ visited_tys : SsoHashSet :: default ( ) ,
289+ visited_consts : SsoHashSet :: default ( ) ,
288290 }
289291 }
290292}
@@ -301,7 +303,7 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
301303
302304 fn visit_ty ( & mut self , t : I :: Ty ) -> Self :: Result {
303305 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) )
305307 {
306308 return ControlFlow :: Break ( ( ) ) ;
307309 }
@@ -319,6 +321,26 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
319321 t. super_visit_with ( self )
320322 }
321323
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+
322344 fn visit_region ( & mut self , r : I :: Region ) -> Self :: Result {
323345 match r. kind ( ) {
324346 ty:: ReBound ( index, br) if index == self . binder_index => {
0 commit comments