@@ -377,7 +377,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
377377
378378 named_region_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . defs . get ( & id) ,
379379 is_late_bound_map,
380- object_lifetime_defaults_map : |tcx, id| match tcx. hir ( ) . find_by_def_id ( id) {
380+ object_lifetime_defaults : |tcx, id| match tcx. hir ( ) . find_by_def_id ( id) {
381381 Some ( Node :: Item ( item) ) => compute_object_lifetime_defaults ( tcx, item) ,
382382 _ => None ,
383383 } ,
@@ -1673,10 +1673,10 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
16731673 }
16741674}
16751675
1676- fn compute_object_lifetime_defaults (
1677- tcx : TyCtxt < ' _ > ,
1676+ fn compute_object_lifetime_defaults < ' tcx > (
1677+ tcx : TyCtxt < ' tcx > ,
16781678 item : & hir:: Item < ' _ > ,
1679- ) -> Option < Vec < ObjectLifetimeDefault > > {
1679+ ) -> Option < & ' tcx [ ObjectLifetimeDefault ] > {
16801680 match item. kind {
16811681 hir:: ItemKind :: Struct ( _, ref generics)
16821682 | hir:: ItemKind :: Union ( _, ref generics)
@@ -1729,10 +1729,10 @@ fn compute_object_lifetime_defaults(
17291729/// Scan the bounds and where-clauses on parameters to extract bounds
17301730/// of the form `T:'a` so as to determine the `ObjectLifetimeDefault`
17311731/// for each type parameter.
1732- fn object_lifetime_defaults_for_item (
1733- tcx : TyCtxt < ' _ > ,
1732+ fn object_lifetime_defaults_for_item < ' tcx > (
1733+ tcx : TyCtxt < ' tcx > ,
17341734 generics : & hir:: Generics < ' _ > ,
1735- ) -> Vec < ObjectLifetimeDefault > {
1735+ ) -> & ' tcx [ ObjectLifetimeDefault ] {
17361736 fn add_bounds ( set : & mut Set1 < hir:: LifetimeName > , bounds : & [ hir:: GenericBound < ' _ > ] ) {
17371737 for bound in bounds {
17381738 if let hir:: GenericBound :: Outlives ( ref lifetime) = * bound {
@@ -1741,81 +1741,75 @@ fn object_lifetime_defaults_for_item(
17411741 }
17421742 }
17431743
1744- generics
1745- . params
1746- . iter ( )
1747- . filter_map ( |param| match param. kind {
1748- GenericParamKind :: Lifetime { .. } => None ,
1749- GenericParamKind :: Type { .. } => {
1750- let mut set = Set1 :: Empty ;
1751-
1752- add_bounds ( & mut set, & param. bounds ) ;
1753-
1754- let param_def_id = tcx. hir ( ) . local_def_id ( param. hir_id ) ;
1755- for predicate in generics. where_clause . predicates {
1756- // Look for `type: ...` where clauses.
1757- let data = match * predicate {
1758- hir:: WherePredicate :: BoundPredicate ( ref data) => data,
1759- _ => continue ,
1760- } ;
1744+ let process_param = |param : & hir:: GenericParam < ' _ > | match param. kind {
1745+ GenericParamKind :: Lifetime { .. } => None ,
1746+ GenericParamKind :: Type { .. } => {
1747+ let mut set = Set1 :: Empty ;
17611748
1762- // Ignore `for<'a> type: ...` as they can change what
1763- // lifetimes mean (although we could "just" handle it).
1764- if !data. bound_generic_params . is_empty ( ) {
1765- continue ;
1766- }
1749+ add_bounds ( & mut set, & param. bounds ) ;
17671750
1768- let res = match data. bounded_ty . kind {
1769- hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) => path. res ,
1770- _ => continue ,
1771- } ;
1751+ let param_def_id = tcx. hir ( ) . local_def_id ( param. hir_id ) ;
1752+ for predicate in generics. where_clause . predicates {
1753+ // Look for `type: ...` where clauses.
1754+ let data = match * predicate {
1755+ hir:: WherePredicate :: BoundPredicate ( ref data) => data,
1756+ _ => continue ,
1757+ } ;
17721758
1773- if res == Res :: Def ( DefKind :: TyParam , param_def_id. to_def_id ( ) ) {
1774- add_bounds ( & mut set, & data. bounds ) ;
1775- }
1759+ // Ignore `for<'a> type: ...` as they can change what
1760+ // lifetimes mean (although we could "just" handle it).
1761+ if !data. bound_generic_params . is_empty ( ) {
1762+ continue ;
17761763 }
17771764
1778- Some ( match set {
1779- Set1 :: Empty => Set1 :: Empty ,
1780- Set1 :: One ( name) => {
1781- if name == hir:: LifetimeName :: Static {
1782- Set1 :: One ( Region :: Static )
1783- } else {
1784- generics
1785- . params
1786- . iter ( )
1787- . filter_map ( |param| match param. kind {
1788- GenericParamKind :: Lifetime { .. } => Some ( (
1789- param. hir_id ,
1790- hir:: LifetimeName :: Param ( param. name ) ,
1791- LifetimeDefOrigin :: from_param ( param) ,
1792- ) ) ,
1793- _ => None ,
1794- } )
1795- . enumerate ( )
1796- . find ( |& ( _, ( _, lt_name, _) ) | lt_name == name)
1797- . map_or ( Set1 :: Many , |( i, ( id, _, origin) ) | {
1798- let def_id = tcx. hir ( ) . local_def_id ( id) ;
1799- Set1 :: One ( Region :: EarlyBound (
1800- i as u32 ,
1801- def_id. to_def_id ( ) ,
1802- origin,
1803- ) )
1804- } )
1805- }
1806- }
1807- Set1 :: Many => Set1 :: Many ,
1808- } )
1809- }
1810- GenericParamKind :: Const { .. } => {
1811- // Generic consts don't impose any constraints.
1812- //
1813- // We still store a dummy value here to allow generic parameters
1814- // in an arbitrary order.
1815- Some ( Set1 :: Empty )
1765+ let res = match data. bounded_ty . kind {
1766+ hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) => path. res ,
1767+ _ => continue ,
1768+ } ;
1769+
1770+ if res == Res :: Def ( DefKind :: TyParam , param_def_id. to_def_id ( ) ) {
1771+ add_bounds ( & mut set, & data. bounds ) ;
1772+ }
18161773 }
1817- } )
1818- . collect ( )
1774+
1775+ Some ( match set {
1776+ Set1 :: Empty => Set1 :: Empty ,
1777+ Set1 :: One ( name) => {
1778+ if name == hir:: LifetimeName :: Static {
1779+ Set1 :: One ( Region :: Static )
1780+ } else {
1781+ generics
1782+ . params
1783+ . iter ( )
1784+ . filter_map ( |param| match param. kind {
1785+ GenericParamKind :: Lifetime { .. } => Some ( (
1786+ param. hir_id ,
1787+ hir:: LifetimeName :: Param ( param. name ) ,
1788+ LifetimeDefOrigin :: from_param ( param) ,
1789+ ) ) ,
1790+ _ => None ,
1791+ } )
1792+ . enumerate ( )
1793+ . find ( |& ( _, ( _, lt_name, _) ) | lt_name == name)
1794+ . map_or ( Set1 :: Many , |( i, ( id, _, origin) ) | {
1795+ let def_id = tcx. hir ( ) . local_def_id ( id) ;
1796+ Set1 :: One ( Region :: EarlyBound ( i as u32 , def_id. to_def_id ( ) , origin) )
1797+ } )
1798+ }
1799+ }
1800+ Set1 :: Many => Set1 :: Many ,
1801+ } )
1802+ }
1803+ GenericParamKind :: Const { .. } => {
1804+ // Generic consts don't impose any constraints.
1805+ //
1806+ // We still store a dummy value here to allow generic parameters
1807+ // in an arbitrary order.
1808+ Some ( Set1 :: Empty )
1809+ }
1810+ } ;
1811+
1812+ tcx. arena . alloc_from_iter ( generics. params . iter ( ) . filter_map ( process_param) )
18191813}
18201814
18211815impl < ' a , ' tcx > LifetimeContext < ' a , ' tcx > {
@@ -2510,8 +2504,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25102504 if let Some ( def_id) = def_id. as_local ( ) {
25112505 let id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
25122506 self . tcx
2513- . object_lifetime_defaults ( id)
2514- . as_ref ( )
2507+ . object_lifetime_defaults ( id. owner )
25152508 . unwrap ( )
25162509 . iter ( )
25172510 . map ( set_to_region)
0 commit comments