@@ -274,17 +274,17 @@ 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`
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 ) > ,
280280}
281281
282282impl < I : Interner > ValidateBoundVars < I > {
283283 pub fn new ( bound_vars : I :: BoundVarKinds ) -> Self {
284284 ValidateBoundVars {
285285 bound_vars,
286286 binder_index : ty:: INNERMOST ,
287- visited : SsoHashSet :: default ( ) ,
287+ visited_tys : SsoHashSet :: default ( ) ,
288288 }
289289 }
290290}
@@ -301,7 +301,7 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
301301
302302 fn visit_ty ( & mut self , t : I :: Ty ) -> Self :: Result {
303303 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) )
305305 {
306306 return ControlFlow :: Break ( ( ) ) ;
307307 }
@@ -319,6 +319,24 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
319319 t. super_visit_with ( self )
320320 }
321321
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+
322340 fn visit_region ( & mut self , r : I :: Region ) -> Self :: Result {
323341 match r. kind ( ) {
324342 ty:: ReBound ( index, br) if index == self . binder_index => {
0 commit comments