@@ -324,16 +324,10 @@ enum FnDeclKind {
324
324
}
325
325
326
326
impl FnDeclKind {
327
- fn impl_trait_return_allowed ( & self , tcx : TyCtxt < ' _ > ) -> bool {
327
+ fn impl_trait_allowed ( & self , tcx : TyCtxt < ' _ > ) -> bool {
328
328
match self {
329
329
FnDeclKind :: Fn | FnDeclKind :: Inherent => true ,
330
330
FnDeclKind :: Impl if tcx. features ( ) . return_position_impl_trait_in_trait => true ,
331
- _ => false ,
332
- }
333
- }
334
-
335
- fn impl_trait_in_trait_allowed ( & self , tcx : TyCtxt < ' _ > ) -> bool {
336
- match self {
337
331
FnDeclKind :: Trait if tcx. features ( ) . return_position_impl_trait_in_trait => true ,
338
332
_ => false ,
339
333
}
@@ -1698,9 +1692,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1698
1692
} ) ) ;
1699
1693
1700
1694
let output = if let Some ( ( ret_id, span) ) = make_ret_async {
1701
- match kind {
1702
- FnDeclKind :: Trait => {
1703
- if !kind . impl_trait_in_trait_allowed ( self . tcx ) {
1695
+ if ! kind. impl_trait_allowed ( self . tcx ) {
1696
+ match kind {
1697
+ FnDeclKind :: Trait | FnDeclKind :: Impl => {
1704
1698
self . tcx
1705
1699
. sess
1706
1700
. create_feature_err (
@@ -1709,51 +1703,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1709
1703
)
1710
1704
. emit ( ) ;
1711
1705
}
1712
- self . lower_async_fn_ret_ty (
1713
- & decl. output ,
1714
- fn_node_id. expect ( "`make_ret_async` but no `fn_def_id`" ) ,
1715
- ret_id,
1716
- true ,
1717
- )
1718
- }
1719
- _ => {
1720
- if !kind. impl_trait_return_allowed ( self . tcx ) {
1721
- if kind == FnDeclKind :: Impl {
1722
- self . tcx
1723
- . sess
1724
- . create_feature_err (
1725
- TraitFnAsync { fn_span, span } ,
1726
- sym:: return_position_impl_trait_in_trait,
1727
- )
1728
- . emit ( ) ;
1729
- } else {
1730
- self . tcx . sess . emit_err ( TraitFnAsync { fn_span, span } ) ;
1731
- }
1706
+ _ => {
1707
+ self . tcx . sess . emit_err ( TraitFnAsync { fn_span, span } ) ;
1732
1708
}
1733
- self . lower_async_fn_ret_ty (
1734
- & decl. output ,
1735
- fn_node_id. expect ( "`make_ret_async` but no `fn_def_id`" ) ,
1736
- ret_id,
1737
- false ,
1738
- )
1739
1709
}
1740
1710
}
1711
+
1712
+ self . lower_async_fn_ret_ty (
1713
+ & decl. output ,
1714
+ fn_node_id. expect ( "`make_ret_async` but no `fn_def_id`" ) ,
1715
+ ret_id,
1716
+ matches ! ( kind, FnDeclKind :: Trait ) ,
1717
+ )
1741
1718
} else {
1742
1719
match decl. output {
1743
1720
FnRetTy :: Ty ( ref ty) => {
1744
1721
let mut context = match fn_node_id {
1745
- Some ( fn_node_id) if kind. impl_trait_return_allowed ( self . tcx ) => {
1746
- let fn_def_id = self . local_def_id ( fn_node_id) ;
1747
- ImplTraitContext :: ReturnPositionOpaqueTy {
1748
- origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1749
- in_trait : false ,
1750
- }
1751
- }
1752
- Some ( fn_node_id) if kind. impl_trait_in_trait_allowed ( self . tcx ) => {
1722
+ Some ( fn_node_id) if kind. impl_trait_allowed ( self . tcx ) => {
1753
1723
let fn_def_id = self . local_def_id ( fn_node_id) ;
1754
1724
ImplTraitContext :: ReturnPositionOpaqueTy {
1755
1725
origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1756
- in_trait : true ,
1726
+ in_trait : matches ! ( kind , FnDeclKind :: Trait ) ,
1757
1727
}
1758
1728
}
1759
1729
_ => ImplTraitContext :: Disallowed ( match kind {
0 commit comments