@@ -1388,6 +1388,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
1388
1388
1389
1389
fn has_late_bound_regions < ' tcx > (
1390
1390
tcx : TyCtxt < ' tcx > ,
1391
+ def_id : LocalDefId ,
1391
1392
generics : & ' tcx hir:: Generics < ' tcx > ,
1392
1393
decl : & ' tcx hir:: FnDecl < ' tcx > ,
1393
1394
) -> Option < Span > {
@@ -1396,9 +1397,14 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
1396
1397
outer_index : ty:: INNERMOST ,
1397
1398
has_late_bound_regions : None ,
1398
1399
} ;
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
+ } ;
1399
1405
for param in generics. params {
1400
1406
if let GenericParamKind :: Lifetime { .. } = param. kind {
1401
- if tcx . is_late_bound ( param. hir_id ) {
1407
+ if is_late_bound ( param. hir_id ) {
1402
1408
return Some ( param. span ) ;
1403
1409
}
1404
1410
}
@@ -1410,25 +1416,25 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
1410
1416
match node {
1411
1417
Node :: TraitItem ( item) => match item. kind {
1412
1418
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 )
1414
1420
}
1415
1421
_ => None ,
1416
1422
} ,
1417
1423
Node :: ImplItem ( item) => match item. kind {
1418
1424
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 )
1420
1426
}
1421
1427
_ => None ,
1422
1428
} ,
1423
1429
Node :: ForeignItem ( item) => match item. kind {
1424
1430
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)
1426
1432
}
1427
1433
_ => None ,
1428
1434
} ,
1429
1435
Node :: Item ( item) => match item. kind {
1430
1436
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 )
1432
1438
}
1433
1439
_ => None ,
1434
1440
} ,
@@ -1677,7 +1683,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1677
1683
params. push ( opt_self) ;
1678
1684
}
1679
1685
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) ;
1681
1687
params. extend ( early_lifetimes. enumerate ( ) . map ( |( i, param) | ty:: GenericParamDef {
1682
1688
name : param. name . ident ( ) . name ,
1683
1689
index : own_start + i as u32 ,
@@ -2034,10 +2040,23 @@ fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity {
2034
2040
/// `resolve_lifetime::early_bound_lifetimes`.
2035
2041
fn early_bound_lifetimes_from_generics < ' a , ' tcx : ' a > (
2036
2042
tcx : TyCtxt < ' tcx > ,
2043
+ def_id : LocalDefId ,
2037
2044
generics : & ' a hir:: Generics < ' a > ,
2038
2045
) -> 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
+ } ;
2039
2058
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 ) ,
2041
2060
_ => false ,
2042
2061
} )
2043
2062
}
@@ -2221,7 +2240,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
2221
2240
// well. In the case of parameters declared on a fn or method, we
2222
2241
// have to be careful to only iterate over early-bound regions.
2223
2242
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) {
2225
2244
let region = tcx. mk_region ( ty:: ReEarlyBound ( ty:: EarlyBoundRegion {
2226
2245
def_id : tcx. hir ( ) . local_def_id ( param. hir_id ) . to_def_id ( ) ,
2227
2246
index,
0 commit comments