@@ -1649,11 +1649,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1649
1649
1650
1650
// When we create the opaque type for this async fn, it is going to have
1651
1651
// to capture all the lifetimes involved in the signature (including in the
1652
- // return type). This is done by introducing lifetime parameters for :
1652
+ // return type). This is done by:
1653
1653
//
1654
- // - all the explicitly declared lifetimes from the impl and function itself;
1655
- // - all the elided lifetimes in the fn arguments;
1656
- // - all the elided lifetimes in the return type.
1654
+ // - making the opaque type inherit all lifetime parameters from its parent;
1655
+ // - make all the elided lifetimes in the fn arguments into parameters;
1656
+ // - manually introducing parameters on the opaque type for elided
1657
+ // lifetimes in the return type.
1657
1658
//
1658
1659
// So for example in this snippet:
1659
1660
//
@@ -1669,44 +1670,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1669
1670
// we would create an opaque type like:
1670
1671
//
1671
1672
// ```
1672
- // type Bar <'a, 'b, '0, '1, '2> = impl Future<Output = &'2 u32>;
1673
+ // type Foo <'a>::bar< 'b, '0, '1>::Bar< '2> = impl Future<Output = &'2 u32>;
1673
1674
// ```
1674
1675
//
1675
1676
// and we would then desugar `bar` to the equivalent of:
1676
1677
//
1677
1678
// ```rust
1678
1679
// impl<'a> Foo<'a> {
1679
- // fn bar<'b, '0, '1>(&'0 self, x: &'b Vec<f64>, y: &'1 str) -> Bar<'a, 'b, '0, '1, ' _>
1680
+ // fn bar<'b, '0, '1>(&'0 self, x: &'b Vec<f64>, y: &'1 str) -> Bar<'_>
1680
1681
// }
1681
1682
// ```
1682
1683
//
1683
1684
// Note that the final parameter to `Bar` is `'_`, not `'2` --
1684
1685
// this is because the elided lifetimes from the return type
1685
1686
// should be figured out using the ordinary elision rules, and
1686
1687
// this desugaring achieves that.
1687
-
1688
- debug ! ( "lower_async_fn_ret_ty: in_scope_lifetimes={:#?}" , self . in_scope_lifetimes) ;
1689
- debug ! ( "lower_async_fn_ret_ty: lifetimes_to_define={:#?}" , self . lifetimes_to_define) ;
1690
-
1691
- // Calculate all the lifetimes that should be captured
1692
- // by the opaque type. This should include all in-scope
1693
- // lifetime parameters, including those defined in-band.
1694
- //
1695
- // `lifetime_params` is a vector of tuple (span, parameter name, lifetime name).
1696
-
1697
- // Input lifetime like `'a` or `'1`:
1698
- let mut lifetime_params: Vec < _ > = self
1699
- . in_scope_lifetimes
1700
- . iter ( )
1701
- . cloned ( )
1702
- . map ( |name| ( name. ident ( ) . span , name, hir:: LifetimeName :: Param ( name) ) )
1703
- . chain (
1704
- self . lifetimes_to_define
1705
- . iter ( )
1706
- . map ( |& ( span, name) | ( span, name, hir:: LifetimeName :: Param ( name) ) ) ,
1707
- )
1708
- . collect ( ) ;
1709
-
1688
+ let mut lifetime_params = Vec :: new ( ) ;
1710
1689
self . with_hir_id_owner ( opaque_ty_node_id, |this| {
1711
1690
// We have to be careful to get elision right here. The
1712
1691
// idea is that we create a lifetime parameter for each
@@ -1725,16 +1704,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1725
1704
debug ! ( "lower_async_fn_ret_ty: future_bound={:#?}" , future_bound) ;
1726
1705
debug ! ( "lower_async_fn_ret_ty: lifetimes_to_define={:#?}" , lifetimes_to_define) ;
1727
1706
1728
- lifetime_params. extend (
1729
- // Output lifetime like `'_`:
1730
- lifetimes_to_define
1731
- . into_iter ( )
1732
- . map ( |( span, name) | ( span, name, hir:: LifetimeName :: Implicit ) ) ,
1733
- ) ;
1707
+ // Output lifetime like `'_`:
1708
+ lifetime_params = lifetimes_to_define;
1734
1709
debug ! ( "lower_async_fn_ret_ty: lifetime_params={:#?}" , lifetime_params) ;
1735
1710
1736
1711
let generic_params =
1737
- this. arena . alloc_from_iter ( lifetime_params. iter ( ) . map ( |& ( span, hir_name, _ ) | {
1712
+ this. arena . alloc_from_iter ( lifetime_params. iter ( ) . map ( |& ( span, hir_name) | {
1738
1713
this. lifetime_to_generic_param ( span, hir_name, opaque_ty_def_id)
1739
1714
} ) ) ;
1740
1715
@@ -1752,28 +1727,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1752
1727
this. generate_opaque_type ( opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span)
1753
1728
} ) ;
1754
1729
1755
- // As documented above on the variable
1756
- // `input_lifetimes_count`, we need to create the lifetime
1757
- // arguments to our opaque type. Continuing with our example,
1758
- // we're creating the type arguments for the return type:
1730
+ // We need to create the lifetime arguments to our opaque type.
1731
+ // Continuing with our example, we're creating the type arguments
1732
+ // for the return type:
1759
1733
//
1760
1734
// ```
1761
- // Bar <'a, 'b, '0, '1, '_>
1735
+ // For <'a>::bar< 'b, '0, '1>::Bar< '_>
1762
1736
// ```
1763
1737
//
1764
- // For the "input" lifetime parameters, we wish to create
1765
- // references to the parameters themselves, including the
1766
- // "implicit" ones created from parameter types (`'a`, `'b`,
1767
- // '`0`, `'1`).
1768
- //
1769
- // For the "output" lifetime parameters, we just want to
1770
- // generate `'_`.
1738
+ // For the "input" lifetime parameters are inherited automatically.
1739
+ // For the "output" lifetime parameters, we just want to generate `'_`.
1771
1740
let generic_args =
1772
- self . arena . alloc_from_iter ( lifetime_params. into_iter ( ) . map ( |( span, _, name ) | {
1741
+ self . arena . alloc_from_iter ( lifetime_params. into_iter ( ) . map ( |( span, _) | {
1773
1742
GenericArg :: Lifetime ( hir:: Lifetime {
1774
1743
hir_id : self . next_id ( ) ,
1775
1744
span : self . lower_span ( span) ,
1776
- name,
1745
+ name : hir :: LifetimeName :: Implicit ,
1777
1746
} )
1778
1747
} ) ) ;
1779
1748
0 commit comments