@@ -12,7 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, 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:: hir_id:: ItemLocalId ;
1717use rustc_hir:: intravisit:: { self , Visitor } ;
1818use rustc_hir:: { GenericArg , GenericParam , LifetimeName , Node } ;
@@ -156,9 +156,6 @@ pub(crate) struct LifetimeContext<'a, 'tcx> {
156156 /// we eventually need lifetimes resolve for trait items.
157157 trait_definition_only : bool ,
158158
159- /// Cache for cross-crate per-definition object lifetime defaults.
160- xcrate_object_lifetime_defaults : DefIdMap < Vec < ObjectLifetimeDefault > > ,
161-
162159 /// When encountering an undefined named lifetime, we will suggest introducing it in these
163160 /// places.
164161 pub ( crate ) missing_named_lifetime_spots : Vec < MissingLifetimeSpot < ' tcx > > ,
@@ -348,9 +345,23 @@ pub fn provide(providers: &mut ty::query::Providers) {
348345
349346 named_region_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . defs . get ( & id) ,
350347 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+ }
354365 } ,
355366 late_bound_vars_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . late_bound_vars . get ( & id) ,
356367 lifetime_scope_map : |tcx, id| {
@@ -425,7 +436,6 @@ fn do_resolve(
425436 map : & mut named_region_map,
426437 scope : ROOT_SCOPE ,
427438 trait_definition_only,
428- xcrate_object_lifetime_defaults : Default :: default ( ) ,
429439 missing_named_lifetime_spots : vec ! [ ] ,
430440 } ;
431441 visitor. visit_item ( item) ;
@@ -1573,22 +1583,19 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15731583 F : for < ' b > FnOnce ( & mut LifetimeContext < ' b , ' tcx > ) ,
15741584 {
15751585 let LifetimeContext { tcx, map, .. } = self ;
1576- let xcrate_object_lifetime_defaults = take ( & mut self . xcrate_object_lifetime_defaults ) ;
15771586 let missing_named_lifetime_spots = take ( & mut self . missing_named_lifetime_spots ) ;
15781587 let mut this = LifetimeContext {
15791588 tcx : * tcx,
15801589 map,
15811590 scope : & wrap_scope,
15821591 trait_definition_only : self . trait_definition_only ,
1583- xcrate_object_lifetime_defaults,
15841592 missing_named_lifetime_spots,
15851593 } ;
15861594 let span = tracing:: debug_span!( "scope" , scope = ?TruncatedScopeDebug ( & this. scope) ) ;
15871595 {
15881596 let _enter = span. enter ( ) ;
15891597 f ( & mut this) ;
15901598 }
1591- self . xcrate_object_lifetime_defaults = this. xcrate_object_lifetime_defaults ;
15921599 self . missing_named_lifetime_spots = this. missing_named_lifetime_spots ;
15931600 }
15941601
@@ -1904,35 +1911,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19041911 }
19051912 Set1 :: Many => None ,
19061913 } ;
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 ( )
19361915 } ) ;
19371916
19381917 debug ! ( "visit_segment_args: object_lifetime_defaults={:?}" , object_lifetime_defaults) ;
0 commit comments