@@ -304,8 +304,6 @@ enum ImplTraitPosition {
304
304
ClosureParam ,
305
305
PointerParam ,
306
306
FnTraitParam ,
307
- TraitParam ,
308
- ImplParam ,
309
307
ExternFnReturn ,
310
308
ClosureReturn ,
311
309
PointerReturn ,
@@ -333,8 +331,6 @@ impl std::fmt::Display for ImplTraitPosition {
333
331
ImplTraitPosition :: ClosureParam => "closure parameters" ,
334
332
ImplTraitPosition :: PointerParam => "`fn` pointer parameters" ,
335
333
ImplTraitPosition :: FnTraitParam => "the parameters of `Fn` trait bounds" ,
336
- ImplTraitPosition :: TraitParam => "trait method parameters" ,
337
- ImplTraitPosition :: ImplParam => "`impl` method parameters" ,
338
334
ImplTraitPosition :: ExternFnReturn => "`extern fn` return types" ,
339
335
ImplTraitPosition :: ClosureReturn => "closure return types" ,
340
336
ImplTraitPosition :: PointerReturn => "`fn` pointer return types" ,
@@ -364,19 +360,6 @@ enum FnDeclKind {
364
360
Impl ,
365
361
}
366
362
367
- impl FnDeclKind {
368
- fn param_impl_trait_allowed ( & self ) -> bool {
369
- matches ! ( self , FnDeclKind :: Fn | FnDeclKind :: Inherent | FnDeclKind :: Impl | FnDeclKind :: Trait )
370
- }
371
-
372
- fn return_impl_trait_allowed ( & self ) -> bool {
373
- match self {
374
- FnDeclKind :: Fn | FnDeclKind :: Inherent | FnDeclKind :: Impl | FnDeclKind :: Trait => true ,
375
- _ => false ,
376
- }
377
- }
378
- }
379
-
380
363
#[ derive( Copy , Clone ) ]
381
364
enum AstOwner < ' a > {
382
365
NonOwner ,
@@ -1842,19 +1825,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1842
1825
inputs = & inputs[ ..inputs. len ( ) - 1 ] ;
1843
1826
}
1844
1827
let inputs = self . arena . alloc_from_iter ( inputs. iter ( ) . map ( |param| {
1845
- let itctx = if kind. param_impl_trait_allowed ( ) {
1846
- ImplTraitContext :: Universal
1847
- } else {
1848
- ImplTraitContext :: Disallowed ( match kind {
1849
- FnDeclKind :: Fn | FnDeclKind :: Inherent => {
1850
- unreachable ! ( "fn should allow APIT" )
1851
- }
1852
- FnDeclKind :: ExternFn => ImplTraitPosition :: ExternFnParam ,
1853
- FnDeclKind :: Closure => ImplTraitPosition :: ClosureParam ,
1854
- FnDeclKind :: Pointer => ImplTraitPosition :: PointerParam ,
1855
- FnDeclKind :: Trait => ImplTraitPosition :: TraitParam ,
1856
- FnDeclKind :: Impl => ImplTraitPosition :: ImplParam ,
1857
- } )
1828
+ let itctx = match kind {
1829
+ FnDeclKind :: Fn | FnDeclKind :: Inherent | FnDeclKind :: Impl | FnDeclKind :: Trait => {
1830
+ ImplTraitContext :: Universal
1831
+ }
1832
+ FnDeclKind :: ExternFn => {
1833
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: ExternFnParam )
1834
+ }
1835
+ FnDeclKind :: Closure => {
1836
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: ClosureParam )
1837
+ }
1838
+ FnDeclKind :: Pointer => {
1839
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: PointerParam )
1840
+ }
1858
1841
} ;
1859
1842
self . lower_ty_direct ( & param. ty , & itctx)
1860
1843
} ) ) ;
@@ -1866,26 +1849,25 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1866
1849
}
1867
1850
None => match & decl. output {
1868
1851
FnRetTy :: Ty ( ty) => {
1869
- let context = if kind. return_impl_trait_allowed ( ) {
1870
- let fn_def_id = self . local_def_id ( fn_node_id) ;
1871
- ImplTraitContext :: ReturnPositionOpaqueTy {
1872
- origin : hir:: OpaqueTyOrigin :: FnReturn ( fn_def_id) ,
1852
+ let itctx = match kind {
1853
+ FnDeclKind :: Fn
1854
+ | FnDeclKind :: Inherent
1855
+ | FnDeclKind :: Trait
1856
+ | FnDeclKind :: Impl => ImplTraitContext :: ReturnPositionOpaqueTy {
1857
+ origin : hir:: OpaqueTyOrigin :: FnReturn ( self . local_def_id ( fn_node_id) ) ,
1873
1858
fn_kind : kind,
1859
+ } ,
1860
+ FnDeclKind :: ExternFn => {
1861
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: ExternFnReturn )
1862
+ }
1863
+ FnDeclKind :: Closure => {
1864
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: ClosureReturn )
1865
+ }
1866
+ FnDeclKind :: Pointer => {
1867
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: PointerReturn )
1874
1868
}
1875
- } else {
1876
- ImplTraitContext :: Disallowed ( match kind {
1877
- FnDeclKind :: Fn
1878
- | FnDeclKind :: Inherent
1879
- | FnDeclKind :: Trait
1880
- | FnDeclKind :: Impl => {
1881
- unreachable ! ( "fn should allow return-position impl trait in traits" )
1882
- }
1883
- FnDeclKind :: ExternFn => ImplTraitPosition :: ExternFnReturn ,
1884
- FnDeclKind :: Closure => ImplTraitPosition :: ClosureReturn ,
1885
- FnDeclKind :: Pointer => ImplTraitPosition :: PointerReturn ,
1886
- } )
1887
1869
} ;
1888
- hir:: FnRetTy :: Return ( self . lower_ty ( ty, & context ) )
1870
+ hir:: FnRetTy :: Return ( self . lower_ty ( ty, & itctx ) )
1889
1871
}
1890
1872
FnRetTy :: Default ( span) => hir:: FnRetTy :: DefaultReturn ( self . lower_span ( * span) ) ,
1891
1873
} ,
0 commit comments