1
+ // ignore-tidy-filelength
1
2
//! Name resolution for lifetimes.
2
3
//!
3
4
//! Name resolution for lifetimes follows *much* simpler rules than the
@@ -230,6 +231,10 @@ enum Scope<'a> {
230
231
hir_id : hir:: HirId ,
231
232
232
233
s : ScopeRef < ' a > ,
234
+
235
+ /// In some cases not allowing late bounds allows us to avoid ICEs.
236
+ /// This is almost ways set to true.
237
+ allow_late_bound : bool ,
233
238
} ,
234
239
235
240
/// Lifetimes introduced by a fn are scoped to the call-site for that fn,
@@ -302,6 +307,7 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
302
307
scope_type,
303
308
hir_id,
304
309
s : _,
310
+ allow_late_bound,
305
311
} => f
306
312
. debug_struct ( "Binder" )
307
313
. field ( "lifetimes" , lifetimes)
@@ -311,6 +317,7 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
311
317
. field ( "scope_type" , scope_type)
312
318
. field ( "hir_id" , hir_id)
313
319
. field ( "s" , & ".." )
320
+ . field ( "allow_late_bound" , allow_late_bound)
314
321
. finish ( ) ,
315
322
Scope :: Body { id, s : _ } => {
316
323
f. debug_struct ( "Body" ) . field ( "id" , id) . field ( "s" , & ".." ) . finish ( )
@@ -703,6 +710,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
703
710
track_lifetime_uses : true ,
704
711
opaque_type_parent : false ,
705
712
scope_type : BinderScopeType :: Normal ,
713
+ allow_late_bound : true ,
706
714
} ;
707
715
self . with ( scope, move |_old_scope, this| {
708
716
intravisit:: walk_fn ( this, fk, fd, b, s, hir_id)
@@ -828,6 +836,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
828
836
track_lifetime_uses,
829
837
scope_type : BinderScopeType :: Normal ,
830
838
s : ROOT_SCOPE ,
839
+ allow_late_bound : false ,
831
840
} ;
832
841
self . with ( scope, |old_scope, this| {
833
842
this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -896,6 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
896
905
track_lifetime_uses : true ,
897
906
opaque_type_parent : false ,
898
907
scope_type : BinderScopeType :: Normal ,
908
+ allow_late_bound : true ,
899
909
} ;
900
910
self . with ( scope, |old_scope, this| {
901
911
// a bare fn has no bounds, so everything
@@ -1077,6 +1087,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1077
1087
track_lifetime_uses : true ,
1078
1088
opaque_type_parent : false ,
1079
1089
scope_type : BinderScopeType :: Normal ,
1090
+ allow_late_bound : false ,
1080
1091
} ;
1081
1092
this. with ( scope, |_old_scope, this| {
1082
1093
this. visit_generics ( generics) ;
@@ -1097,6 +1108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1097
1108
track_lifetime_uses : true ,
1098
1109
opaque_type_parent : false ,
1099
1110
scope_type : BinderScopeType :: Normal ,
1111
+ allow_late_bound : false ,
1100
1112
} ;
1101
1113
self . with ( scope, |_old_scope, this| {
1102
1114
let scope = Scope :: TraitRefBoundary { s : this. scope } ;
@@ -1156,6 +1168,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1156
1168
track_lifetime_uses : true ,
1157
1169
opaque_type_parent : true ,
1158
1170
scope_type : BinderScopeType :: Normal ,
1171
+ allow_late_bound : false ,
1159
1172
} ;
1160
1173
self . with ( scope, |old_scope, this| {
1161
1174
this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -1225,6 +1238,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1225
1238
track_lifetime_uses : true ,
1226
1239
opaque_type_parent : true ,
1227
1240
scope_type : BinderScopeType :: Normal ,
1241
+ allow_late_bound : true ,
1228
1242
} ;
1229
1243
self . with ( scope, |old_scope, this| {
1230
1244
this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -1378,6 +1392,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1378
1392
track_lifetime_uses : true ,
1379
1393
opaque_type_parent : false ,
1380
1394
scope_type : BinderScopeType :: Normal ,
1395
+ allow_late_bound : true ,
1381
1396
} ;
1382
1397
this. with ( scope, |old_scope, this| {
1383
1398
this. check_lifetime_params ( old_scope, & bound_generic_params) ;
@@ -1425,6 +1440,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1425
1440
track_lifetime_uses : true ,
1426
1441
opaque_type_parent : false ,
1427
1442
scope_type,
1443
+ allow_late_bound : true ,
1428
1444
} ;
1429
1445
self . with ( scope, |_, this| {
1430
1446
intravisit:: walk_param_bound ( this, bound) ;
@@ -1477,6 +1493,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1477
1493
track_lifetime_uses : true ,
1478
1494
opaque_type_parent : false ,
1479
1495
scope_type,
1496
+ allow_late_bound : true ,
1480
1497
} ;
1481
1498
self . with ( scope, |old_scope, this| {
1482
1499
this. check_lifetime_params ( old_scope, & trait_ref. bound_generic_params ) ;
@@ -2180,6 +2197,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2180
2197
opaque_type_parent : true ,
2181
2198
track_lifetime_uses : false ,
2182
2199
scope_type : BinderScopeType :: Normal ,
2200
+ allow_late_bound : true ,
2183
2201
} ;
2184
2202
self . with ( scope, move |old_scope, this| {
2185
2203
this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -2602,7 +2620,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2602
2620
let mut scope = & * self . scope ;
2603
2621
let hir_id = loop {
2604
2622
match scope {
2605
- Scope :: Binder { hir_id, .. } => {
2623
+ Scope :: Binder { hir_id, allow_late_bound : true , .. } => {
2606
2624
break * hir_id;
2607
2625
}
2608
2626
Scope :: ObjectLifetimeDefault { ref s, .. }
@@ -2611,8 +2629,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2611
2629
| Scope :: TraitRefBoundary { ref s, .. } => {
2612
2630
scope = * s;
2613
2631
}
2614
- Scope :: Root | Scope :: Body { .. } => {
2632
+ Scope :: Root
2633
+ | Scope :: Body { .. }
2634
+ | Scope :: Binder { allow_late_bound : false , .. } => {
2615
2635
// See issues #83907 and #83693. Just bail out from looking inside.
2636
+ // See the issue #95023 for not allowing late bound
2616
2637
self . tcx . sess . delay_span_bug (
2617
2638
rustc_span:: DUMMY_SP ,
2618
2639
"In fn_like_elision without appropriate scope above" ,
0 commit comments