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

This commit is contained in:
Seiichi Uchida
2018-09-02 15:13:29 +09:00
parent 3480ac2a80
commit 51dbb024f7

View File

@@ -1160,9 +1160,7 @@ impl<'a> Parser<'a> {
{ {
self.expect(bra)?; self.expect(bra)?;
let result = self.parse_seq_to_before_end(ket, sep, f)?; let result = self.parse_seq_to_before_end(ket, sep, f)?;
if self.token == *ket { self.eat(ket);
self.bump();
}
Ok(result) Ok(result)
} }
@@ -1358,8 +1356,7 @@ impl<'a> Parser<'a> {
let ident = self.parse_ident()?; let ident = self.parse_ident()?;
self.expect(&token::Colon)?; self.expect(&token::Colon)?;
let ty = self.parse_ty()?; let ty = self.parse_ty()?;
let default = if self.check(&token::Eq) { let default = if self.eat(&token::Eq) {
self.bump();
let expr = self.parse_expr()?; let expr = self.parse_expr()?;
self.expect(&token::Semi)?; self.expect(&token::Semi)?;
Some(expr) Some(expr)
@@ -2270,10 +2267,8 @@ impl<'a> Parser<'a> {
while self.token != token::CloseDelim(token::Paren) { while self.token != token::CloseDelim(token::Paren) {
es.push(self.parse_expr()?); es.push(self.parse_expr()?);
self.expect_one_of(&[], &[token::Comma, token::CloseDelim(token::Paren)])?; self.expect_one_of(&[], &[token::Comma, token::CloseDelim(token::Paren)])?;
if self.check(&token::Comma) { if self.eat(&token::Comma) {
trailing_comma = true; trailing_comma = true;
self.bump();
} else { } else {
trailing_comma = false; trailing_comma = false;
break; break;
@@ -2299,25 +2294,22 @@ impl<'a> Parser<'a> {
attrs.extend(self.parse_inner_attributes()?); attrs.extend(self.parse_inner_attributes()?);
if self.check(&token::CloseDelim(token::Bracket)) { if self.eat(&token::CloseDelim(token::Bracket)) {
// Empty vector. // Empty vector.
self.bump();
ex = ExprKind::Array(Vec::new()); ex = ExprKind::Array(Vec::new());
} else { } else {
// Nonempty vector. // Nonempty vector.
let first_expr = self.parse_expr()?; let first_expr = self.parse_expr()?;
if self.check(&token::Semi) { if self.eat(&token::Semi) {
// Repeating array syntax: [ 0; 512 ] // Repeating array syntax: [ 0; 512 ]
self.bump();
let count = AnonConst { let count = AnonConst {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
value: self.parse_expr()?, value: self.parse_expr()?,
}; };
self.expect(&token::CloseDelim(token::Bracket))?; self.expect(&token::CloseDelim(token::Bracket))?;
ex = ExprKind::Repeat(first_expr, count); ex = ExprKind::Repeat(first_expr, count);
} else if self.check(&token::Comma) { } else if self.eat(&token::Comma) {
// Vector with two or more elements. // Vector with two or more elements.
self.bump();
let remaining_exprs = self.parse_seq_to_end( let remaining_exprs = self.parse_seq_to_end(
&token::CloseDelim(token::Bracket), &token::CloseDelim(token::Bracket),
SeqSep::trailing_allowed(token::Comma), SeqSep::trailing_allowed(token::Comma),
@@ -3624,8 +3616,7 @@ impl<'a> Parser<'a> {
/// Parse the RHS of a local variable declaration (e.g. '= 14;') /// Parse the RHS of a local variable declaration (e.g. '= 14;')
fn parse_initializer(&mut self, skip_eq: bool) -> PResult<'a, Option<P<Expr>>> { fn parse_initializer(&mut self, skip_eq: bool) -> PResult<'a, Option<P<Expr>>> {
if self.check(&token::Eq) { if self.eat(&token::Eq) {
self.bump();
Ok(Some(self.parse_expr()?)) Ok(Some(self.parse_expr()?))
} else if skip_eq { } else if skip_eq {
Ok(Some(self.parse_expr()?)) Ok(Some(self.parse_expr()?))
@@ -3651,8 +3642,8 @@ impl<'a> Parser<'a> {
); );
err.emit(); err.emit();
self.bump(); self.bump();
} else if self.check(&token::BinOp(token::Or)) { } else if self.eat(&token::BinOp(token::Or)) {
self.bump(); // No op.
} else { } else {
return Ok(pats); return Ok(pats);
} }
@@ -6290,8 +6281,7 @@ impl<'a> Parser<'a> {
let id_span = self.span; let id_span = self.span;
let id = self.parse_ident()?; let id = self.parse_ident()?;
if self.check(&token::Semi) { if self.eat(&token::Semi) {
self.bump();
if in_cfg && self.recurse_into_file_modules { if in_cfg && self.recurse_into_file_modules {
// This mod is in an external file. Let's go get it! // This mod is in an external file. Let's go get it!
let ModulePathSuccess { path, directory_ownership, warn } = let ModulePathSuccess { path, directory_ownership, warn } =