@@ -1388,6 +1388,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
13881388
13891389 fn has_late_bound_regions < ' tcx > (
13901390 tcx : TyCtxt < ' tcx > ,
1391+ def_id : LocalDefId ,
13911392 generics : & ' tcx hir:: Generics < ' tcx > ,
13921393 decl : & ' tcx hir:: FnDecl < ' tcx > ,
13931394 ) -> Option < Span > {
@@ -1396,9 +1397,14 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
13961397 outer_index : ty:: INNERMOST ,
13971398 has_late_bound_regions : None ,
13981399 } ;
1400+ let late_bound_map = tcx. is_late_bound_map ( def_id) ;
1401+ let is_late_bound = |id| {
1402+ let id = tcx. hir ( ) . local_def_id ( id) ;
1403+ late_bound_map. map_or ( false , |( _, set) | set. contains ( & id) )
1404+ } ;
13991405 for param in generics. params {
14001406 if let GenericParamKind :: Lifetime { .. } = param. kind {
1401- if tcx . is_late_bound ( param. hir_id ) {
1407+ if is_late_bound ( param. hir_id ) {
14021408 return Some ( param. span ) ;
14031409 }
14041410 }
@@ -1410,25 +1416,25 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
14101416 match node {
14111417 Node :: TraitItem ( item) => match item. kind {
14121418 hir:: TraitItemKind :: Fn ( ref sig, _) => {
1413- has_late_bound_regions ( tcx, & item. generics , sig. decl )
1419+ has_late_bound_regions ( tcx, item . def_id , & item. generics , sig. decl )
14141420 }
14151421 _ => None ,
14161422 } ,
14171423 Node :: ImplItem ( item) => match item. kind {
14181424 hir:: ImplItemKind :: Fn ( ref sig, _) => {
1419- has_late_bound_regions ( tcx, & item. generics , sig. decl )
1425+ has_late_bound_regions ( tcx, item . def_id , & item. generics , sig. decl )
14201426 }
14211427 _ => None ,
14221428 } ,
14231429 Node :: ForeignItem ( item) => match item. kind {
14241430 hir:: ForeignItemKind :: Fn ( fn_decl, _, ref generics) => {
1425- has_late_bound_regions ( tcx, generics, fn_decl)
1431+ has_late_bound_regions ( tcx, item . def_id , generics, fn_decl)
14261432 }
14271433 _ => None ,
14281434 } ,
14291435 Node :: Item ( item) => match item. kind {
14301436 hir:: ItemKind :: Fn ( ref sig, .., ref generics, _) => {
1431- has_late_bound_regions ( tcx, generics, sig. decl )
1437+ has_late_bound_regions ( tcx, item . def_id , generics, sig. decl )
14321438 }
14331439 _ => None ,
14341440 } ,
@@ -1677,7 +1683,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
16771683 params. push ( opt_self) ;
16781684 }
16791685
1680- let early_lifetimes = early_bound_lifetimes_from_generics ( tcx, ast_generics) ;
1686+ let early_lifetimes = early_bound_lifetimes_from_generics ( tcx, hir_id . owner , ast_generics) ;
16811687 params. extend ( early_lifetimes. enumerate ( ) . map ( |( i, param) | ty:: GenericParamDef {
16821688 name : param. name . ident ( ) . name ,
16831689 index : own_start + i as u32 ,
@@ -2034,10 +2040,23 @@ fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity {
20342040/// `resolve_lifetime::early_bound_lifetimes`.
20352041fn early_bound_lifetimes_from_generics < ' a , ' tcx : ' a > (
20362042 tcx : TyCtxt < ' tcx > ,
2043+ def_id : LocalDefId ,
20372044 generics : & ' a hir:: Generics < ' a > ,
20382045) -> impl Iterator < Item = & ' a hir:: GenericParam < ' a > > + Captures < ' tcx > {
2046+ let late_bound_map = if generics. params . is_empty ( ) {
2047+ // This function may be called on `def_id == CRATE_DEF_ID`,
2048+ // which makes `is_late_bound_map` ICE. Don't even try if there
2049+ // is no generic parameter.
2050+ None
2051+ } else {
2052+ tcx. is_late_bound_map ( def_id)
2053+ } ;
2054+ let is_late_bound = move |hir_id| {
2055+ let id = tcx. hir ( ) . local_def_id ( hir_id) ;
2056+ late_bound_map. map_or ( false , |( _, set) | set. contains ( & id) )
2057+ } ;
20392058 generics. params . iter ( ) . filter ( move |param| match param. kind {
2040- GenericParamKind :: Lifetime { .. } => !tcx . is_late_bound ( param. hir_id ) ,
2059+ GenericParamKind :: Lifetime { .. } => !is_late_bound ( param. hir_id ) ,
20412060 _ => false ,
20422061 } )
20432062}
@@ -2221,7 +2240,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
22212240 // well. In the case of parameters declared on a fn or method, we
22222241 // have to be careful to only iterate over early-bound regions.
22232242 let mut index = parent_count + has_own_self as u32 ;
2224- for param in early_bound_lifetimes_from_generics ( tcx, ast_generics) {
2243+ for param in early_bound_lifetimes_from_generics ( tcx, hir_id . owner , ast_generics) {
22252244 let region = tcx. mk_region ( ty:: ReEarlyBound ( ty:: EarlyBoundRegion {
22262245 def_id : tcx. hir ( ) . local_def_id ( param. hir_id ) . to_def_id ( ) ,
22272246 index,
0 commit comments