@@ -177,6 +177,7 @@ enum Scope<'a> {
177
177
LateBoundary {
178
178
s : ScopeRef < ' a > ,
179
179
what : & ' static str ,
180
+ deny_late_regions : bool ,
180
181
} ,
181
182
182
183
Root {
@@ -234,9 +235,11 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
234
235
. field ( "s" , & ".." )
235
236
. finish ( ) ,
236
237
Scope :: TraitRefBoundary { s : _ } => f. debug_struct ( "TraitRefBoundary" ) . finish ( ) ,
237
- Scope :: LateBoundary { s : _, what } => {
238
- f. debug_struct ( "LateBoundary" ) . field ( "what" , what) . finish ( )
239
- }
238
+ Scope :: LateBoundary { s : _, what, deny_late_regions } => f
239
+ . debug_struct ( "LateBoundary" )
240
+ . field ( "what" , what)
241
+ . field ( "deny_late_regions" , deny_late_regions)
242
+ . finish ( ) ,
240
243
Scope :: Root { opt_parent_item } => {
241
244
f. debug_struct ( "Root" ) . field ( "opt_parent_item" , & opt_parent_item) . finish ( )
242
245
}
@@ -630,7 +633,16 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
630
633
let scope = Scope :: Opaque { captures : & captures, def_id : opaque. def_id , s : self . scope } ;
631
634
self . with ( scope, |this| {
632
635
let scope = Scope :: TraitRefBoundary { s : this. scope } ;
633
- this. with ( scope, |this| intravisit:: walk_opaque_ty ( this, opaque) )
636
+ this. with ( scope, |this| {
637
+ let scope = Scope :: LateBoundary {
638
+ s : this. scope ,
639
+ what : "nested `impl Trait`" ,
640
+ // We can capture late-bound regions; we just don't duplicate
641
+ // lifetime or const params, so we can't allow those.
642
+ deny_late_regions : false ,
643
+ } ;
644
+ this. with ( scope, |this| intravisit:: walk_opaque_ty ( this, opaque) )
645
+ } )
634
646
} ) ;
635
647
636
648
let captures = captures. into_inner ( ) . into_iter ( ) . collect ( ) ;
@@ -987,9 +999,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
987
999
}
988
1000
989
1001
fn visit_anon_const ( & mut self , c : & ' tcx hir:: AnonConst ) {
990
- self . with ( Scope :: LateBoundary { s : self . scope , what : "constant" } , |this| {
991
- intravisit:: walk_anon_const ( this, c) ;
992
- } ) ;
1002
+ self . with (
1003
+ Scope :: LateBoundary { s : self . scope , what : "constant" , deny_late_regions : true } ,
1004
+ |this| {
1005
+ intravisit:: walk_anon_const ( this, c) ;
1006
+ } ,
1007
+ ) ;
993
1008
}
994
1009
995
1010
fn visit_generic_param ( & mut self , p : & ' tcx GenericParam < ' tcx > ) {
@@ -1281,8 +1296,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1281
1296
scope = s;
1282
1297
}
1283
1298
1284
- Scope :: LateBoundary { s, what } => {
1285
- crossed_late_boundary = Some ( what) ;
1299
+ Scope :: LateBoundary { s, what, deny_late_regions } => {
1300
+ if deny_late_regions {
1301
+ crossed_late_boundary = Some ( what) ;
1302
+ }
1286
1303
scope = s;
1287
1304
}
1288
1305
}
@@ -1498,7 +1515,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1498
1515
scope = s;
1499
1516
}
1500
1517
1501
- Scope :: LateBoundary { s, what } => {
1518
+ Scope :: LateBoundary { s, what, deny_late_regions : _ } => {
1502
1519
crossed_late_boundary = Some ( what) ;
1503
1520
scope = s;
1504
1521
}
0 commit comments