@@ -265,15 +265,11 @@ 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,
270
- origin : hir:: OpaqueTyOrigin ,
271
- fn_kind : FnDeclKind ,
272
- } ,
273
- /// Impl trait in type aliases.
274
- TypeAliasesOpaqueTy {
275
- /// Origin: Always OpaqueTyOrigin::TypeAliasImplTrait
268
+ OpaqueTy {
276
269
origin : hir:: OpaqueTyOrigin ,
270
+ /// Only used to change the lifetime capture rules, since
271
+ /// RPITIT captures all in scope, RPIT does not.
272
+ fn_kind : Option < FnDeclKind > ,
277
273
} ,
278
274
/// `impl Trait` is unstably accepted in this position.
279
275
FeatureGated ( ImplTraitPosition , Symbol ) ,
@@ -1078,9 +1074,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1078
1074
// Disallow ATB in dyn types
1079
1075
if self . is_in_dyn_type {
1080
1076
let suggestion = match itctx {
1081
- ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1082
- | ImplTraitContext :: TypeAliasesOpaqueTy { .. }
1083
- | ImplTraitContext :: Universal => {
1077
+ ImplTraitContext :: OpaqueTy { .. } | ImplTraitContext :: Universal => {
1084
1078
let bound_end_span = constraint
1085
1079
. gen_args
1086
1080
. as_ref ( )
@@ -1420,17 +1414,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1420
1414
TyKind :: ImplTrait ( def_node_id, bounds) => {
1421
1415
let span = t. span ;
1422
1416
match itctx {
1423
- ImplTraitContext :: ReturnPositionOpaqueTy { origin, fn_kind } => self
1424
- . lower_opaque_impl_trait (
1425
- span,
1426
- origin,
1427
- * def_node_id,
1428
- bounds,
1429
- Some ( fn_kind) ,
1430
- itctx,
1431
- ) ,
1432
- ImplTraitContext :: TypeAliasesOpaqueTy { origin } => self
1433
- . lower_opaque_impl_trait ( span, origin, * def_node_id, bounds, None , itctx) ,
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
+ ) ,
1434
1425
ImplTraitContext :: Universal => {
1435
1426
let span = t. span ;
1436
1427
@@ -1824,9 +1815,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1824
1815
FnDeclKind :: Fn
1825
1816
| FnDeclKind :: Inherent
1826
1817
| FnDeclKind :: Trait
1827
- | FnDeclKind :: Impl => ImplTraitContext :: ReturnPositionOpaqueTy {
1818
+ | FnDeclKind :: Impl => ImplTraitContext :: OpaqueTy {
1828
1819
origin : hir:: OpaqueTyOrigin :: FnReturn ( self . local_def_id ( fn_node_id) ) ,
1829
- fn_kind : kind,
1820
+ fn_kind : Some ( kind) ,
1830
1821
} ,
1831
1822
FnDeclKind :: ExternFn => {
1832
1823
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ExternFnReturn )
@@ -1920,9 +1911,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1920
1911
output,
1921
1912
coro,
1922
1913
opaque_ty_span,
1923
- ImplTraitContext :: ReturnPositionOpaqueTy {
1914
+ ImplTraitContext :: OpaqueTy {
1924
1915
origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1925
- fn_kind,
1916
+ fn_kind : Some ( fn_kind ) ,
1926
1917
} ,
1927
1918
) ;
1928
1919
arena_vec ! [ this; bound]
0 commit comments