@@ -265,13 +265,12 @@ enum ImplTraitContext {
265
265
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
266
266
/// equivalent to a new opaque type like `type T = impl Debug; fn foo() -> T`.
267
267
///
268
- ReturnPositionOpaqueTy {
269
- /// Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
268
+ OpaqueTy {
270
269
origin : hir:: OpaqueTyOrigin ,
271
- fn_kind : FnDeclKind ,
270
+ /// Only used to change the lifetime capture rules, since
271
+ /// RPITIT captures all in scope, RPIT does not.
272
+ fn_kind : Option < FnDeclKind > ,
272
273
} ,
273
- /// Impl trait in type aliases.
274
- TypeAliasesOpaqueTy { in_assoc_ty : bool } ,
275
274
/// `impl Trait` is unstably accepted in this position.
276
275
FeatureGated ( ImplTraitPosition , Symbol ) ,
277
276
/// `impl Trait` is not accepted in this position.
@@ -1075,9 +1074,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1075
1074
// Disallow ATB in dyn types
1076
1075
if self . is_in_dyn_type {
1077
1076
let suggestion = match itctx {
1078
- ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1079
- | ImplTraitContext :: TypeAliasesOpaqueTy { .. }
1080
- | ImplTraitContext :: Universal => {
1077
+ ImplTraitContext :: OpaqueTy { .. } | ImplTraitContext :: Universal => {
1081
1078
let bound_end_span = constraint
1082
1079
. gen_args
1083
1080
. as_ref ( )
@@ -1417,24 +1414,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1417
1414
TyKind :: ImplTrait ( def_node_id, bounds) => {
1418
1415
let span = t. span ;
1419
1416
match itctx {
1420
- ImplTraitContext :: ReturnPositionOpaqueTy { origin, fn_kind } => self
1421
- . lower_opaque_impl_trait (
1422
- span,
1423
- origin,
1424
- * def_node_id,
1425
- bounds,
1426
- Some ( fn_kind) ,
1427
- itctx,
1428
- ) ,
1429
- ImplTraitContext :: TypeAliasesOpaqueTy { in_assoc_ty } => self
1430
- . lower_opaque_impl_trait (
1431
- span,
1432
- hir:: OpaqueTyOrigin :: TyAlias { in_assoc_ty } ,
1433
- * def_node_id,
1434
- bounds,
1435
- None ,
1436
- itctx,
1437
- ) ,
1417
+ ImplTraitContext :: OpaqueTy { origin, fn_kind } => self . lower_opaque_impl_trait (
1418
+ span,
1419
+ origin,
1420
+ * def_node_id,
1421
+ bounds,
1422
+ fn_kind,
1423
+ itctx,
1424
+ ) ,
1438
1425
ImplTraitContext :: Universal => {
1439
1426
let span = t. span ;
1440
1427
@@ -1553,9 +1540,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1553
1540
1554
1541
let captured_lifetimes_to_duplicate = match origin {
1555
1542
hir:: OpaqueTyOrigin :: TyAlias { .. } => {
1556
- // in a TAIT like `type Foo<'a> = impl Foo<'a>`, we don't duplicate any
1557
- // lifetimes, since we don't have the issue that any are late-bound.
1558
- Vec :: new ( )
1543
+ // type alias impl trait and associated type position impl trait were
1544
+ // decided to capture all in-scope lifetimes, which we collect for
1545
+ // all opaques during resolution.
1546
+ self . resolver
1547
+ . take_extra_lifetime_params ( opaque_ty_node_id)
1548
+ . into_iter ( )
1549
+ . map ( |( ident, id, _) | Lifetime { id, ident } )
1550
+ . collect ( )
1559
1551
}
1560
1552
hir:: OpaqueTyOrigin :: FnReturn ( ..) => {
1561
1553
if matches ! (
@@ -1823,9 +1815,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1823
1815
FnDeclKind :: Fn
1824
1816
| FnDeclKind :: Inherent
1825
1817
| FnDeclKind :: Trait
1826
- | FnDeclKind :: Impl => ImplTraitContext :: ReturnPositionOpaqueTy {
1818
+ | FnDeclKind :: Impl => ImplTraitContext :: OpaqueTy {
1827
1819
origin : hir:: OpaqueTyOrigin :: FnReturn ( self . local_def_id ( fn_node_id) ) ,
1828
- fn_kind : kind,
1820
+ fn_kind : Some ( kind) ,
1829
1821
} ,
1830
1822
FnDeclKind :: ExternFn => {
1831
1823
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ExternFnReturn )
@@ -1919,9 +1911,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1919
1911
output,
1920
1912
coro,
1921
1913
opaque_ty_span,
1922
- ImplTraitContext :: ReturnPositionOpaqueTy {
1914
+ ImplTraitContext :: OpaqueTy {
1923
1915
origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1924
- fn_kind,
1916
+ fn_kind : Some ( fn_kind ) ,
1925
1917
} ,
1926
1918
) ;
1927
1919
arena_vec ! [ this; bound]
0 commit comments