@@ -12,7 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, 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:: hir_id:: ItemLocalId ;
17
17
use rustc_hir:: intravisit:: { self , Visitor } ;
18
18
use rustc_hir:: { GenericArg , GenericParam , LifetimeName , Node } ;
@@ -156,9 +156,6 @@ pub(crate) struct LifetimeContext<'a, 'tcx> {
156
156
/// we eventually need lifetimes resolve for trait items.
157
157
trait_definition_only : bool ,
158
158
159
- /// Cache for cross-crate per-definition object lifetime defaults.
160
- xcrate_object_lifetime_defaults : DefIdMap < Vec < ObjectLifetimeDefault > > ,
161
-
162
159
/// When encountering an undefined named lifetime, we will suggest introducing it in these
163
160
/// places.
164
161
pub ( crate ) missing_named_lifetime_spots : Vec < MissingLifetimeSpot < ' tcx > > ,
@@ -348,9 +345,23 @@ pub fn provide(providers: &mut ty::query::Providers) {
348
345
349
346
named_region_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . defs . get ( & id) ,
350
347
is_late_bound_map,
351
- object_lifetime_defaults : |tcx, id| match tcx. hir ( ) . find_by_def_id ( id) {
352
- Some ( Node :: Item ( item) ) => compute_object_lifetime_defaults ( tcx, item) ,
353
- _ => None ,
348
+ object_lifetime_defaults : |tcx, def_id| {
349
+ if let Some ( def_id) = def_id. as_local ( ) {
350
+ match tcx. hir ( ) . get_by_def_id ( def_id) {
351
+ Node :: Item ( item) => compute_object_lifetime_defaults ( tcx, item) ,
352
+ _ => None ,
353
+ }
354
+ } else {
355
+ Some ( tcx. arena . alloc_from_iter ( tcx. generics_of ( def_id) . params . iter ( ) . filter_map (
356
+ |param| match param. kind {
357
+ GenericParamDefKind :: Type { object_lifetime_default, .. } => {
358
+ Some ( object_lifetime_default)
359
+ }
360
+ GenericParamDefKind :: Const { .. } => Some ( Set1 :: Empty ) ,
361
+ GenericParamDefKind :: Lifetime => None ,
362
+ } ,
363
+ ) ) )
364
+ }
354
365
} ,
355
366
late_bound_vars_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . late_bound_vars . get ( & id) ,
356
367
lifetime_scope_map : |tcx, id| {
@@ -425,7 +436,6 @@ fn do_resolve(
425
436
map : & mut named_region_map,
426
437
scope : ROOT_SCOPE ,
427
438
trait_definition_only,
428
- xcrate_object_lifetime_defaults : Default :: default ( ) ,
429
439
missing_named_lifetime_spots : vec ! [ ] ,
430
440
} ;
431
441
visitor. visit_item ( item) ;
@@ -1573,22 +1583,19 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1573
1583
F : for < ' b > FnOnce ( & mut LifetimeContext < ' b , ' tcx > ) ,
1574
1584
{
1575
1585
let LifetimeContext { tcx, map, .. } = self ;
1576
- let xcrate_object_lifetime_defaults = take ( & mut self . xcrate_object_lifetime_defaults ) ;
1577
1586
let missing_named_lifetime_spots = take ( & mut self . missing_named_lifetime_spots ) ;
1578
1587
let mut this = LifetimeContext {
1579
1588
tcx : * tcx,
1580
1589
map,
1581
1590
scope : & wrap_scope,
1582
1591
trait_definition_only : self . trait_definition_only ,
1583
- xcrate_object_lifetime_defaults,
1584
1592
missing_named_lifetime_spots,
1585
1593
} ;
1586
1594
let span = tracing:: debug_span!( "scope" , scope = ?TruncatedScopeDebug ( & this. scope) ) ;
1587
1595
{
1588
1596
let _enter = span. enter ( ) ;
1589
1597
f ( & mut this) ;
1590
1598
}
1591
- self . xcrate_object_lifetime_defaults = this. xcrate_object_lifetime_defaults ;
1592
1599
self . missing_named_lifetime_spots = this. missing_named_lifetime_spots ;
1593
1600
}
1594
1601
@@ -1904,35 +1911,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1904
1911
}
1905
1912
Set1 :: Many => None ,
1906
1913
} ;
1907
- if let Some ( def_id) = def_id. as_local ( ) {
1908
- let id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
1909
- self . tcx
1910
- . object_lifetime_defaults ( id. owner )
1911
- . unwrap ( )
1912
- . iter ( )
1913
- . map ( set_to_region)
1914
- . collect ( )
1915
- } else {
1916
- let tcx = self . tcx ;
1917
- self . xcrate_object_lifetime_defaults
1918
- . entry ( def_id)
1919
- . or_insert_with ( || {
1920
- tcx. generics_of ( def_id)
1921
- . params
1922
- . iter ( )
1923
- . filter_map ( |param| match param. kind {
1924
- GenericParamDefKind :: Type { object_lifetime_default, .. } => {
1925
- Some ( object_lifetime_default)
1926
- }
1927
- GenericParamDefKind :: Const { .. } => Some ( Set1 :: Empty ) ,
1928
- GenericParamDefKind :: Lifetime => None ,
1929
- } )
1930
- . collect ( )
1931
- } )
1932
- . iter ( )
1933
- . map ( set_to_region)
1934
- . collect ( )
1935
- }
1914
+ self . tcx . object_lifetime_defaults ( def_id) . unwrap ( ) . iter ( ) . map ( set_to_region) . collect ( )
1936
1915
} ) ;
1937
1916
1938
1917
debug ! ( "visit_segment_args: object_lifetime_defaults={:?}" , object_lifetime_defaults) ;
0 commit comments