11use super :: { Parser , PResult , Restrictions , PrevTokenKind , TokenType , PathStyle } ;
22use super :: { BlockCheckMode , BlockMode , SemiColonMode } ;
3- use super :: SeqSep ;
4-
5- use crate :: { maybe_recover_from_interpolated_ty_qpath} ;
3+ use super :: { SeqSep , TokenExpectType } ;
64
5+ use crate :: maybe_recover_from_interpolated_ty_qpath;
76use crate :: ptr:: P ;
8- use crate :: ast;
9- use crate :: ast:: { Attribute , AttrStyle } ;
7+ use crate :: ast:: { self , Attribute , AttrStyle } ;
108use crate :: ast:: { Ident , CaptureBy } ;
119use crate :: ast:: { Expr , ExprKind , RangeLimits , Label , Movability , IsAsync , Arm } ;
12- use crate :: ast:: { Ty , TyKind , FunctionRetTy } ;
10+ use crate :: ast:: { Ty , TyKind , FunctionRetTy , Arg , FnDecl } ;
1311use crate :: ast:: { BinOpKind , BinOp , UnOp } ;
1412use crate :: ast:: { Mac_ , AnonConst , Field } ;
1513
@@ -22,9 +20,7 @@ use crate::symbol::{kw, sym};
2220use crate :: util:: parser:: { AssocOp , Fixity , prec_let_scrutinee_needs_par} ;
2321
2422use std:: mem;
25-
26- use errors:: { Applicability } ;
27-
23+ use errors:: Applicability ;
2824use rustc_data_structures:: thin_vec:: ThinVec ;
2925
3026/// Possibly accepts an `token::Interpolated` expression (a pre-parsed expression
@@ -1142,6 +1138,56 @@ impl<'a> Parser<'a> {
11421138 }
11431139 }
11441140
1141+ /// Parses the `|arg, arg|` header of a closure.
1142+ fn parse_fn_block_decl ( & mut self ) -> PResult < ' a , P < FnDecl > > {
1143+ let inputs_captures = {
1144+ if self . eat ( & token:: OrOr ) {
1145+ Vec :: new ( )
1146+ } else {
1147+ self . expect ( & token:: BinOp ( token:: Or ) ) ?;
1148+ let args = self . parse_seq_to_before_tokens (
1149+ & [ & token:: BinOp ( token:: Or ) , & token:: OrOr ] ,
1150+ SeqSep :: trailing_allowed ( token:: Comma ) ,
1151+ TokenExpectType :: NoExpect ,
1152+ |p| p. parse_fn_block_arg ( )
1153+ ) ?. 0 ;
1154+ self . expect_or ( ) ?;
1155+ args
1156+ }
1157+ } ;
1158+ let output = self . parse_ret_ty ( true ) ?;
1159+
1160+ Ok ( P ( FnDecl {
1161+ inputs : inputs_captures,
1162+ output,
1163+ c_variadic : false
1164+ } ) )
1165+ }
1166+
1167+ /// Parses an argument in a lambda header (e.g., `|arg, arg|`).
1168+ fn parse_fn_block_arg ( & mut self ) -> PResult < ' a , Arg > {
1169+ let lo = self . token . span ;
1170+ let attrs = self . parse_arg_attributes ( ) ?;
1171+ let pat = self . parse_pat ( Some ( "argument name" ) ) ?;
1172+ let t = if self . eat ( & token:: Colon ) {
1173+ self . parse_ty ( ) ?
1174+ } else {
1175+ P ( Ty {
1176+ id : ast:: DUMMY_NODE_ID ,
1177+ node : TyKind :: Infer ,
1178+ span : self . prev_span ,
1179+ } )
1180+ } ;
1181+ let span = lo. to ( self . token . span ) ;
1182+ Ok ( Arg {
1183+ attrs : attrs. into ( ) ,
1184+ ty : t,
1185+ pat,
1186+ span,
1187+ id : ast:: DUMMY_NODE_ID
1188+ } )
1189+ }
1190+
11451191 /// Parses an `if` expression (`if` token already eaten).
11461192 fn parse_if_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
11471193 let lo = self . prev_span ;
0 commit comments