@@ -11,7 +11,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
11
11
use rustc_errors:: struct_span_err;
12
12
use rustc_hir as hir;
13
13
use rustc_hir:: def:: { DefKind , Res } ;
14
- use rustc_hir:: def_id:: { DefIdMap , LocalDefId } ;
14
+ use rustc_hir:: def_id:: LocalDefId ;
15
15
use rustc_hir:: intravisit:: { self , Visitor } ;
16
16
use rustc_hir:: { GenericArg , GenericParam , GenericParamKind , HirIdMap , LifetimeName , Node } ;
17
17
use rustc_middle:: bug;
@@ -24,7 +24,6 @@ use rustc_span::symbol::{sym, Ident};
24
24
use rustc_span:: Span ;
25
25
use std:: borrow:: Cow ;
26
26
use std:: fmt;
27
- use std:: mem:: take;
28
27
29
28
trait RegionExt {
30
29
fn early ( hir_map : Map < ' _ > , index : & mut u32 , param : & GenericParam < ' _ > ) -> ( LocalDefId , Region ) ;
@@ -131,9 +130,6 @@ pub(crate) struct LifetimeContext<'a, 'tcx> {
131
130
/// be false if the `Item` we are resolving lifetimes for is not a trait or
132
131
/// we eventually need lifetimes resolve for trait items.
133
132
trait_definition_only : bool ,
134
-
135
- /// Cache for cross-crate per-definition object lifetime defaults.
136
- xcrate_object_lifetime_defaults : DefIdMap < Vec < ObjectLifetimeDefault > > ,
137
133
}
138
134
139
135
#[ derive( Debug ) ]
@@ -294,9 +290,23 @@ pub fn provide(providers: &mut ty::query::Providers) {
294
290
295
291
named_region_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . defs . get ( & id) ,
296
292
is_late_bound_map,
297
- object_lifetime_defaults : |tcx, id| match tcx. hir ( ) . find_by_def_id ( id) {
298
- Some ( Node :: Item ( item) ) => compute_object_lifetime_defaults ( tcx, item) ,
299
- _ => None ,
293
+ object_lifetime_defaults : |tcx, def_id| {
294
+ if let Some ( def_id) = def_id. as_local ( ) {
295
+ match tcx. hir ( ) . get_by_def_id ( def_id) {
296
+ Node :: Item ( item) => compute_object_lifetime_defaults ( tcx, item) ,
297
+ _ => None ,
298
+ }
299
+ } else {
300
+ Some ( tcx. arena . alloc_from_iter ( tcx. generics_of ( def_id) . params . iter ( ) . filter_map (
301
+ |param| match param. kind {
302
+ GenericParamDefKind :: Type { object_lifetime_default, .. } => {
303
+ Some ( object_lifetime_default)
304
+ }
305
+ GenericParamDefKind :: Const { .. } => Some ( Set1 :: Empty ) ,
306
+ GenericParamDefKind :: Lifetime => None ,
307
+ } ,
308
+ ) ) )
309
+ }
300
310
} ,
301
311
late_bound_vars_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . late_bound_vars . get ( & id) ,
302
312
@@ -363,7 +373,6 @@ fn do_resolve(
363
373
map : & mut named_region_map,
364
374
scope : ROOT_SCOPE ,
365
375
trait_definition_only,
366
- xcrate_object_lifetime_defaults : Default :: default ( ) ,
367
376
} ;
368
377
visitor. visit_item ( item) ;
369
378
@@ -1413,20 +1422,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1413
1422
F : for < ' b > FnOnce ( & mut LifetimeContext < ' b , ' tcx > ) ,
1414
1423
{
1415
1424
let LifetimeContext { tcx, map, .. } = self ;
1416
- let xcrate_object_lifetime_defaults = take ( & mut self . xcrate_object_lifetime_defaults ) ;
1417
1425
let mut this = LifetimeContext {
1418
1426
tcx : * tcx,
1419
1427
map,
1420
1428
scope : & wrap_scope,
1421
1429
trait_definition_only : self . trait_definition_only ,
1422
- xcrate_object_lifetime_defaults,
1423
1430
} ;
1424
1431
let span = tracing:: debug_span!( "scope" , scope = ?TruncatedScopeDebug ( & this. scope) ) ;
1425
1432
{
1426
1433
let _enter = span. enter ( ) ;
1427
1434
f ( & mut this) ;
1428
1435
}
1429
- self . xcrate_object_lifetime_defaults = this. xcrate_object_lifetime_defaults ;
1430
1436
}
1431
1437
1432
1438
/// Visits self by adding a scope and handling recursive walk over the contents with `walk`.
@@ -1780,35 +1786,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1780
1786
}
1781
1787
Set1 :: Many => None ,
1782
1788
} ;
1783
- if let Some ( def_id) = def_id. as_local ( ) {
1784
- let id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
1785
- self . tcx
1786
- . object_lifetime_defaults ( id. owner )
1787
- . unwrap ( )
1788
- . iter ( )
1789
- . map ( set_to_region)
1790
- . collect ( )
1791
- } else {
1792
- let tcx = self . tcx ;
1793
- self . xcrate_object_lifetime_defaults
1794
- . entry ( def_id)
1795
- . or_insert_with ( || {
1796
- tcx. generics_of ( def_id)
1797
- . params
1798
- . iter ( )
1799
- . filter_map ( |param| match param. kind {
1800
- GenericParamDefKind :: Type { object_lifetime_default, .. } => {
1801
- Some ( object_lifetime_default)
1802
- }
1803
- GenericParamDefKind :: Const { .. } => Some ( Set1 :: Empty ) ,
1804
- GenericParamDefKind :: Lifetime => None ,
1805
- } )
1806
- . collect ( )
1807
- } )
1808
- . iter ( )
1809
- . map ( set_to_region)
1810
- . collect ( )
1811
- }
1789
+ self . tcx . object_lifetime_defaults ( def_id) . unwrap ( ) . iter ( ) . map ( set_to_region) . collect ( )
1812
1790
} ) ;
1813
1791
1814
1792
debug ! ( "visit_segment_args: object_lifetime_defaults={:?}" , object_lifetime_defaults) ;
0 commit comments