@@ -1539,9 +1539,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1539
1539
) ;
1540
1540
debug ! ( ?opaque_ty_def_id) ;
1541
1541
1542
- // Contains the new lifetime definitions created for the TAIT (if any).
1543
- let mut collected_lifetimes = Vec :: new ( ) ;
1544
-
1545
1542
// If this came from a TAIT (as opposed to a function that returns an RPIT), we only want
1546
1543
// to capture the lifetimes that appear in the bounds. So visit the bounds to find out
1547
1544
// exactly which ones those are.
@@ -1558,20 +1555,29 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1558
1555
} ;
1559
1556
debug ! ( ?lifetimes_to_remap) ;
1560
1557
1561
- self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
1562
- let mut new_remapping = FxHashMap :: default ( ) ;
1558
+ let mut new_remapping = FxHashMap :: default ( ) ;
1563
1559
1564
- // If this opaque type is only capturing a subset of the lifetimes (those that appear
1565
- // in bounds), then create the new lifetime parameters required and create a mapping
1566
- // from the old `'a` (on the function) to the new `'a` (on the opaque type).
1567
- collected_lifetimes = lctx. create_lifetime_defs (
1568
- opaque_ty_def_id,
1569
- & lifetimes_to_remap,
1570
- & mut new_remapping,
1571
- ) ;
1572
- debug ! ( ?collected_lifetimes) ;
1573
- debug ! ( ?new_remapping) ;
1560
+ // Contains the new lifetime definitions created for the TAIT (if any).
1561
+ // If this opaque type is only capturing a subset of the lifetimes (those that appear in
1562
+ // bounds), then create the new lifetime parameters required and create a mapping from the
1563
+ // old `'a` (on the function) to the new `'a` (on the opaque type).
1564
+ let collected_lifetimes =
1565
+ self . create_lifetime_defs ( opaque_ty_def_id, & lifetimes_to_remap, & mut new_remapping) ;
1566
+ debug ! ( ?collected_lifetimes) ;
1567
+ debug ! ( ?new_remapping) ;
1568
+
1569
+ // This creates HIR lifetime arguments as `hir::GenericArg`, in the given example `type
1570
+ // TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing `&['x]`.
1571
+ let lifetimes: Vec < _ > = collected_lifetimes
1572
+ . iter ( )
1573
+ . map ( |( _, lifetime) | {
1574
+ let id = self . next_node_id ( ) ;
1575
+ self . new_named_lifetime ( lifetime. id , id, lifetime. ident )
1576
+ } )
1577
+ . collect ( ) ;
1578
+ debug ! ( ?lifetimes) ;
1574
1579
1580
+ self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
1575
1581
// Install the remapping from old to new (if any):
1576
1582
lctx. with_remapping ( new_remapping, |lctx| {
1577
1583
// This creates HIR lifetime definitions as `hir::GenericParam`, in the given
@@ -1630,12 +1636,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1630
1636
1631
1637
// This creates HIR lifetime arguments as `hir::GenericArg`, in the given example `type
1632
1638
// TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing `&['x]`.
1633
- let lifetimes =
1634
- self . arena . alloc_from_iter ( collected_lifetimes. into_iter ( ) . map ( |( _, lifetime) | {
1635
- let id = self . next_node_id ( ) ;
1636
- let l = self . new_named_lifetime ( lifetime. id , id, lifetime. ident ) ;
1637
- hir:: GenericArg :: Lifetime ( l)
1638
- } ) ) ;
1639
+ let lifetimes = self . arena . alloc_from_iter (
1640
+ lifetimes. into_iter ( ) . map ( |lifetime| hir:: GenericArg :: Lifetime ( lifetime) ) ,
1641
+ ) ;
1639
1642
debug ! ( ?lifetimes) ;
1640
1643
1641
1644
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
@@ -1993,22 +1996,32 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1993
1996
let lifetimes_to_remap = lifetime_collector:: lifetimes_in_ret_ty ( & self . resolver , output) ;
1994
1997
debug ! ( ?lifetimes_to_remap) ;
1995
1998
1996
- self . with_hir_id_owner ( opaque_ty_node_id, |this| {
1997
- // If this opaque type is only capturing a subset of the lifetimes (those that appear
1998
- // in bounds), then create the new lifetime parameters required and create a mapping
1999
- // from the old `'a` (on the function) to the new `'a` (on the opaque type).
2000
- collected_lifetimes. extend (
2001
- this. create_lifetime_defs (
2002
- opaque_ty_def_id,
2003
- & lifetimes_to_remap,
2004
- & mut new_remapping,
2005
- )
1999
+ // If this opaque type is only capturing a subset of the lifetimes (those that appear in
2000
+ // bounds), then create the new lifetime parameters required and create a mapping from the
2001
+ // old `'a` (on the function) to the new `'a` (on the opaque type).
2002
+ collected_lifetimes. extend (
2003
+ self . create_lifetime_defs ( opaque_ty_def_id, & lifetimes_to_remap, & mut new_remapping)
2006
2004
. into_iter ( )
2007
2005
. map ( |( new_node_id, lifetime) | ( new_node_id, lifetime, None ) ) ,
2008
- ) ;
2009
- debug ! ( ?collected_lifetimes) ;
2010
- debug ! ( ?new_remapping) ;
2006
+ ) ;
2007
+ debug ! ( ?collected_lifetimes) ;
2008
+ debug ! ( ?new_remapping) ;
2011
2009
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
2013
+ . iter ( )
2014
+ . map ( |( _, lifetime, res) | {
2015
+ let id = self . next_node_id ( ) ;
2016
+ let res = res. unwrap_or (
2017
+ self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ,
2018
+ ) ;
2019
+ self . new_named_lifetime_with_res ( id, lifetime. ident , res)
2020
+ } )
2021
+ . collect ( ) ;
2022
+ debug ! ( ?lifetimes) ;
2023
+
2024
+ self . with_hir_id_owner ( opaque_ty_node_id, |this| {
2012
2025
// Install the remapping from old to new (if any):
2013
2026
this. with_remapping ( new_remapping, |this| {
2014
2027
// We have to be careful to get elision right here. The
@@ -2096,15 +2109,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2096
2109
//
2097
2110
// For the "output" lifetime parameters, we just want to
2098
2111
// generate `'_`.
2099
- let generic_args = self . arena . alloc_from_iter ( collected_lifetimes. into_iter ( ) . map (
2100
- |( _, lifetime, res) | {
2101
- let id = self . next_node_id ( ) ;
2102
- let res = res. unwrap_or (
2103
- self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ,
2104
- ) ;
2105
- hir:: GenericArg :: Lifetime ( self . new_named_lifetime_with_res ( id, lifetime. ident , res) )
2106
- } ,
2107
- ) ) ;
2112
+ let generic_args = self
2113
+ . arena
2114
+ . alloc_from_iter ( lifetimes. iter ( ) . map ( |lifetime| hir:: GenericArg :: Lifetime ( * lifetime) ) ) ;
2108
2115
2109
2116
// Create the `Foo<...>` reference itself. Note that the `type
2110
2117
// Foo = impl Trait` is, internally, created as a child of the
0 commit comments