Skip to content

Commit 5299d8a

Browse files
committed
parser: extract ban_unexpected_or_or.
1 parent 5ade61a commit 5299d8a

File tree

1 file changed

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

1 file changed

+13
-11
lines changed

src/libsyntax/parse/parser/pat.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ impl<'a> Parser<'a> {
3131
pats.push(self.parse_top_level_pat()?);
3232

3333
if self.token == token::OrOr {
34-
self.struct_span_err(self.token.span, "unexpected token `||` after pattern")
35-
.span_suggestion(
36-
self.token.span,
37-
"use a single `|` to specify multiple patterns",
38-
"|".to_owned(),
39-
Applicability::MachineApplicable
40-
)
41-
.emit();
34+
self.ban_unexpected_or_or();
4235
self.bump();
4336
} else if self.eat(&token::BinOp(token::Or)) {
4437
// This is a No-op. Continue the loop to parse the next
@@ -49,6 +42,17 @@ impl<'a> Parser<'a> {
4942
};
5043
}
5144

45+
fn ban_unexpected_or_or(&mut self) {
46+
self.struct_span_err(self.token.span, "unexpected token `||` after pattern")
47+
.span_suggestion(
48+
self.token.span,
49+
"use a single `|` to specify multiple patterns",
50+
"|".to_owned(),
51+
Applicability::MachineApplicable
52+
)
53+
.emit();
54+
}
55+
5256
/// A wrapper around `parse_pat` with some special error handling for the
5357
/// "top-level" patterns in a match arm, `for` loop, `let`, &c. (in contrast
5458
/// to subpatterns within such).
@@ -116,9 +120,7 @@ impl<'a> Parser<'a> {
116120
let mut pats = vec![first_pat];
117121

118122
while self.eat(&token::BinOp(token::Or)) {
119-
pats.push(self.parse_pat_with_range_pat(
120-
true, expected
121-
)?);
123+
pats.push(self.parse_pat_with_range_pat(true, expected)?);
122124
}
123125

124126
let or_pattern_span = lo.to(self.prev_span);

0 commit comments

Comments
 (0)