parser: extract ban_unexpected_or_or
.
This commit is contained in:
parent
5ade61a4f1
commit
5299d8a191
1 changed files with 13 additions and 11 deletions
|
@ -31,14 +31,7 @@ impl<'a> Parser<'a> {
|
|||
pats.push(self.parse_top_level_pat()?);
|
||||
|
||||
if self.token == token::OrOr {
|
||||
self.struct_span_err(self.token.span, "unexpected token `||` after pattern")
|
||||
.span_suggestion(
|
||||
self.token.span,
|
||||
"use a single `|` to specify multiple patterns",
|
||||
"|".to_owned(),
|
||||
Applicability::MachineApplicable
|
||||
)
|
||||
.emit();
|
||||
self.ban_unexpected_or_or();
|
||||
self.bump();
|
||||
} else if self.eat(&token::BinOp(token::Or)) {
|
||||
// This is a No-op. Continue the loop to parse the next
|
||||
|
@ -49,6 +42,17 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
}
|
||||
|
||||
fn ban_unexpected_or_or(&mut self) {
|
||||
self.struct_span_err(self.token.span, "unexpected token `||` after pattern")
|
||||
.span_suggestion(
|
||||
self.token.span,
|
||||
"use a single `|` to specify multiple patterns",
|
||||
"|".to_owned(),
|
||||
Applicability::MachineApplicable
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
||||
/// A wrapper around `parse_pat` with some special error handling for the
|
||||
/// "top-level" patterns in a match arm, `for` loop, `let`, &c. (in contrast
|
||||
/// to subpatterns within such).
|
||||
|
@ -116,9 +120,7 @@ impl<'a> Parser<'a> {
|
|||
let mut pats = vec![first_pat];
|
||||
|
||||
while self.eat(&token::BinOp(token::Or)) {
|
||||
pats.push(self.parse_pat_with_range_pat(
|
||||
true, expected
|
||||
)?);
|
||||
pats.push(self.parse_pat_with_range_pat(true, expected)?);
|
||||
}
|
||||
|
||||
let or_pattern_span = lo.to(self.prev_span);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue