@@ -304,8 +304,6 @@ enum ImplTraitPosition {
304304 ClosureParam ,
305305 PointerParam ,
306306 FnTraitParam ,
307- TraitParam ,
308- ImplParam ,
309307 ExternFnReturn ,
310308 ClosureReturn ,
311309 PointerReturn ,
@@ -324,29 +322,27 @@ impl std::fmt::Display for ImplTraitPosition {
324322 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
325323 let name = match self {
326324 ImplTraitPosition :: Path => "paths" ,
327- ImplTraitPosition :: Variable => "variable bindings" ,
325+ ImplTraitPosition :: Variable => "the type of variable bindings" ,
328326 ImplTraitPosition :: Trait => "traits" ,
329327 ImplTraitPosition :: AsyncBlock => "async blocks" ,
330328 ImplTraitPosition :: Bound => "bounds" ,
331329 ImplTraitPosition :: Generic => "generics" ,
332- ImplTraitPosition :: ExternFnParam => "`extern fn` params" ,
333- ImplTraitPosition :: ClosureParam => "closure params" ,
334- ImplTraitPosition :: PointerParam => "`fn` pointer params" ,
335- ImplTraitPosition :: FnTraitParam => "`Fn` trait params" ,
336- ImplTraitPosition :: TraitParam => "trait method params" ,
337- ImplTraitPosition :: ImplParam => "`impl` method params" ,
330+ ImplTraitPosition :: ExternFnParam => "`extern fn` parameters" ,
331+ ImplTraitPosition :: ClosureParam => "closure parameters" ,
332+ ImplTraitPosition :: PointerParam => "`fn` pointer parameters" ,
333+ ImplTraitPosition :: FnTraitParam => "the parameters of `Fn` trait bounds" ,
338334 ImplTraitPosition :: ExternFnReturn => "`extern fn` return types" ,
339335 ImplTraitPosition :: ClosureReturn => "closure return types" ,
340336 ImplTraitPosition :: PointerReturn => "`fn` pointer return types" ,
341- ImplTraitPosition :: FnTraitReturn => "`Fn` trait return types " ,
337+ ImplTraitPosition :: FnTraitReturn => "the return type of `Fn` trait bounds " ,
342338 ImplTraitPosition :: GenericDefault => "generic parameter defaults" ,
343339 ImplTraitPosition :: ConstTy => "const types" ,
344340 ImplTraitPosition :: StaticTy => "static types" ,
345341 ImplTraitPosition :: AssocTy => "associated types" ,
346342 ImplTraitPosition :: FieldTy => "field types" ,
347- ImplTraitPosition :: Cast => "cast types" ,
343+ ImplTraitPosition :: Cast => "cast expression types" ,
348344 ImplTraitPosition :: ImplSelf => "impl headers" ,
349- ImplTraitPosition :: OffsetOf => "`offset_of!` params " ,
345+ ImplTraitPosition :: OffsetOf => "`offset_of!` parameters " ,
350346 } ;
351347
352348 write ! ( f, "{name}" )
@@ -364,19 +360,6 @@ enum FnDeclKind {
364360 Impl ,
365361}
366362
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-
380363#[ derive( Copy , Clone ) ]
381364enum AstOwner < ' a > {
382365 NonOwner ,
@@ -1842,19 +1825,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18421825 inputs = & inputs[ ..inputs. len ( ) - 1 ] ;
18431826 }
18441827 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+ }
18581841 } ;
18591842 self . lower_ty_direct ( & param. ty , & itctx)
18601843 } ) ) ;
@@ -1866,26 +1849,25 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18661849 }
18671850 None => match & decl. output {
18681851 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) ) ,
18731858 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 )
18741868 }
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- } )
18871869 } ;
1888- hir:: FnRetTy :: Return ( self . lower_ty ( ty, & context ) )
1870+ hir:: FnRetTy :: Return ( self . lower_ty ( ty, & itctx ) )
18891871 }
18901872 FnRetTy :: Default ( span) => hir:: FnRetTy :: DefaultReturn ( self . lower_span ( * span) ) ,
18911873 } ,
0 commit comments