@@ -1568,7 +1568,7 @@ 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 lifetime_mapping : Vec < _ > = collected_lifetimes
1571+ let collected_lifetime_mapping : Vec < _ > = collected_lifetimes
15721572 . iter ( )
15731573 . map ( |( node_id, lifetime) | {
15741574 let id = self . next_node_id ( ) ;
@@ -1577,7 +1577,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15771577 ( lifetime, def_id)
15781578 } )
15791579 . collect ( ) ;
1580- debug ! ( ?lifetime_mapping ) ;
1580+ debug ! ( ?collected_lifetime_mapping ) ;
15811581
15821582 self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
15831583 // Install the remapping from old to new (if any):
@@ -1618,6 +1618,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16181618 let hir_bounds = lctx. lower_param_bounds ( bounds, itctx) ;
16191619 debug ! ( ?hir_bounds) ;
16201620
1621+ let lifetime_mapping = if in_trait {
1622+ self . arena . alloc_from_iter (
1623+ collected_lifetime_mapping
1624+ . iter ( )
1625+ . map ( |( lifetime, def_id) | ( * * lifetime, * def_id) ) ,
1626+ )
1627+ } else {
1628+ & mut [ ]
1629+ } ;
1630+
16211631 let opaque_ty_item = hir:: OpaqueTy {
16221632 generics : self . arena . alloc ( hir:: Generics {
16231633 params : lifetime_defs,
@@ -1628,9 +1638,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16281638 } ) ,
16291639 bounds : hir_bounds,
16301640 origin,
1631- lifetime_mapping : self . arena . alloc_from_iter (
1632- lifetime_mapping. iter ( ) . map ( |( lifetime, def_id) | ( * * lifetime, * def_id) ) ,
1633- ) ,
1641+ lifetime_mapping,
16341642 in_trait,
16351643 } ;
16361644 debug ! ( ?opaque_ty_item) ;
@@ -1643,7 +1651,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16431651 hir:: TyKind :: OpaqueDef (
16441652 hir:: ItemId { owner_id : hir:: OwnerId { def_id : opaque_ty_def_id } } ,
16451653 self . arena . alloc_from_iter (
1646- lifetime_mapping. iter ( ) . map ( |( lifetime, _) | hir:: GenericArg :: Lifetime ( * lifetime) ) ,
1654+ collected_lifetime_mapping
1655+ . iter ( )
1656+ . map ( |( lifetime, _) | hir:: GenericArg :: Lifetime ( * lifetime) ) ,
16471657 ) ,
16481658 in_trait,
16491659 )
@@ -2010,7 +2020,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20102020 // TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing the
20112021 // new lifetime of the RPIT 'x and the def_id of the lifetime 'x corresponding to
20122022 // `TestReturn`.
2013- let lifetime_mapping : Vec < _ > = collected_lifetimes
2023+ let collected_lifetime_mapping : Vec < _ > = collected_lifetimes
20142024 . iter ( )
20152025 . map ( |( node_id, lifetime, res) | {
20162026 let id = self . next_node_id ( ) ;
@@ -2022,7 +2032,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20222032 ( lifetime, def_id)
20232033 } )
20242034 . collect ( ) ;
2025- debug ! ( ?lifetime_mapping ) ;
2035+ debug ! ( ?collected_lifetime_mapping ) ;
20262036
20272037 self . with_hir_id_owner ( opaque_ty_node_id, |this| {
20282038 // Install the remapping from old to new (if any):
@@ -2079,6 +2089,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20792089 ) ) ;
20802090 debug ! ( "lower_async_fn_ret_ty: generic_params={:#?}" , generic_params) ;
20812091
2092+ let lifetime_mapping = if in_trait {
2093+ self . arena . alloc_from_iter (
2094+ collected_lifetime_mapping
2095+ . iter ( )
2096+ . map ( |( lifetime, def_id) | ( * * lifetime, * def_id) ) ,
2097+ )
2098+ } else {
2099+ & mut [ ]
2100+ } ;
2101+
20822102 let opaque_ty_item = hir:: OpaqueTy {
20832103 generics : this. arena . alloc ( hir:: Generics {
20842104 params : generic_params,
@@ -2089,9 +2109,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20892109 } ) ,
20902110 bounds : arena_vec ! [ this; future_bound] ,
20912111 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- ) ,
2112+ lifetime_mapping,
20952113 in_trait,
20962114 } ;
20972115
@@ -2116,7 +2134,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21162134 // For the "output" lifetime parameters, we just want to
21172135 // generate `'_`.
21182136 let generic_args = self . arena . alloc_from_iter (
2119- lifetime_mapping. iter ( ) . map ( |( lifetime, _) | hir:: GenericArg :: Lifetime ( * lifetime) ) ,
2137+ collected_lifetime_mapping
2138+ . iter ( )
2139+ . map ( |( lifetime, _) | hir:: GenericArg :: Lifetime ( * lifetime) ) ,
21202140 ) ;
21212141
21222142 // Create the `Foo<...>` reference itself. Note that the `type
0 commit comments