@@ -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,16 @@ 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 ,
335
+ FnDeclKind :: Fn | FnDeclKind :: Inherent | FnDeclKind :: Impl | FnDeclKind :: Trait => true ,
342
336
_ => false ,
343
337
}
344
338
}
345
339
346
- fn async_fn_allowed ( & self , tcx : TyCtxt < ' _ > ) -> bool {
340
+ fn async_fn_allowed ( & self ) -> bool {
347
341
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 ,
342
+ FnDeclKind :: Fn | FnDeclKind :: Inherent | FnDeclKind :: Impl | FnDeclKind :: Trait => true ,
351
343
_ => false ,
352
344
}
353
345
}
@@ -1806,52 +1798,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1806
1798
} ) ) ;
1807
1799
1808
1800
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
- }
1801
+ if !kind. async_fn_allowed ( ) {
1802
+ self . tcx . sess . emit_err ( TraitFnAsync { fn_span, span } ) ;
1824
1803
}
1825
1804
1826
1805
let fn_def_id = self . local_def_id ( fn_node_id) ;
1827
1806
self . lower_async_fn_ret_ty ( & decl. output , fn_def_id, ret_id, kind)
1828
1807
} else {
1829
1808
match & decl. output {
1830
1809
FnRetTy :: Ty ( ty) => {
1831
- let context = if kind. return_impl_trait_allowed ( self . tcx ) {
1810
+ let context = if kind. return_impl_trait_allowed ( ) {
1832
1811
let fn_def_id = self . local_def_id ( fn_node_id) ;
1833
1812
ImplTraitContext :: ReturnPositionOpaqueTy {
1834
1813
origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1835
1814
fn_kind : kind,
1836
1815
}
1837
1816
} else {
1838
- let position = match kind {
1839
- FnDeclKind :: Fn | FnDeclKind :: Inherent => {
1840
- unreachable ! ( "fn should allow in-band lifetimes" )
1817
+ ImplTraitContext :: Disallowed ( match kind {
1818
+ FnDeclKind :: Fn
1819
+ | FnDeclKind :: Inherent
1820
+ | FnDeclKind :: Trait
1821
+ | FnDeclKind :: Impl => {
1822
+ unreachable ! ( "fn should allow return-position impl trait in traits" )
1841
1823
}
1842
1824
FnDeclKind :: ExternFn => ImplTraitPosition :: ExternFnReturn ,
1843
1825
FnDeclKind :: Closure => ImplTraitPosition :: ClosureReturn ,
1844
1826
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
- }
1827
+ } )
1855
1828
} ;
1856
1829
hir:: FnRetTy :: Return ( self . lower_ty ( ty, & context) )
1857
1830
}
@@ -1923,18 +1896,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1923
1896
let future_bound = this. lower_async_fn_output_type_to_future_bound (
1924
1897
output,
1925
1898
span,
1926
- if let FnDeclKind :: Trait = fn_kind
1927
- && !this. tcx . features ( ) . return_position_impl_trait_in_trait
1928
- {
1929
- ImplTraitContext :: FeatureGated (
1930
- ImplTraitPosition :: TraitReturn ,
1931
- sym:: return_position_impl_trait_in_trait,
1932
- )
1933
- } else {
1934
- ImplTraitContext :: ReturnPositionOpaqueTy {
1935
- origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1936
- fn_kind,
1937
- }
1899
+ ImplTraitContext :: ReturnPositionOpaqueTy {
1900
+ origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1901
+ fn_kind,
1938
1902
} ,
1939
1903
) ;
1940
1904
arena_vec ! [ this; future_bound]
0 commit comments