Skip to content

Commit 28db7c5

Browse files
committed
parser: move parse_fn_block_decl into expr.rs
1 parent 848ec4a commit 28db7c5

File tree

2 files changed

+56
-60
lines changed

2 files changed

+56
-60
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::ast::{Mutability};
1919
use crate::ast::StrStyle;
2020
use crate::ast::SelfKind;
2121
use crate::ast::{GenericParam, GenericParamKind, WhereClause};
22-
use crate::ast::{Ty, TyKind, GenericBounds};
22+
use crate::ast::{TyKind, GenericBounds};
2323
use crate::ast::{Visibility, VisibilityKind, Unsafety, CrateSugar};
2424
use crate::ext::base::DummyResult;
2525
use crate::ext::hygiene::SyntaxContext;
@@ -1055,30 +1055,6 @@ impl<'a> Parser<'a> {
10551055
Ok(Arg { attrs: attrs.into(), id: ast::DUMMY_NODE_ID, pat, span, ty })
10561056
}
10571057

1058-
/// Parses an argument in a lambda header (e.g., `|arg, arg|`).
1059-
fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> {
1060-
let lo = self.token.span;
1061-
let attrs = self.parse_arg_attributes()?;
1062-
let pat = self.parse_pat(Some("argument name"))?;
1063-
let t = if self.eat(&token::Colon) {
1064-
self.parse_ty()?
1065-
} else {
1066-
P(Ty {
1067-
id: ast::DUMMY_NODE_ID,
1068-
node: TyKind::Infer,
1069-
span: self.prev_span,
1070-
})
1071-
};
1072-
let span = lo.to(self.token.span);
1073-
Ok(Arg {
1074-
attrs: attrs.into(),
1075-
ty: t,
1076-
pat,
1077-
span,
1078-
id: ast::DUMMY_NODE_ID
1079-
})
1080-
}
1081-
10821058
crate fn check_lifetime(&mut self) -> bool {
10831059
self.expected_tokens.push(TokenType::Lifetime);
10841060
self.token.is_lifetime()
@@ -2148,32 +2124,6 @@ impl<'a> Parser<'a> {
21482124
}))
21492125
}
21502126

2151-
/// Parses the `|arg, arg|` header of a closure.
2152-
fn parse_fn_block_decl(&mut self) -> PResult<'a, P<FnDecl>> {
2153-
let inputs_captures = {
2154-
if self.eat(&token::OrOr) {
2155-
Vec::new()
2156-
} else {
2157-
self.expect(&token::BinOp(token::Or))?;
2158-
let args = self.parse_seq_to_before_tokens(
2159-
&[&token::BinOp(token::Or), &token::OrOr],
2160-
SeqSep::trailing_allowed(token::Comma),
2161-
TokenExpectType::NoExpect,
2162-
|p| p.parse_fn_block_arg()
2163-
)?.0;
2164-
self.expect_or()?;
2165-
args
2166-
}
2167-
};
2168-
let output = self.parse_ret_ty(true)?;
2169-
2170-
Ok(P(FnDecl {
2171-
inputs: inputs_captures,
2172-
output,
2173-
c_variadic: false
2174-
}))
2175-
}
2176-
21772127
fn choose_generics_over_qpath(&self) -> bool {
21782128
// There's an ambiguity between generic parameters and qualified paths in impls.
21792129
// If we see `<` it may start both, so we have to inspect some following tokens.

src/libsyntax/parse/parser/expr.rs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use super::{Parser, PResult, Restrictions, PrevTokenKind, TokenType, PathStyle};
22
use 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;
76
use crate::ptr::P;
8-
use crate::ast;
9-
use crate::ast::{Attribute, AttrStyle};
7+
use crate::ast::{self, Attribute, AttrStyle};
108
use crate::ast::{Ident, CaptureBy};
119
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};
1311
use crate::ast::{BinOpKind, BinOp, UnOp};
1412
use crate::ast::{Mac_, AnonConst, Field};
1513

@@ -22,9 +20,7 @@ use crate::symbol::{kw, sym};
2220
use crate::util::parser::{AssocOp, Fixity, prec_let_scrutinee_needs_par};
2321

2422
use std::mem;
25-
26-
use errors::{Applicability};
27-
23+
use errors::Applicability;
2824
use 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

Comments
 (0)