Skip to content

Commit 30b841d

Browse files
committed
parser: improve or-patterns recovery.
1 parent 0bbea47 commit 30b841d

File tree

1 file changed

+11
-4
lines changed
  • src/libsyntax/parse/parser

1 file changed

+11
-4
lines changed

src/libsyntax/parse/parser/pat.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,25 @@ impl<'a> Parser<'a> {
110110

111111
// If the next token is not a `|`,
112112
// this is not an or-pattern and we should exit here.
113-
if !self.check(&token::BinOp(token::Or)) {
113+
if !self.check(&token::BinOp(token::Or)) && self.token != token::OrOr {
114114
return Ok(first_pat)
115115
}
116116

117117
let lo = first_pat.span;
118-
119118
let mut pats = vec![first_pat];
119+
loop {
120+
if self.token == token::OrOr {
121+
// Found `||`; Recover and pretend we parsed `|`.
122+
self.ban_unexpected_or_or();
123+
self.bump();
124+
} else if self.eat(&token::BinOp(token::Or)) {
125+
// Found `|`. Working towards a proper or-pattern.
126+
} else {
127+
break;
128+
}
120129

121-
while self.eat(&token::BinOp(token::Or)) {
122130
pats.push(self.parse_pat_with_range_pat(true, expected)?);
123131
}
124-
125132
let or_pattern_span = lo.to(self.prev_span);
126133

127134
// Feature gate the or-pattern if instructed:

0 commit comments

Comments
 (0)