@@ -1568,14 +1568,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1568
1568
1569
1569
// This creates HIR lifetime arguments as `hir::GenericArg`, in the given example `type
1570
1570
// TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing `&['x]`.
1571
- let lifetimes : Vec < _ > = collected_lifetimes
1571
+ let lifetime_mapping : Vec < _ > = collected_lifetimes
1572
1572
. iter ( )
1573
- . map ( |( _ , lifetime) | {
1573
+ . map ( |( node_id , lifetime) | {
1574
1574
let id = self . next_node_id ( ) ;
1575
- self . new_named_lifetime ( lifetime. id , id, lifetime. ident )
1575
+ let lifetime = self . new_named_lifetime ( lifetime. id , id, lifetime. ident ) ;
1576
+ let def_id = self . local_def_id ( * node_id) ;
1577
+ ( lifetime, def_id)
1576
1578
} )
1577
1579
. collect ( ) ;
1578
- debug ! ( ?lifetimes ) ;
1580
+ debug ! ( ?lifetime_mapping ) ;
1579
1581
1580
1582
self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
1581
1583
// Install the remapping from old to new (if any):
@@ -1626,6 +1628,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1626
1628
} ) ,
1627
1629
bounds : hir_bounds,
1628
1630
origin,
1631
+ lifetime_mapping : self . arena . alloc_from_iter (
1632
+ lifetime_mapping. iter ( ) . map ( |( lifetime, def_id) | ( * * lifetime, * def_id) ) ,
1633
+ ) ,
1629
1634
in_trait,
1630
1635
} ;
1631
1636
debug ! ( ?opaque_ty_item) ;
@@ -1634,17 +1639,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1634
1639
} )
1635
1640
} ) ;
1636
1641
1637
- // This creates HIR lifetime arguments as `hir::GenericArg`, in the given example `type
1638
- // TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing `&['x]`.
1639
- let lifetimes = self . arena . alloc_from_iter (
1640
- lifetimes. into_iter ( ) . map ( |lifetime| hir:: GenericArg :: Lifetime ( lifetime) ) ,
1641
- ) ;
1642
- debug ! ( ?lifetimes) ;
1643
-
1644
1642
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
1645
1643
hir:: TyKind :: OpaqueDef (
1646
1644
hir:: ItemId { owner_id : hir:: OwnerId { def_id : opaque_ty_def_id } } ,
1647
- lifetimes,
1645
+ self . arena . alloc_from_iter (
1646
+ lifetime_mapping. iter ( ) . map ( |( lifetime, _) | hir:: GenericArg :: Lifetime ( * lifetime) ) ,
1647
+ ) ,
1648
1648
in_trait,
1649
1649
)
1650
1650
}
@@ -1986,7 +1986,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1986
1986
let lifetime = Lifetime { id : outer_node_id, ident } ;
1987
1987
collected_lifetimes. push ( ( inner_node_id, lifetime, Some ( inner_res) ) ) ;
1988
1988
}
1989
-
1990
1989
debug ! ( ?collected_lifetimes) ;
1991
1990
1992
1991
// We only want to capture the lifetimes that appear in the bounds. So visit the bounds to
@@ -2007,19 +2006,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2007
2006
debug ! ( ?collected_lifetimes) ;
2008
2007
debug ! ( ?new_remapping) ;
2009
2008
2010
- // This creates HIR lifetime arguments as `hir::GenericArg`, in the given example `type
2011
- // TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing `&['x]`.
2012
- let lifetimes: Vec < _ > = collected_lifetimes
2009
+ // This creates pairs of HIR lifetimes and def_ids. In the given example `type
2010
+ // TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing the
2011
+ // new lifetime of the RPIT 'x and the def_id of the lifetime 'x corresponding to
2012
+ // `TestReturn`.
2013
+ let lifetime_mapping: Vec < _ > = collected_lifetimes
2013
2014
. iter ( )
2014
- . map ( |( _ , lifetime, res) | {
2015
+ . map ( |( node_id , lifetime, res) | {
2015
2016
let id = self . next_node_id ( ) ;
2016
2017
let res = res. unwrap_or (
2017
2018
self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ,
2018
2019
) ;
2019
- self . new_named_lifetime_with_res ( id, lifetime. ident , res)
2020
+ let lifetime = self . new_named_lifetime_with_res ( id, lifetime. ident , res) ;
2021
+ let def_id = self . local_def_id ( * node_id) ;
2022
+ ( lifetime, def_id)
2020
2023
} )
2021
2024
. collect ( ) ;
2022
- debug ! ( ?lifetimes ) ;
2025
+ debug ! ( ?lifetime_mapping ) ;
2023
2026
2024
2027
self . with_hir_id_owner ( opaque_ty_node_id, |this| {
2025
2028
// Install the remapping from old to new (if any):
@@ -2086,6 +2089,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2086
2089
} ) ,
2087
2090
bounds : arena_vec ! [ this; future_bound] ,
2088
2091
origin : hir:: OpaqueTyOrigin :: AsyncFn ( fn_def_id) ,
2092
+ lifetime_mapping : self . arena . alloc_from_iter (
2093
+ lifetime_mapping. iter ( ) . map ( |( lifetime, def_id) | ( * * lifetime, * def_id) ) ,
2094
+ ) ,
2089
2095
in_trait,
2090
2096
} ;
2091
2097
@@ -2109,9 +2115,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2109
2115
//
2110
2116
// For the "output" lifetime parameters, we just want to
2111
2117
// generate `'_`.
2112
- let generic_args = self
2113
- . arena
2114
- . alloc_from_iter ( lifetimes . iter ( ) . map ( |lifetime| hir :: GenericArg :: Lifetime ( * lifetime ) ) ) ;
2118
+ let generic_args = self . arena . alloc_from_iter (
2119
+ lifetime_mapping . iter ( ) . map ( | ( lifetime , _ ) | hir :: GenericArg :: Lifetime ( * lifetime ) ) ,
2120
+ ) ;
2115
2121
2116
2122
// Create the `Foo<...>` reference itself. Note that the `type
2117
2123
// Foo = impl Trait` is, internally, created as a child of the
0 commit comments