@@ -265,15 +265,11 @@ enum ImplTraitContext {
265265 /// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
266266 /// equivalent to a new opaque type like `type T = impl Debug; fn foo() -> T`.
267267 ///
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 {
276269 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 > ,
277273 } ,
278274 /// `impl Trait` is unstably accepted in this position.
279275 FeatureGated ( ImplTraitPosition , Symbol ) ,
@@ -1078,9 +1074,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10781074 // Disallow ATB in dyn types
10791075 if self . is_in_dyn_type {
10801076 let suggestion = match itctx {
1081- ImplTraitContext :: ReturnPositionOpaqueTy { .. }
1082- | ImplTraitContext :: TypeAliasesOpaqueTy { .. }
1083- | ImplTraitContext :: Universal => {
1077+ ImplTraitContext :: OpaqueTy { .. } | ImplTraitContext :: Universal => {
10841078 let bound_end_span = constraint
10851079 . gen_args
10861080 . as_ref ( )
@@ -1420,17 +1414,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14201414 TyKind :: ImplTrait ( def_node_id, bounds) => {
14211415 let span = t. span ;
14221416 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+ ) ,
14341425 ImplTraitContext :: Universal => {
14351426 let span = t. span ;
14361427
@@ -1824,9 +1815,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18241815 FnDeclKind :: Fn
18251816 | FnDeclKind :: Inherent
18261817 | FnDeclKind :: Trait
1827- | FnDeclKind :: Impl => ImplTraitContext :: ReturnPositionOpaqueTy {
1818+ | FnDeclKind :: Impl => ImplTraitContext :: OpaqueTy {
18281819 origin : hir:: OpaqueTyOrigin :: FnReturn ( self . local_def_id ( fn_node_id) ) ,
1829- fn_kind : kind,
1820+ fn_kind : Some ( kind) ,
18301821 } ,
18311822 FnDeclKind :: ExternFn => {
18321823 ImplTraitContext :: Disallowed ( ImplTraitPosition :: ExternFnReturn )
@@ -1920,9 +1911,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19201911 output,
19211912 coro,
19221913 opaque_ty_span,
1923- ImplTraitContext :: ReturnPositionOpaqueTy {
1914+ ImplTraitContext :: OpaqueTy {
19241915 origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1925- fn_kind,
1916+ fn_kind : Some ( fn_kind ) ,
19261917 } ,
19271918 ) ;
19281919 arena_vec ! [ this; bound]
0 commit comments