@@ -571,17 +571,29 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
571
571
// We list scopes outwards, this causes us to see lifetime parameters in reverse
572
572
// declaration order. In order to make it consistent with what `generics_of` might
573
573
// give, we will reverse the IndexMap after early captures.
574
+ let mut late_depth = 0 ;
574
575
let mut scope = self . scope ;
576
+ let mut crossed_late_boundary = None ;
575
577
let mut opaque_capture_scopes = vec ! [ ( opaque. def_id, & captures) ] ;
576
578
loop {
577
579
match * scope {
578
- Scope :: Binder { ref bound_vars, s, .. } => {
580
+ Scope :: Binder { ref bound_vars, scope_type , s, .. } => {
579
581
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
+ }
580
587
if let DefKind :: LifetimeParam = self . tcx . def_kind ( original_lifetime) {
588
+ let def = def. shifted ( late_depth) ;
581
589
let ident = lifetime_ident ( original_lifetime) ;
582
590
self . remap_opaque_captures ( & opaque_capture_scopes, def, ident) ;
583
591
}
584
592
}
593
+ match scope_type {
594
+ BinderScopeType :: Normal => late_depth += 1 ,
595
+ BinderScopeType :: Concatenating => { }
596
+ }
585
597
scope = s;
586
598
}
587
599
@@ -602,6 +614,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
602
614
603
615
Scope :: Opaque { captures, def_id, s } => {
604
616
opaque_capture_scopes. push ( ( def_id, captures) ) ;
617
+ late_depth = 0 ;
605
618
scope = s;
606
619
}
607
620
@@ -611,8 +624,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
611
624
612
625
Scope :: ObjectLifetimeDefault { s, .. }
613
626
| 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) ;
616
633
scope = s;
617
634
}
618
635
}
0 commit comments