1+ // ignore-tidy-filelength
12//! Name resolution for lifetimes.
23//!
34//! Name resolution for lifetimes follows *much* simpler rules than the
@@ -230,6 +231,10 @@ enum Scope<'a> {
230231 hir_id : hir:: HirId ,
231232
232233 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 ,
233238 } ,
234239
235240 /// 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> {
302307 scope_type,
303308 hir_id,
304309 s : _,
310+ allow_late_bound,
305311 } => f
306312 . debug_struct ( "Binder" )
307313 . field ( "lifetimes" , lifetimes)
@@ -311,6 +317,7 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
311317 . field ( "scope_type" , scope_type)
312318 . field ( "hir_id" , hir_id)
313319 . field ( "s" , & ".." )
320+ . field ( "allow_late_bound" , allow_late_bound)
314321 . finish ( ) ,
315322 Scope :: Body { id, s : _ } => {
316323 f. debug_struct ( "Body" ) . field ( "id" , id) . field ( "s" , & ".." ) . finish ( )
@@ -703,6 +710,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
703710 track_lifetime_uses : true ,
704711 opaque_type_parent : false ,
705712 scope_type : BinderScopeType :: Normal ,
713+ allow_late_bound : true ,
706714 } ;
707715 self . with ( scope, move |_old_scope, this| {
708716 intravisit:: walk_fn ( this, fk, fd, b, s, hir_id)
@@ -828,6 +836,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
828836 track_lifetime_uses,
829837 scope_type : BinderScopeType :: Normal ,
830838 s : ROOT_SCOPE ,
839+ allow_late_bound : false ,
831840 } ;
832841 self . with ( scope, |old_scope, this| {
833842 this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -896,6 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
896905 track_lifetime_uses : true ,
897906 opaque_type_parent : false ,
898907 scope_type : BinderScopeType :: Normal ,
908+ allow_late_bound : true ,
899909 } ;
900910 self . with ( scope, |old_scope, this| {
901911 // a bare fn has no bounds, so everything
@@ -1077,6 +1087,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10771087 track_lifetime_uses : true ,
10781088 opaque_type_parent : false ,
10791089 scope_type : BinderScopeType :: Normal ,
1090+ allow_late_bound : false ,
10801091 } ;
10811092 this. with ( scope, |_old_scope, this| {
10821093 this. visit_generics ( generics) ;
@@ -1097,6 +1108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10971108 track_lifetime_uses : true ,
10981109 opaque_type_parent : false ,
10991110 scope_type : BinderScopeType :: Normal ,
1111+ allow_late_bound : false ,
11001112 } ;
11011113 self . with ( scope, |_old_scope, this| {
11021114 let scope = Scope :: TraitRefBoundary { s : this. scope } ;
@@ -1156,6 +1168,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11561168 track_lifetime_uses : true ,
11571169 opaque_type_parent : true ,
11581170 scope_type : BinderScopeType :: Normal ,
1171+ allow_late_bound : false ,
11591172 } ;
11601173 self . with ( scope, |old_scope, this| {
11611174 this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -1225,6 +1238,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
12251238 track_lifetime_uses : true ,
12261239 opaque_type_parent : true ,
12271240 scope_type : BinderScopeType :: Normal ,
1241+ allow_late_bound : true ,
12281242 } ;
12291243 self . with ( scope, |old_scope, this| {
12301244 this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -1378,6 +1392,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
13781392 track_lifetime_uses : true ,
13791393 opaque_type_parent : false ,
13801394 scope_type : BinderScopeType :: Normal ,
1395+ allow_late_bound : true ,
13811396 } ;
13821397 this. with ( scope, |old_scope, this| {
13831398 this. check_lifetime_params ( old_scope, & bound_generic_params) ;
@@ -1425,6 +1440,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
14251440 track_lifetime_uses : true ,
14261441 opaque_type_parent : false ,
14271442 scope_type,
1443+ allow_late_bound : true ,
14281444 } ;
14291445 self . with ( scope, |_, this| {
14301446 intravisit:: walk_param_bound ( this, bound) ;
@@ -1477,6 +1493,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
14771493 track_lifetime_uses : true ,
14781494 opaque_type_parent : false ,
14791495 scope_type,
1496+ allow_late_bound : true ,
14801497 } ;
14811498 self . with ( scope, |old_scope, this| {
14821499 this. check_lifetime_params ( old_scope, & trait_ref. bound_generic_params ) ;
@@ -2180,6 +2197,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
21802197 opaque_type_parent : true ,
21812198 track_lifetime_uses : false ,
21822199 scope_type : BinderScopeType :: Normal ,
2200+ allow_late_bound : true ,
21832201 } ;
21842202 self . with ( scope, move |old_scope, this| {
21852203 this. check_lifetime_params ( old_scope, & generics. params ) ;
@@ -2602,7 +2620,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26022620 let mut scope = & * self . scope ;
26032621 let hir_id = loop {
26042622 match scope {
2605- Scope :: Binder { hir_id, .. } => {
2623+ Scope :: Binder { hir_id, allow_late_bound : true , .. } => {
26062624 break * hir_id;
26072625 }
26082626 Scope :: ObjectLifetimeDefault { ref s, .. }
@@ -2611,8 +2629,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26112629 | Scope :: TraitRefBoundary { ref s, .. } => {
26122630 scope = * s;
26132631 }
2614- Scope :: Root | Scope :: Body { .. } => {
2632+ Scope :: Root
2633+ | Scope :: Body { .. }
2634+ | Scope :: Binder { allow_late_bound : false , .. } => {
26152635 // See issues #83907 and #83693. Just bail out from looking inside.
2636+ // See the issue #95023 for not allowing late bound
26162637 self . tcx . sess . delay_span_bug (
26172638 rustc_span:: DUMMY_SP ,
26182639 "In fn_like_elision without appropriate scope above" ,
0 commit comments