|
40 | 40 | #[macro_use] |
41 | 41 | extern crate tracing; |
42 | 42 |
|
43 | | -use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait, TraitFnAsync}; |
| 43 | +use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait}; |
44 | 44 |
|
45 | 45 | use rustc_ast::ptr::P; |
46 | 46 | use rustc_ast::visit; |
@@ -271,8 +271,6 @@ enum ImplTraitPosition { |
271 | 271 | ClosureReturn, |
272 | 272 | PointerReturn, |
273 | 273 | FnTraitReturn, |
274 | | - TraitReturn, |
275 | | - ImplReturn, |
276 | 274 | GenericDefault, |
277 | 275 | ConstTy, |
278 | 276 | StaticTy, |
@@ -302,8 +300,6 @@ impl std::fmt::Display for ImplTraitPosition { |
302 | 300 | ImplTraitPosition::ClosureReturn => "closure return types", |
303 | 301 | ImplTraitPosition::PointerReturn => "`fn` pointer return types", |
304 | 302 | ImplTraitPosition::FnTraitReturn => "`Fn` trait return types", |
305 | | - ImplTraitPosition::TraitReturn => "trait method return types", |
306 | | - ImplTraitPosition::ImplReturn => "`impl` method return types", |
307 | 303 | ImplTraitPosition::GenericDefault => "generic parameter defaults", |
308 | 304 | ImplTraitPosition::ConstTy => "const types", |
309 | 305 | ImplTraitPosition::StaticTy => "static types", |
@@ -334,20 +330,9 @@ impl FnDeclKind { |
334 | 330 | matches!(self, FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait) |
335 | 331 | } |
336 | 332 |
|
337 | | - fn return_impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool { |
| 333 | + fn return_impl_trait_allowed(&self) -> bool { |
338 | 334 | match self { |
339 | | - FnDeclKind::Fn | FnDeclKind::Inherent => true, |
340 | | - FnDeclKind::Impl if tcx.features().return_position_impl_trait_in_trait => true, |
341 | | - FnDeclKind::Trait if tcx.features().return_position_impl_trait_in_trait => true, |
342 | | - _ => false, |
343 | | - } |
344 | | - } |
345 | | - |
346 | | - fn async_fn_allowed(&self, tcx: TyCtxt<'_>) -> bool { |
347 | | - match self { |
348 | | - FnDeclKind::Fn | FnDeclKind::Inherent => true, |
349 | | - FnDeclKind::Impl if tcx.features().async_fn_in_trait => true, |
350 | | - FnDeclKind::Trait if tcx.features().async_fn_in_trait => true, |
| 335 | + FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true, |
351 | 336 | _ => false, |
352 | 337 | } |
353 | 338 | } |
@@ -1805,53 +1790,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
1805 | 1790 | self.lower_ty_direct(¶m.ty, &itctx) |
1806 | 1791 | })); |
1807 | 1792 |
|
1808 | | - let output = if let Some((ret_id, span)) = make_ret_async { |
1809 | | - if !kind.async_fn_allowed(self.tcx) { |
1810 | | - match kind { |
1811 | | - FnDeclKind::Trait | FnDeclKind::Impl => { |
1812 | | - self.tcx |
1813 | | - .sess |
1814 | | - .create_feature_err( |
1815 | | - TraitFnAsync { fn_span, span }, |
1816 | | - sym::async_fn_in_trait, |
1817 | | - ) |
1818 | | - .emit(); |
1819 | | - } |
1820 | | - _ => { |
1821 | | - self.tcx.sess.emit_err(TraitFnAsync { fn_span, span }); |
1822 | | - } |
1823 | | - } |
1824 | | - } |
1825 | | - |
| 1793 | + let output = if let Some((ret_id, _span)) = make_ret_async { |
1826 | 1794 | let fn_def_id = self.local_def_id(fn_node_id); |
1827 | 1795 | self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind, fn_span) |
1828 | 1796 | } else { |
1829 | 1797 | match &decl.output { |
1830 | 1798 | FnRetTy::Ty(ty) => { |
1831 | | - let context = if kind.return_impl_trait_allowed(self.tcx) { |
| 1799 | + let context = if kind.return_impl_trait_allowed() { |
1832 | 1800 | let fn_def_id = self.local_def_id(fn_node_id); |
1833 | 1801 | ImplTraitContext::ReturnPositionOpaqueTy { |
1834 | 1802 | origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id), |
1835 | 1803 | fn_kind: kind, |
1836 | 1804 | } |
1837 | 1805 | } else { |
1838 | | - let position = match kind { |
1839 | | - FnDeclKind::Fn | FnDeclKind::Inherent => { |
1840 | | - unreachable!("fn should allow in-band lifetimes") |
| 1806 | + ImplTraitContext::Disallowed(match kind { |
| 1807 | + FnDeclKind::Fn |
| 1808 | + | FnDeclKind::Inherent |
| 1809 | + | FnDeclKind::Trait |
| 1810 | + | FnDeclKind::Impl => { |
| 1811 | + unreachable!("fn should allow return-position impl trait in traits") |
1841 | 1812 | } |
1842 | 1813 | FnDeclKind::ExternFn => ImplTraitPosition::ExternFnReturn, |
1843 | 1814 | FnDeclKind::Closure => ImplTraitPosition::ClosureReturn, |
1844 | 1815 | FnDeclKind::Pointer => ImplTraitPosition::PointerReturn, |
1845 | | - FnDeclKind::Trait => ImplTraitPosition::TraitReturn, |
1846 | | - FnDeclKind::Impl => ImplTraitPosition::ImplReturn, |
1847 | | - }; |
1848 | | - match kind { |
1849 | | - FnDeclKind::Trait | FnDeclKind::Impl => ImplTraitContext::FeatureGated( |
1850 | | - position, |
1851 | | - sym::return_position_impl_trait_in_trait, |
1852 | | - ), |
1853 | | - _ => ImplTraitContext::Disallowed(position), |
1854 | | - } |
| 1816 | + }) |
1855 | 1817 | }; |
1856 | 1818 | hir::FnRetTy::Return(self.lower_ty(ty, &context)) |
1857 | 1819 | } |
@@ -1924,18 +1886,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
1924 | 1886 | let future_bound = this.lower_async_fn_output_type_to_future_bound( |
1925 | 1887 | output, |
1926 | 1888 | span, |
1927 | | - if let FnDeclKind::Trait = fn_kind |
1928 | | - && !this.tcx.features().return_position_impl_trait_in_trait |
1929 | | - { |
1930 | | - ImplTraitContext::FeatureGated( |
1931 | | - ImplTraitPosition::TraitReturn, |
1932 | | - sym::return_position_impl_trait_in_trait, |
1933 | | - ) |
1934 | | - } else { |
1935 | | - ImplTraitContext::ReturnPositionOpaqueTy { |
1936 | | - origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id), |
1937 | | - fn_kind, |
1938 | | - } |
| 1889 | + ImplTraitContext::ReturnPositionOpaqueTy { |
| 1890 | + origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id), |
| 1891 | + fn_kind, |
1939 | 1892 | }, |
1940 | 1893 | ); |
1941 | 1894 | arena_vec![this; future_bound] |
|
0 commit comments