@@ -11,7 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
1212use rustc_hir as hir;
1313use 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 ;
1516use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
1617use rustc_hir:: { GenericArg , GenericParam , LifetimeName , Node , ParamName , QPath } ;
1718use rustc_hir:: { GenericParamKind , HirIdMap , HirIdSet , LifetimeParamKind } ;
@@ -20,6 +21,7 @@ use rustc_middle::middle::resolve_lifetime::*;
2021use rustc_middle:: ty:: { self , DefIdTree , GenericParamDefKind , TyCtxt } ;
2122use rustc_middle:: { bug, span_bug} ;
2223use rustc_session:: lint;
24+ use rustc_span:: def_id:: { DefId , LocalDefId } ;
2325use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
2426use rustc_span:: Span ;
2527use std:: borrow:: Cow ;
@@ -284,7 +286,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
284286 resolve_lifetimes,
285287
286288 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,
288290 object_lifetime_defaults_map : |tcx, id| {
289291 tcx. resolve_lifetimes ( LOCAL_CRATE ) . object_lifetime_defaults . get ( & id)
290292 } ,
@@ -320,6 +322,32 @@ fn resolve_lifetimes(tcx: TyCtxt<'_>, for_krate: CrateNum) -> ResolveLifetimes {
320322 rl
321323}
322324
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+
323351fn krate ( tcx : TyCtxt < ' _ > ) -> NamedRegionMap {
324352 let krate = tcx. hir ( ) . krate ( ) ;
325353 let mut map = NamedRegionMap {
0 commit comments