@@ -12,7 +12,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1212use rustc_errors:: struct_span_err;
1313use rustc_hir as hir;
1414use rustc_hir:: def:: { DefKind , Res } ;
15- use rustc_hir:: def_id:: { DefIdMap , LocalDefId } ;
15+ use rustc_hir:: def_id:: LocalDefId ;
1616use rustc_hir:: intravisit:: { self , Visitor } ;
1717use rustc_hir:: { GenericArg , GenericParam , LifetimeName , Node } ;
1818use rustc_hir:: { GenericParamKind , HirIdMap } ;
@@ -152,9 +152,6 @@ pub(crate) struct LifetimeContext<'a, 'tcx> {
152152 /// we eventually need lifetimes resolve for trait items.
153153 trait_definition_only : bool ,
154154
155- /// Cache for cross-crate per-definition object lifetime defaults.
156- xcrate_object_lifetime_defaults : DefIdMap < Vec < ObjectLifetimeDefault > > ,
157-
158155 /// When encountering an undefined named lifetime, we will suggest introducing it in these
159156 /// places.
160157 pub ( crate ) missing_named_lifetime_spots : Vec < MissingLifetimeSpot < ' tcx > > ,
@@ -353,9 +350,23 @@ pub fn provide(providers: &mut ty::query::Providers) {
353350
354351 named_region_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . defs . get ( & id) ,
355352 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+ }
359370 } ,
360371 late_bound_vars_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . late_bound_vars . get ( & id) ,
361372
@@ -422,7 +433,6 @@ fn do_resolve(
422433 map : & mut named_region_map,
423434 scope : ROOT_SCOPE ,
424435 trait_definition_only,
425- xcrate_object_lifetime_defaults : Default :: default ( ) ,
426436 missing_named_lifetime_spots : vec ! [ ] ,
427437 } ;
428438 visitor. visit_item ( item) ;
@@ -1511,22 +1521,19 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15111521 F : for < ' b > FnOnce ( & mut LifetimeContext < ' b , ' tcx > ) ,
15121522 {
15131523 let LifetimeContext { tcx, map, .. } = self ;
1514- let xcrate_object_lifetime_defaults = take ( & mut self . xcrate_object_lifetime_defaults ) ;
15151524 let missing_named_lifetime_spots = take ( & mut self . missing_named_lifetime_spots ) ;
15161525 let mut this = LifetimeContext {
15171526 tcx : * tcx,
15181527 map,
15191528 scope : & wrap_scope,
15201529 trait_definition_only : self . trait_definition_only ,
1521- xcrate_object_lifetime_defaults,
15221530 missing_named_lifetime_spots,
15231531 } ;
15241532 let span = tracing:: debug_span!( "scope" , scope = ?TruncatedScopeDebug ( & this. scope) ) ;
15251533 {
15261534 let _enter = span. enter ( ) ;
15271535 f ( & mut this) ;
15281536 }
1529- self . xcrate_object_lifetime_defaults = this. xcrate_object_lifetime_defaults ;
15301537 self . missing_named_lifetime_spots = this. missing_named_lifetime_spots ;
15311538 }
15321539
@@ -1879,35 +1886,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
18791886 }
18801887 Set1 :: Many => None ,
18811888 } ;
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 ( )
19111890 } ) ;
19121891
19131892 debug ! ( "visit_segment_args: object_lifetime_defaults={:?}" , object_lifetime_defaults) ;
0 commit comments