@@ -239,6 +239,7 @@ where
239239 first_free_index : ty:: DebruijnIndex ,
240240 scopes : & [ BoundRegionScope < ' tcx > ] ,
241241 ) -> ty:: Region < ' tcx > {
242+ debug ! ( "replace_bound_regions(scopes={:?})" , scopes) ;
242243 if let ty:: ReLateBound ( debruijn, br) = r {
243244 Self :: lookup_bound_region ( * debruijn, br, first_free_index, scopes)
244245 } else {
@@ -421,7 +422,13 @@ where
421422 // Forbid inference variables in the RHS.
422423 bug ! ( "unexpected inference var {:?}" , b)
423424 } else {
424- self . relate_ty_var ( vid, a)
425+ // We swap the order of `a` and `b` in the call to
426+ // `relate_ty_var` below, so swap the corresponding scopes
427+ // as well.
428+ std:: mem:: swap ( & mut self . a_scopes , & mut self . b_scopes ) ;
429+ let res = self . relate_ty_var ( vid, a) ;
430+ std:: mem:: swap ( & mut self . a_scopes , & mut self . b_scopes ) ;
431+ res
425432 }
426433 }
427434
@@ -436,7 +443,12 @@ where
436443 ( _, & ty:: Projection ( projection_ty) )
437444 if D :: normalization ( ) == NormalizationStrategy :: Lazy =>
438445 {
439- Ok ( self . relate_projection_ty ( projection_ty, a) )
446+ // Swap the respective scopes of `a` and `b` (see comment
447+ // above).
448+ std:: mem:: swap ( & mut self . a_scopes , & mut self . b_scopes ) ;
449+ let res = self . relate_projection_ty ( projection_ty, a) ;
450+ std:: mem:: swap ( & mut self . a_scopes , & mut self . b_scopes ) ;
451+ Ok ( res)
440452 }
441453
442454 _ => {
0 commit comments