@@ -1525,7 +1525,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1525
1525
bounds : & GenericBounds ,
1526
1526
fn_kind : Option < FnDeclKind > ,
1527
1527
itctx : ImplTraitContext ,
1528
- precise_capturing : Option < & ast:: GenericArgs > ,
1528
+ precise_capturing : Option < & [ ast:: PreciseCapturingArg ] > ,
1529
1529
) -> hir:: TyKind < ' hir > {
1530
1530
// Make sure we know that some funky desugaring has been going on here.
1531
1531
// This is a first: there is code in other places like for loop
@@ -1534,58 +1534,55 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1534
1534
// frequently opened issues show.
1535
1535
let opaque_ty_span = self . mark_span_with_reason ( DesugaringKind :: OpaqueTy , span, None ) ;
1536
1536
1537
- let captured_lifetimes_to_duplicate = if let Some ( precise_capturing) = precise_capturing {
1538
- let ast:: GenericArgs :: AngleBracketed ( precise_capturing) = precise_capturing else {
1539
- panic ! ( "we only parse angle-bracketed args" )
1540
- } ;
1541
- // We'll actually validate these later on; all we need is the list of
1542
- // lifetimes to duplicate during this portion of lowering.
1543
- precise_capturing
1544
- . args
1545
- . iter ( )
1546
- . filter_map ( |arg| match arg {
1547
- ast:: AngleBracketedArg :: Arg ( ast:: GenericArg :: Lifetime ( lt) ) => Some ( * lt) ,
1548
- _ => None ,
1549
- } )
1550
- . collect ( )
1551
- } else {
1552
- match origin {
1553
- hir:: OpaqueTyOrigin :: TyAlias { .. } => {
1554
- // type alias impl trait and associated type position impl trait were
1555
- // decided to capture all in-scope lifetimes, which we collect for
1556
- // all opaques during resolution.
1557
- self . resolver
1558
- . take_extra_lifetime_params ( opaque_ty_node_id)
1559
- . into_iter ( )
1560
- . map ( |( ident, id, _) | Lifetime { id, ident } )
1561
- . collect ( )
1562
- }
1563
- hir:: OpaqueTyOrigin :: FnReturn ( ..) => {
1564
- if matches ! (
1565
- fn_kind. expect( "expected RPITs to be lowered with a FnKind" ) ,
1566
- FnDeclKind :: Impl | FnDeclKind :: Trait
1567
- ) || self . tcx . features ( ) . lifetime_capture_rules_2024
1568
- || span. at_least_rust_2024 ( )
1569
- {
1570
- // return-position impl trait in trait was decided to capture all
1571
- // in-scope lifetimes, which we collect for all opaques during resolution.
1537
+ let captured_lifetimes_to_duplicate =
1538
+ if let Some ( precise_capturing) = precise_capturing_args {
1539
+ // We'll actually validate these later on; all we need is the list of
1540
+ // lifetimes to duplicate during this portion of lowering.
1541
+ precise_capturing
1542
+ . iter ( )
1543
+ . filter_map ( |arg| match arg {
1544
+ ast:: PreciseCapturingArg :: Lifetime ( lt) => Some ( * lt) ,
1545
+ ast:: PreciseCapturingArg :: Arg ( ..) => None ,
1546
+ } )
1547
+ . collect ( )
1548
+ } else {
1549
+ match origin {
1550
+ hir:: OpaqueTyOrigin :: TyAlias { .. } => {
1551
+ // type alias impl trait and associated type position impl trait were
1552
+ // decided to capture all in-scope lifetimes, which we collect for
1553
+ // all opaques during resolution.
1572
1554
self . resolver
1573
1555
. take_extra_lifetime_params ( opaque_ty_node_id)
1574
1556
. into_iter ( )
1575
1557
. map ( |( ident, id, _) | Lifetime { id, ident } )
1576
1558
. collect ( )
1577
- } else {
1578
- // in fn return position, like the `fn test<'a>() -> impl Debug + 'a`
1579
- // example, we only need to duplicate lifetimes that appear in the
1580
- // bounds, since those are the only ones that are captured by the opaque.
1581
- lifetime_collector:: lifetimes_in_bounds ( self . resolver , bounds)
1559
+ }
1560
+ hir:: OpaqueTyOrigin :: FnReturn ( ..) => {
1561
+ if matches ! (
1562
+ fn_kind. expect( "expected RPITs to be lowered with a FnKind" ) ,
1563
+ FnDeclKind :: Impl | FnDeclKind :: Trait
1564
+ ) || self . tcx . features ( ) . lifetime_capture_rules_2024
1565
+ || span. at_least_rust_2024 ( )
1566
+ {
1567
+ // return-position impl trait in trait was decided to capture all
1568
+ // in-scope lifetimes, which we collect for all opaques during resolution.
1569
+ self . resolver
1570
+ . take_extra_lifetime_params ( opaque_ty_node_id)
1571
+ . into_iter ( )
1572
+ . map ( |( ident, id, _) | Lifetime { id, ident } )
1573
+ . collect ( )
1574
+ } else {
1575
+ // in fn return position, like the `fn test<'a>() -> impl Debug + 'a`
1576
+ // example, we only need to duplicate lifetimes that appear in the
1577
+ // bounds, since those are the only ones that are captured by the opaque.
1578
+ lifetime_collector:: lifetimes_in_bounds ( self . resolver , bounds)
1579
+ }
1580
+ }
1581
+ hir:: OpaqueTyOrigin :: AsyncFn ( ..) => {
1582
+ unreachable ! ( "should be using `lower_async_fn_ret_ty`" )
1582
1583
}
1583
1584
}
1584
- hir:: OpaqueTyOrigin :: AsyncFn ( ..) => {
1585
- unreachable ! ( "should be using `lower_async_fn_ret_ty`" )
1586
- }
1587
- }
1588
- } ;
1585
+ } ;
1589
1586
debug ! ( ?captured_lifetimes_to_duplicate) ;
1590
1587
1591
1588
self . lower_opaque_inner (
0 commit comments