Skip to content

Replace check() + bump() with eat() #53897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,7 @@ impl<'a> Parser<'a> {
{
self.expect(bra)?;
let result = self.parse_seq_to_before_end(ket, sep, f)?;
if self.token == *ket {
self.bump();
}
self.eat(ket);
Ok(result)
}

Expand Down Expand Up @@ -1358,8 +1356,7 @@ impl<'a> Parser<'a> {
let ident = self.parse_ident()?;
self.expect(&token::Colon)?;
let ty = self.parse_ty()?;
let default = if self.check(&token::Eq) {
self.bump();
let default = if self.eat(&token::Eq) {
let expr = self.parse_expr()?;
self.expect(&token::Semi)?;
Some(expr)
Expand Down Expand Up @@ -2270,10 +2267,8 @@ impl<'a> Parser<'a> {
while self.token != token::CloseDelim(token::Paren) {
es.push(self.parse_expr()?);
self.expect_one_of(&[], &[token::Comma, token::CloseDelim(token::Paren)])?;
if self.check(&token::Comma) {
if self.eat(&token::Comma) {
trailing_comma = true;

self.bump();
} else {
trailing_comma = false;
break;
Expand All @@ -2299,25 +2294,22 @@ impl<'a> Parser<'a> {

attrs.extend(self.parse_inner_attributes()?);

if self.check(&token::CloseDelim(token::Bracket)) {
if self.eat(&token::CloseDelim(token::Bracket)) {
// Empty vector.
self.bump();
ex = ExprKind::Array(Vec::new());
} else {
// Nonempty vector.
let first_expr = self.parse_expr()?;
if self.check(&token::Semi) {
if self.eat(&token::Semi) {
// Repeating array syntax: [ 0; 512 ]
self.bump();
let count = AnonConst {
id: ast::DUMMY_NODE_ID,
value: self.parse_expr()?,
};
self.expect(&token::CloseDelim(token::Bracket))?;
ex = ExprKind::Repeat(first_expr, count);
} else if self.check(&token::Comma) {
} else if self.eat(&token::Comma) {
// Vector with two or more elements.
self.bump();
let remaining_exprs = self.parse_seq_to_end(
&token::CloseDelim(token::Bracket),
SeqSep::trailing_allowed(token::Comma),
Expand Down Expand Up @@ -3624,8 +3616,7 @@ impl<'a> Parser<'a> {

/// Parse the RHS of a local variable declaration (e.g. '= 14;')
fn parse_initializer(&mut self, skip_eq: bool) -> PResult<'a, Option<P<Expr>>> {
if self.check(&token::Eq) {
self.bump();
if self.eat(&token::Eq) {
Ok(Some(self.parse_expr()?))
} else if skip_eq {
Ok(Some(self.parse_expr()?))
Expand All @@ -3651,8 +3642,8 @@ impl<'a> Parser<'a> {
);
err.emit();
self.bump();
} else if self.check(&token::BinOp(token::Or)) {
self.bump();
} else if self.eat(&token::BinOp(token::Or)) {
// No op.
} else {
return Ok(pats);
}
Expand Down Expand Up @@ -6290,8 +6281,7 @@ impl<'a> Parser<'a> {

let id_span = self.span;
let id = self.parse_ident()?;
if self.check(&token::Semi) {
self.bump();
if self.eat(&token::Semi) {
if in_cfg && self.recurse_into_file_modules {
// This mod is in an external file. Let's go get it!
let ModulePathSuccess { path, directory_ownership, warn } =
Expand Down