@@ -1568,14 +1568,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15681568
15691569 // This creates HIR lifetime arguments as `hir::GenericArg`, in the given example `type
15701570 // 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
15721572 . iter ( )
1573- . map ( |( _ , lifetime) | {
1573+ . map ( |( node_id , lifetime) | {
15741574 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)
15761578 } )
15771579 . collect ( ) ;
1578- debug ! ( ?lifetimes ) ;
1580+ debug ! ( ?lifetime_mapping ) ;
15791581
15801582 self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
15811583 // Install the remapping from old to new (if any):
@@ -1626,6 +1628,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16261628 } ) ,
16271629 bounds : hir_bounds,
16281630 origin,
1631+ lifetime_mapping : self . arena . alloc_from_iter (
1632+ lifetime_mapping. iter ( ) . map ( |( lifetime, def_id) | ( * * lifetime, * def_id) ) ,
1633+ ) ,
16291634 in_trait,
16301635 } ;
16311636 debug ! ( ?opaque_ty_item) ;
@@ -1634,17 +1639,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16341639 } )
16351640 } ) ;
16361641
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-
16441642 // `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
16451643 hir:: TyKind :: OpaqueDef (
16461644 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+ ) ,
16481648 in_trait,
16491649 )
16501650 }
@@ -1986,7 +1986,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19861986 let lifetime = Lifetime { id : outer_node_id, ident } ;
19871987 collected_lifetimes. push ( ( inner_node_id, lifetime, Some ( inner_res) ) ) ;
19881988 }
1989-
19901989 debug ! ( ?collected_lifetimes) ;
19911990
19921991 // 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> {
20072006 debug ! ( ?collected_lifetimes) ;
20082007 debug ! ( ?new_remapping) ;
20092008
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
20132014 . iter ( )
2014- . map ( |( _ , lifetime, res) | {
2015+ . map ( |( node_id , lifetime, res) | {
20152016 let id = self . next_node_id ( ) ;
20162017 let res = res. unwrap_or (
20172018 self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ,
20182019 ) ;
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)
20202023 } )
20212024 . collect ( ) ;
2022- debug ! ( ?lifetimes ) ;
2025+ debug ! ( ?lifetime_mapping ) ;
20232026
20242027 self . with_hir_id_owner ( opaque_ty_node_id, |this| {
20252028 // Install the remapping from old to new (if any):
@@ -2086,6 +2089,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20862089 } ) ,
20872090 bounds : arena_vec ! [ this; future_bound] ,
20882091 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+ ) ,
20892095 in_trait,
20902096 } ;
20912097
@@ -2109,9 +2115,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21092115 //
21102116 // For the "output" lifetime parameters, we just want to
21112117 // 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+ ) ;
21152121
21162122 // Create the `Foo<...>` reference itself. Note that the `type
21172123 // Foo = impl Trait` is, internally, created as a child of the
0 commit comments