@@ -12,7 +12,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
12
12
use rustc_errors:: struct_span_err;
13
13
use rustc_hir as hir;
14
14
use rustc_hir:: def:: { DefKind , Res } ;
15
- use rustc_hir:: def_id:: { DefIdMap , LocalDefId } ;
15
+ use rustc_hir:: def_id:: LocalDefId ;
16
16
use rustc_hir:: intravisit:: { self , Visitor } ;
17
17
use rustc_hir:: { GenericArg , GenericParam , LifetimeName , Node } ;
18
18
use rustc_hir:: { GenericParamKind , HirIdMap } ;
@@ -152,9 +152,6 @@ pub(crate) struct LifetimeContext<'a, 'tcx> {
152
152
/// we eventually need lifetimes resolve for trait items.
153
153
trait_definition_only : bool ,
154
154
155
- /// Cache for cross-crate per-definition object lifetime defaults.
156
- xcrate_object_lifetime_defaults : DefIdMap < Vec < ObjectLifetimeDefault > > ,
157
-
158
155
/// When encountering an undefined named lifetime, we will suggest introducing it in these
159
156
/// places.
160
157
pub ( crate ) missing_named_lifetime_spots : Vec < MissingLifetimeSpot < ' tcx > > ,
@@ -353,9 +350,23 @@ pub fn provide(providers: &mut ty::query::Providers) {
353
350
354
351
named_region_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . defs . get ( & id) ,
355
352
is_late_bound_map,
356
- object_lifetime_defaults : |tcx, id| match tcx. hir ( ) . find_by_def_id ( id) {
357
- Some ( Node :: Item ( item) ) => compute_object_lifetime_defaults ( tcx, item) ,
358
- _ => None ,
353
+ object_lifetime_defaults : |tcx, def_id| {
354
+ if let Some ( def_id) = def_id. as_local ( ) {
355
+ match tcx. hir ( ) . get_by_def_id ( def_id) {
356
+ Node :: Item ( item) => compute_object_lifetime_defaults ( tcx, item) ,
357
+ _ => None ,
358
+ }
359
+ } else {
360
+ Some ( tcx. arena . alloc_from_iter ( tcx. generics_of ( def_id) . params . iter ( ) . filter_map (
361
+ |param| match param. kind {
362
+ GenericParamDefKind :: Type { object_lifetime_default, .. } => {
363
+ Some ( object_lifetime_default)
364
+ }
365
+ GenericParamDefKind :: Const { .. } => Some ( Set1 :: Empty ) ,
366
+ GenericParamDefKind :: Lifetime => None ,
367
+ } ,
368
+ ) ) )
369
+ }
359
370
} ,
360
371
late_bound_vars_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . late_bound_vars . get ( & id) ,
361
372
@@ -422,7 +433,6 @@ fn do_resolve(
422
433
map : & mut named_region_map,
423
434
scope : ROOT_SCOPE ,
424
435
trait_definition_only,
425
- xcrate_object_lifetime_defaults : Default :: default ( ) ,
426
436
missing_named_lifetime_spots : vec ! [ ] ,
427
437
} ;
428
438
visitor. visit_item ( item) ;
@@ -1511,22 +1521,19 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1511
1521
F : for < ' b > FnOnce ( & mut LifetimeContext < ' b , ' tcx > ) ,
1512
1522
{
1513
1523
let LifetimeContext { tcx, map, .. } = self ;
1514
- let xcrate_object_lifetime_defaults = take ( & mut self . xcrate_object_lifetime_defaults ) ;
1515
1524
let missing_named_lifetime_spots = take ( & mut self . missing_named_lifetime_spots ) ;
1516
1525
let mut this = LifetimeContext {
1517
1526
tcx : * tcx,
1518
1527
map,
1519
1528
scope : & wrap_scope,
1520
1529
trait_definition_only : self . trait_definition_only ,
1521
- xcrate_object_lifetime_defaults,
1522
1530
missing_named_lifetime_spots,
1523
1531
} ;
1524
1532
let span = tracing:: debug_span!( "scope" , scope = ?TruncatedScopeDebug ( & this. scope) ) ;
1525
1533
{
1526
1534
let _enter = span. enter ( ) ;
1527
1535
f ( & mut this) ;
1528
1536
}
1529
- self . xcrate_object_lifetime_defaults = this. xcrate_object_lifetime_defaults ;
1530
1537
self . missing_named_lifetime_spots = this. missing_named_lifetime_spots ;
1531
1538
}
1532
1539
@@ -1879,35 +1886,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1879
1886
}
1880
1887
Set1 :: Many => None ,
1881
1888
} ;
1882
- if let Some ( def_id) = def_id. as_local ( ) {
1883
- let id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
1884
- self . tcx
1885
- . object_lifetime_defaults ( id. owner )
1886
- . unwrap ( )
1887
- . iter ( )
1888
- . map ( set_to_region)
1889
- . collect ( )
1890
- } else {
1891
- let tcx = self . tcx ;
1892
- self . xcrate_object_lifetime_defaults
1893
- . entry ( def_id)
1894
- . or_insert_with ( || {
1895
- tcx. generics_of ( def_id)
1896
- . params
1897
- . iter ( )
1898
- . filter_map ( |param| match param. kind {
1899
- GenericParamDefKind :: Type { object_lifetime_default, .. } => {
1900
- Some ( object_lifetime_default)
1901
- }
1902
- GenericParamDefKind :: Const { .. } => Some ( Set1 :: Empty ) ,
1903
- GenericParamDefKind :: Lifetime => None ,
1904
- } )
1905
- . collect ( )
1906
- } )
1907
- . iter ( )
1908
- . map ( set_to_region)
1909
- . collect ( )
1910
- }
1889
+ self . tcx . object_lifetime_defaults ( def_id) . unwrap ( ) . iter ( ) . map ( set_to_region) . collect ( )
1911
1890
} ) ;
1912
1891
1913
1892
debug ! ( "visit_segment_args: object_lifetime_defaults={:?}" , object_lifetime_defaults) ;
0 commit comments