@@ -312,7 +312,7 @@ impl std::fmt::Display for ImplTraitPosition {
312
312
}
313
313
}
314
314
315
- #[ derive( Debug ) ]
315
+ #[ derive( Debug , PartialEq , Eq ) ]
316
316
enum FnDeclKind {
317
317
Fn ,
318
318
Inherent ,
@@ -1373,6 +1373,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1373
1373
}
1374
1374
path
1375
1375
}
1376
+ ImplTraitContext :: Disallowed (
1377
+ position @ ( ImplTraitPosition :: TraitReturn | ImplTraitPosition :: ImplReturn ) ,
1378
+ ) => {
1379
+ self . tcx . sess . create_feature_err (
1380
+ MisplacedImplTrait {
1381
+ span : t. span ,
1382
+ position : DiagnosticArgFromDisplay ( & position) ,
1383
+ } ,
1384
+ sym:: return_position_impl_trait_in_trait,
1385
+ ) . emit ( ) ;
1386
+ hir:: TyKind :: Err
1387
+ }
1376
1388
ImplTraitContext :: Disallowed ( position) => {
1377
1389
self . tcx . sess . emit_err ( MisplacedImplTrait {
1378
1390
span : t. span ,
@@ -1717,13 +1729,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1717
1729
}
1718
1730
_ => {
1719
1731
if !kind. impl_trait_return_allowed ( self . tcx ) {
1720
- self . tcx
1721
- . sess
1722
- . create_feature_err (
1723
- TraitFnAsync { fn_span, span } ,
1724
- sym:: return_position_impl_trait_in_trait,
1725
- )
1726
- . emit ( ) ;
1732
+ if kind == FnDeclKind :: Impl {
1733
+ self . tcx
1734
+ . sess
1735
+ . create_feature_err (
1736
+ TraitFnAsync { fn_span, span } ,
1737
+ sym:: return_position_impl_trait_in_trait,
1738
+ )
1739
+ . emit ( ) ;
1740
+ } else {
1741
+ self . tcx . sess . emit_err ( TraitFnAsync { fn_span, span } ) ;
1742
+ }
1727
1743
}
1728
1744
self . lower_async_fn_ret_ty (
1729
1745
& decl. output ,
0 commit comments