Skip to content
Permalink
Browse files

syntax: de-closure-ify `check_or_expected`.

  • Loading branch information...
Centril committed Oct 1, 2019
1 parent 49780d2 commit e04690440b6d77b4da9bfcf593a641133033ae44
Showing with 7 additions and 7 deletions.
  1. +7 −7 src/libsyntax/parse/parser.rs
@@ -549,37 +549,37 @@ impl<'a> Parser<'a> {
}
}

fn check_or_expected(&mut self, ok: bool, mk_type: impl FnOnce() -> TokenType) -> bool {
fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool {
if ok {
true
} else {
self.expected_tokens.push(mk_type());
self.expected_tokens.push(typ);
false
}
}

crate fn check_ident(&mut self) -> bool {
self.check_or_expected(self.token.is_ident(), || TokenType::Ident)
self.check_or_expected(self.token.is_ident(), TokenType::Ident)
}

fn check_path(&mut self) -> bool {
self.check_or_expected(self.token.is_path_start(), || TokenType::Path)
self.check_or_expected(self.token.is_path_start(), TokenType::Path)
}

fn check_type(&mut self) -> bool {
self.check_or_expected(self.token.can_begin_type(), || TokenType::Type)
self.check_or_expected(self.token.can_begin_type(), TokenType::Type)
}

fn check_const_arg(&mut self) -> bool {
self.check_or_expected(self.token.can_begin_const_arg(), || TokenType::Const)
self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const)
}

/// Checks to see if the next token is either `+` or `+=`.
/// Otherwise returns `false`.
fn check_plus(&mut self) -> bool {
self.check_or_expected(
self.token.is_like_plus(),
|| TokenType::Token(token::BinOp(token::Plus)),
TokenType::Token(token::BinOp(token::Plus)),
)
}

0 comments on commit e046904

Please sign in to comment.
You can’t perform that action at this time.