@@ -11,7 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
11
11
use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
12
12
use rustc_hir as hir;
13
13
use rustc_hir:: def:: { DefKind , Res } ;
14
- use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LOCAL_CRATE } ;
14
+ use rustc_hir:: def_id:: { CrateNum , DefIdMap , LOCAL_CRATE } ;
15
+ use rustc_hir:: hir_id:: ItemLocalId ;
15
16
use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
16
17
use rustc_hir:: { GenericArg , GenericParam , LifetimeName , Node , ParamName , QPath } ;
17
18
use rustc_hir:: { GenericParamKind , HirIdMap , HirIdSet , LifetimeParamKind } ;
@@ -20,6 +21,7 @@ use rustc_middle::middle::resolve_lifetime::*;
20
21
use rustc_middle:: ty:: { self , DefIdTree , GenericParamDefKind , TyCtxt } ;
21
22
use rustc_middle:: { bug, span_bug} ;
22
23
use rustc_session:: lint;
24
+ use rustc_span:: def_id:: { DefId , LocalDefId } ;
23
25
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
24
26
use rustc_span:: Span ;
25
27
use std:: borrow:: Cow ;
@@ -284,7 +286,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
284
286
resolve_lifetimes,
285
287
286
288
named_region_map : |tcx, id| tcx. resolve_lifetimes ( LOCAL_CRATE ) . defs . get ( & id) ,
287
- is_late_bound_map : |tcx , id| tcx . resolve_lifetimes ( LOCAL_CRATE ) . late_bound . get ( & id ) ,
289
+ is_late_bound_map,
288
290
object_lifetime_defaults_map : |tcx, id| {
289
291
tcx. resolve_lifetimes ( LOCAL_CRATE ) . object_lifetime_defaults . get ( & id)
290
292
} ,
@@ -320,6 +322,32 @@ fn resolve_lifetimes(tcx: TyCtxt<'_>, for_krate: CrateNum) -> ResolveLifetimes {
320
322
rl
321
323
}
322
324
325
+ fn is_late_bound_map < ' tcx > (
326
+ tcx : TyCtxt < ' tcx > ,
327
+ def_id : LocalDefId ,
328
+ ) -> Option < ( LocalDefId , & ' tcx FxHashSet < ItemLocalId > ) > {
329
+ match tcx. def_kind ( def_id) {
330
+ DefKind :: AnonConst => {
331
+ let mut def_id = tcx
332
+ . parent ( def_id. to_def_id ( ) )
333
+ . unwrap_or_else ( || bug ! ( "anon const or closure without a parent" ) ) ;
334
+ // We search for the next outer anon const or fn here
335
+ // while skipping closures.
336
+ //
337
+ // Note that for `AnonConst` we still just recurse until we
338
+ // find a function body, but who cares :shrug:
339
+ while tcx. is_closure ( def_id) {
340
+ def_id = tcx
341
+ . parent ( def_id)
342
+ . unwrap_or_else ( || bug ! ( "anon const or closure without a parent" ) ) ;
343
+ }
344
+
345
+ tcx. is_late_bound_map ( def_id. expect_local ( ) )
346
+ }
347
+ _ => tcx. resolve_lifetimes ( LOCAL_CRATE ) . late_bound . get ( & def_id) . map ( |lt| ( def_id, lt) ) ,
348
+ }
349
+ }
350
+
323
351
fn krate ( tcx : TyCtxt < ' _ > ) -> NamedRegionMap {
324
352
let krate = tcx. hir ( ) . krate ( ) ;
325
353
let mut map = NamedRegionMap {
0 commit comments