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