|
42 | 42 | #[macro_use] |
43 | 43 | extern crate tracing; |
44 | 44 |
|
45 | | -use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait}; |
| 45 | +use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait, TraitFnAsync}; |
46 | 46 |
|
47 | 47 | use rustc_arena::declare_arena; |
48 | 48 | use rustc_ast::ptr::P; |
@@ -1274,7 +1274,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
1274 | 1274 | generic_params, |
1275 | 1275 | unsafety: lctx.lower_unsafety(f.unsafety), |
1276 | 1276 | abi: lctx.lower_extern(f.ext), |
1277 | | - decl: lctx.lower_fn_decl(&f.decl, None, FnDeclKind::Pointer, None), |
| 1277 | + decl: lctx.lower_fn_decl(&f.decl, None, t.span, FnDeclKind::Pointer, None), |
1278 | 1278 | param_names: lctx.lower_fn_params_to_names(&f.decl), |
1279 | 1279 | })) |
1280 | 1280 | }) |
@@ -1677,19 +1677,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
1677 | 1677 | // `fn_def_id`: if `Some`, impl Trait arguments are lowered into generic parameters on the |
1678 | 1678 | // given DefId, otherwise impl Trait is disallowed. Must be `Some` if |
1679 | 1679 | // `make_ret_async` is also `Some`. |
1680 | | - // `impl_trait_return_allow`: determines whether `impl Trait` can be used in return position. |
1681 | | - // This guards against trait declarations and implementations where `impl Trait` is |
1682 | | - // disallowed. |
1683 | 1680 | // `make_ret_async`: if `Some`, converts `-> T` into `-> impl Future<Output = T>` in the |
1684 | 1681 | // return type. This is used for `async fn` declarations. The `NodeId` is the ID of the |
1685 | | - // return type `impl Trait` item. |
| 1682 | + // return type `impl Trait` item, and the `Span` points to the `async` keyword. |
1686 | 1683 | #[instrument(level = "debug", skip(self))] |
1687 | 1684 | fn lower_fn_decl( |
1688 | 1685 | &mut self, |
1689 | 1686 | decl: &FnDecl, |
1690 | 1687 | fn_node_id: Option<NodeId>, |
| 1688 | + fn_span: Span, |
1691 | 1689 | kind: FnDeclKind, |
1692 | | - make_ret_async: Option<NodeId>, |
| 1690 | + make_ret_async: Option<(NodeId, Span)>, |
1693 | 1691 | ) -> &'hir hir::FnDecl<'hir> { |
1694 | 1692 | let c_variadic = decl.c_variadic(); |
1695 | 1693 |
|
@@ -1720,7 +1718,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
1720 | 1718 | } |
1721 | 1719 | })); |
1722 | 1720 |
|
1723 | | - let output = if let Some(ret_id) = make_ret_async { |
| 1721 | + let output = if let Some((ret_id, span)) = make_ret_async { |
| 1722 | + if !self.tcx.features().return_position_impl_trait_in_trait { |
| 1723 | + self.tcx.sess.emit_feature_err( |
| 1724 | + TraitFnAsync { fn_span, span }, |
| 1725 | + sym::return_position_impl_trait_in_trait, |
| 1726 | + ); |
| 1727 | + } |
| 1728 | + |
1724 | 1729 | self.lower_async_fn_ret_ty( |
1725 | 1730 | &decl.output, |
1726 | 1731 | fn_node_id.expect("`make_ret_async` but no `fn_def_id`"), |
|
0 commit comments