@@ -1651,11 +1651,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16511651
16521652 // When we create the opaque type for this async fn, it is going to have
16531653 // 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:
16551655 //
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.
16591660 //
16601661 // So for example in this snippet:
16611662 //
@@ -1671,44 +1672,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16711672 // we would create an opaque type like:
16721673 //
16731674 // ```
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>;
16751676 // ```
16761677 //
16771678 // and we would then desugar `bar` to the equivalent of:
16781679 //
16791680 // ```rust
16801681 // 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<'_>
16821683 // }
16831684 // ```
16841685 //
16851686 // Note that the final parameter to `Bar` is `'_`, not `'2` --
16861687 // this is because the elided lifetimes from the return type
16871688 // should be figured out using the ordinary elision rules, and
16881689 // 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 ( ) ;
17121691 self . with_hir_id_owner ( opaque_ty_node_id, |this| {
17131692 // We have to be careful to get elision right here. The
17141693 // idea is that we create a lifetime parameter for each
@@ -1727,16 +1706,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17271706 debug ! ( "lower_async_fn_ret_ty: future_bound={:#?}" , future_bound) ;
17281707 debug ! ( "lower_async_fn_ret_ty: lifetimes_to_define={:#?}" , lifetimes_to_define) ;
17291708
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;
17361711 debug ! ( "lower_async_fn_ret_ty: lifetime_params={:#?}" , lifetime_params) ;
17371712
17381713 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) | {
17401715 this. lifetime_to_generic_param ( span, hir_name, opaque_ty_def_id)
17411716 } ) ) ;
17421717
@@ -1754,28 +1729,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17541729 this. generate_opaque_type ( opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span)
17551730 } ) ;
17561731
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:
17611735 //
17621736 // ```
1763- // Bar <'a, 'b, '0, '1, '_>
1737+ // For <'a>::bar< 'b, '0, '1>::Bar< '_>
17641738 // ```
17651739 //
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 `'_`.
17731742 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, _) | {
17751744 GenericArg :: Lifetime ( hir:: Lifetime {
17761745 hir_id : self . next_id ( ) ,
17771746 span : self . lower_span ( span) ,
1778- name,
1747+ name : hir :: LifetimeName :: Implicit ( false ) ,
17791748 } )
17801749 } ) ) ;
17811750
0 commit comments