@@ -191,7 +191,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
191
191
self . lower_angle_bracketed_parameter_data ( data, param_mode, itctx)
192
192
}
193
193
GenericArgs :: Parenthesized ( ref data) => match parenthesized_generic_args {
194
- ParenthesizedGenericArgs :: Ok => self . lower_parenthesized_parameter_data ( data) ,
194
+ ParenthesizedGenericArgs :: Ok => {
195
+ self . lower_parenthesized_parameter_data ( data, itctx)
196
+ }
195
197
ParenthesizedGenericArgs :: Err => {
196
198
// Suggest replacing parentheses with angle brackets `Trait(params...)` to `Trait<params...>`
197
199
let sub = if !data. inputs . is_empty ( ) {
@@ -344,6 +346,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
344
346
fn lower_parenthesized_parameter_data (
345
347
& mut self ,
346
348
data : & ParenthesizedArgs ,
349
+ itctx : & ImplTraitContext ,
347
350
) -> ( GenericArgsCtor < ' hir > , bool ) {
348
351
// Switch to `PassThrough` mode for anonymous lifetimes; this
349
352
// means that we permit things like `&Ref<T>`, where `Ref` has
@@ -355,6 +358,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
355
358
self . lower_ty_direct ( ty, & ImplTraitContext :: Disallowed ( ImplTraitPosition :: FnTraitParam ) )
356
359
} ) ) ;
357
360
let output_ty = match output {
361
+ // Only allow `impl Trait` in return position. i.e.:
362
+ // ```rust
363
+ // fn f(_: impl Fn() -> impl Debug) -> impl Fn() -> impl Debug
364
+ // // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
365
+ // ```
366
+ FnRetTy :: Ty ( ty)
367
+ if matches ! ( itctx, ImplTraitContext :: ReturnPositionOpaqueTy { .. } )
368
+ && self . tcx . features ( ) . impl_trait_in_fn_trait_return =>
369
+ {
370
+ self . lower_ty ( & ty, itctx)
371
+ }
358
372
FnRetTy :: Ty ( ty) => {
359
373
self . lower_ty ( & ty, & ImplTraitContext :: Disallowed ( ImplTraitPosition :: FnTraitReturn ) )
360
374
}
0 commit comments