@@ -571,17 +571,29 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
571571 // We list scopes outwards, this causes us to see lifetime parameters in reverse
572572 // declaration order. In order to make it consistent with what `generics_of` might
573573 // give, we will reverse the IndexMap after early captures.
574+ let mut late_depth = 0 ;
574575 let mut scope = self . scope ;
576+ let mut crossed_late_boundary = None ;
575577 let mut opaque_capture_scopes = vec ! [ ( opaque. def_id, & captures) ] ;
576578 loop {
577579 match * scope {
578- Scope :: Binder { ref bound_vars, s, .. } => {
580+ Scope :: Binder { ref bound_vars, scope_type , s, .. } => {
579581 for ( & original_lifetime, & def) in bound_vars. iter ( ) . rev ( ) {
582+ if let ResolvedArg :: LateBound ( ..) = def
583+ && crossed_late_boundary. is_some ( )
584+ {
585+ continue ;
586+ }
580587 if let DefKind :: LifetimeParam = self . tcx . def_kind ( original_lifetime) {
588+ let def = def. shifted ( late_depth) ;
581589 let ident = lifetime_ident ( original_lifetime) ;
582590 self . remap_opaque_captures ( & opaque_capture_scopes, def, ident) ;
583591 }
584592 }
593+ match scope_type {
594+ BinderScopeType :: Normal => late_depth += 1 ,
595+ BinderScopeType :: Concatenating => { }
596+ }
585597 scope = s;
586598 }
587599
@@ -602,6 +614,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
602614
603615 Scope :: Opaque { captures, def_id, s } => {
604616 opaque_capture_scopes. push ( ( def_id, captures) ) ;
617+ late_depth = 0 ;
605618 scope = s;
606619 }
607620
@@ -611,8 +624,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
611624
612625 Scope :: ObjectLifetimeDefault { s, .. }
613626 | Scope :: Supertrait { s, .. }
614- | Scope :: TraitRefBoundary { s, .. }
615- | Scope :: LateBoundary { s, .. } => {
627+ | Scope :: TraitRefBoundary { s, .. } => {
628+ scope = s;
629+ }
630+
631+ Scope :: LateBoundary { s, what, .. } => {
632+ crossed_late_boundary = Some ( what) ;
616633 scope = s;
617634 }
618635 }
0 commit comments