Skip to content

Commit

Permalink
Replace check() + bump() with eat()
Browse files Browse the repository at this point in the history
  • Loading branch information
topecongiro committed Sep 2, 2018
1 parent 3480ac2 commit 51dbb02
Showing 1 changed file with 10 additions and 20 deletions.
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

0 comments on commit 51dbb02

Please sign in to comment.