1
1
use super :: { Parser , PResult , Restrictions , PrevTokenKind , TokenType , PathStyle } ;
2
2
use super :: { BlockCheckMode , BlockMode , SemiColonMode } ;
3
- use super :: SeqSep ;
4
-
5
- use crate :: { maybe_recover_from_interpolated_ty_qpath} ;
3
+ use super :: { SeqSep , TokenExpectType } ;
6
4
5
+ use crate :: maybe_recover_from_interpolated_ty_qpath;
7
6
use crate :: ptr:: P ;
8
- use crate :: ast;
9
- use crate :: ast:: { Attribute , AttrStyle } ;
7
+ use crate :: ast:: { self , Attribute , AttrStyle } ;
10
8
use crate :: ast:: { Ident , CaptureBy } ;
11
9
use 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 } ;
13
11
use crate :: ast:: { BinOpKind , BinOp , UnOp } ;
14
12
use crate :: ast:: { Mac_ , AnonConst , Field } ;
15
13
@@ -22,9 +20,7 @@ use crate::symbol::{kw, sym};
22
20
use crate :: util:: parser:: { AssocOp , Fixity , prec_let_scrutinee_needs_par} ;
23
21
24
22
use std:: mem;
25
-
26
- use errors:: { Applicability } ;
27
-
23
+ use errors:: Applicability ;
28
24
use rustc_data_structures:: thin_vec:: ThinVec ;
29
25
30
26
/// Possibly accepts an `token::Interpolated` expression (a pre-parsed expression
@@ -1142,6 +1138,56 @@ impl<'a> Parser<'a> {
1142
1138
}
1143
1139
}
1144
1140
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
+
1145
1191
/// Parses an `if` expression (`if` token already eaten).
1146
1192
fn parse_if_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
1147
1193
let lo = self . prev_span ;
0 commit comments