parser: use eat_or_separator for leading vert.

This commit is contained in:
Mazdak Farrokhzad 2019-08-18 18:34:35 +02:00
parent dc5bbaf7b2
commit 6498959377
3 changed files with 14 additions and 3 deletions

View File

@ -22,8 +22,8 @@ pub fn parse_pat(&mut self, expected: Expected) -> PResult<'a, P<Pat>> {
/// Parses patterns, separated by '|' s.
pub(super) fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> {
// Allow a '|' before the pats (RFC 1925 + RFC 2530)
self.eat(&token::BinOp(token::Or));
// Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
self.eat_or_separator();
let mut pats = Vec::new();
loop {

View File

@ -37,4 +37,9 @@ struct NS { f: u8 }
[1 | 2 || 3] => (), //~ ERROR unexpected token `||` after pattern
_ => (),
}
match x {
|| 1 | 2 | 3 => (), //~ ERROR unexpected token `||` after pattern
_ => (),
}
}

View File

@ -34,6 +34,12 @@ error: unexpected token `||` after pattern
LL | [1 | 2 || 3] => (),
| ^^ help: use a single `|` to specify multiple patterns: `|`
error: unexpected token `||` after pattern
--> $DIR/multiple-pattern-typo.rs:42:9
|
LL | || 1 | 2 | 3 => (),
| ^^ help: use a single `|` to specify multiple patterns: `|`
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
--> $DIR/multiple-pattern-typo.rs:1:12
|
@ -42,5 +48,5 @@ LL | #![feature(or_patterns)]
|
= note: `#[warn(incomplete_features)]` on by default
error: aborting due to 6 previous errors
error: aborting due to 7 previous errors