Skip to content

Commit 682033c

Browse files
committed
Implemented eat_plus and used it in parsing parse_ty_param_bounds_common.
1 parent c610be9 commit 682033c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,27 @@ impl<'a> Parser<'a> {
880880
false
881881
}
882882
}
883+
884+
/// Expect and consume a `+`. if `+=` is seen, replace it with a `=`
885+
/// and continue. If a `+` is not seen, return false.
886+
///
887+
/// This is using when token splitting += into +.
888+
/// See issue 47856 for an example of when this may occur.
889+
fn eat_plus(&mut self) -> bool {
890+
self.expected_tokens.push(TokenType::Token(token::BinOp(token::Plus)));
891+
match self.token {
892+
token::BinOp(token::Plus) => {
893+
self.bump();
894+
true
895+
}
896+
token::BinOpEq(token::Plus) => {
897+
let span = self.span.with_lo(self.span.lo() + BytePos(1));
898+
self.bump_with(token::Eq, span);
899+
true
900+
}
901+
_ => false,
902+
}
903+
}
883904

884905
/// Expect and consume an `&`. If `&&` is seen, replace it with a single
885906
/// `&` and continue. If an `&` is not seen, signal an error.
@@ -4801,7 +4822,7 @@ impl<'a> Parser<'a> {
48014822
break
48024823
}
48034824

4804-
if !allow_plus || !self.eat(&token::BinOp(token::Plus)) {
4825+
if !allow_plus || !self.eat_plus() {
48054826
break
48064827
}
48074828
}

0 commit comments

Comments
 (0)