@@ -377,7 +377,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
377
377
378
378
named_region_map : |tcx, id| resolve_lifetimes_for ( tcx, id) . defs . get ( & id) ,
379
379
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) {
381
381
Some ( Node :: Item ( item) ) => compute_object_lifetime_defaults ( tcx, item) ,
382
382
_ => None ,
383
383
} ,
@@ -1673,10 +1673,10 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
1673
1673
}
1674
1674
}
1675
1675
1676
- fn compute_object_lifetime_defaults (
1677
- tcx : TyCtxt < ' _ > ,
1676
+ fn compute_object_lifetime_defaults < ' tcx > (
1677
+ tcx : TyCtxt < ' tcx > ,
1678
1678
item : & hir:: Item < ' _ > ,
1679
- ) -> Option < Vec < ObjectLifetimeDefault > > {
1679
+ ) -> Option < & ' tcx [ ObjectLifetimeDefault ] > {
1680
1680
match item. kind {
1681
1681
hir:: ItemKind :: Struct ( _, ref generics)
1682
1682
| hir:: ItemKind :: Union ( _, ref generics)
@@ -1729,10 +1729,10 @@ fn compute_object_lifetime_defaults(
1729
1729
/// Scan the bounds and where-clauses on parameters to extract bounds
1730
1730
/// of the form `T:'a` so as to determine the `ObjectLifetimeDefault`
1731
1731
/// 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 > ,
1734
1734
generics : & hir:: Generics < ' _ > ,
1735
- ) -> Vec < ObjectLifetimeDefault > {
1735
+ ) -> & ' tcx [ ObjectLifetimeDefault ] {
1736
1736
fn add_bounds ( set : & mut Set1 < hir:: LifetimeName > , bounds : & [ hir:: GenericBound < ' _ > ] ) {
1737
1737
for bound in bounds {
1738
1738
if let hir:: GenericBound :: Outlives ( ref lifetime) = * bound {
@@ -1741,81 +1741,75 @@ fn object_lifetime_defaults_for_item(
1741
1741
}
1742
1742
}
1743
1743
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 ;
1761
1748
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 ) ;
1767
1750
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
+ } ;
1772
1758
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 ;
1776
1763
}
1777
1764
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
+ }
1816
1773
}
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) )
1819
1813
}
1820
1814
1821
1815
impl < ' a , ' tcx > LifetimeContext < ' a , ' tcx > {
@@ -2510,8 +2504,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2510
2504
if let Some ( def_id) = def_id. as_local ( ) {
2511
2505
let id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
2512
2506
self . tcx
2513
- . object_lifetime_defaults ( id)
2514
- . as_ref ( )
2507
+ . object_lifetime_defaults ( id. owner )
2515
2508
. unwrap ( )
2516
2509
. iter ( )
2517
2510
. map ( set_to_region)
0 commit comments