@@ -324,16 +324,10 @@ enum FnDeclKind {
324324}
325325
326326impl FnDeclKind {
327- fn impl_trait_return_allowed ( & self , tcx : TyCtxt < ' _ > ) -> bool {
327+ fn impl_trait_allowed ( & self , tcx : TyCtxt < ' _ > ) -> bool {
328328 match self {
329329 FnDeclKind :: Fn | FnDeclKind :: Inherent => true ,
330330 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 {
337331 FnDeclKind :: Trait if tcx. features ( ) . return_position_impl_trait_in_trait => true ,
338332 _ => false ,
339333 }
@@ -1698,9 +1692,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16981692 } ) ) ;
16991693
17001694 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 => {
17041698 self . tcx
17051699 . sess
17061700 . create_feature_err (
@@ -1709,51 +1703,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17091703 )
17101704 . emit ( ) ;
17111705 }
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 } ) ;
17321708 }
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- )
17391709 }
17401710 }
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+ )
17411718 } else {
17421719 match decl. output {
17431720 FnRetTy :: Ty ( ref ty) => {
17441721 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 ) => {
17531723 let fn_def_id = self . local_def_id ( fn_node_id) ;
17541724 ImplTraitContext :: ReturnPositionOpaqueTy {
17551725 origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1756- in_trait : true ,
1726+ in_trait : matches ! ( kind , FnDeclKind :: Trait ) ,
17571727 }
17581728 }
17591729 _ => ImplTraitContext :: Disallowed ( match kind {
0 commit comments