@@ -1649,11 +1649,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16491649
16501650 // When we create the opaque type for this async fn, it is going to have
16511651 // 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:
16531653 //
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.
16571658 //
16581659 // So for example in this snippet:
16591660 //
@@ -1669,44 +1670,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16691670 // we would create an opaque type like:
16701671 //
16711672 // ```
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>;
16731674 // ```
16741675 //
16751676 // and we would then desugar `bar` to the equivalent of:
16761677 //
16771678 // ```rust
16781679 // 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<'_>
16801681 // }
16811682 // ```
16821683 //
16831684 // Note that the final parameter to `Bar` is `'_`, not `'2` --
16841685 // this is because the elided lifetimes from the return type
16851686 // should be figured out using the ordinary elision rules, and
16861687 // 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 ( ) ;
17101689 self . with_hir_id_owner ( opaque_ty_node_id, |this| {
17111690 // We have to be careful to get elision right here. The
17121691 // idea is that we create a lifetime parameter for each
@@ -1725,16 +1704,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17251704 debug ! ( "lower_async_fn_ret_ty: future_bound={:#?}" , future_bound) ;
17261705 debug ! ( "lower_async_fn_ret_ty: lifetimes_to_define={:#?}" , lifetimes_to_define) ;
17271706
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;
17341709 debug ! ( "lower_async_fn_ret_ty: lifetime_params={:#?}" , lifetime_params) ;
17351710
17361711 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) | {
17381713 this. lifetime_to_generic_param ( span, hir_name, opaque_ty_def_id)
17391714 } ) ) ;
17401715
@@ -1752,28 +1727,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17521727 this. generate_opaque_type ( opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span)
17531728 } ) ;
17541729
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:
17591733 //
17601734 // ```
1761- // Bar <'a, 'b, '0, '1, '_>
1735+ // For <'a>::bar< 'b, '0, '1>::Bar< '_>
17621736 // ```
17631737 //
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 `'_`.
17711740 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, _) | {
17731742 GenericArg :: Lifetime ( hir:: Lifetime {
17741743 hir_id : self . next_id ( ) ,
17751744 span : self . lower_span ( span) ,
1776- name,
1745+ name : hir :: LifetimeName :: Implicit ,
17771746 } )
17781747 } ) ) ;
17791748
0 commit comments