Skip to content

Commit 41f58a7

Browse files
committed
Add help message for incorrect pattern syntax
1 parent 90e019b commit 41f58a7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3432,7 +3432,16 @@ impl<'a> Parser<'a> {
34323432
loop {
34333433
pats.push(self.parse_pat()?);
34343434
if self.check(&token::BinOp(token::Or)) { self.bump();}
3435-
else { return Ok(pats); }
3435+
else {
3436+
// Accidental use of || instead of | inbetween patterns
3437+
if self.token == token::OrOr {
3438+
return Err(self.span_fatal_help(
3439+
self.span, "Unexpected token `||` after pattern",
3440+
"Did you mean to use `|` to specify multiple patterns instead?"));
3441+
}
3442+
3443+
return Ok(pats);
3444+
}
34363445
};
34373446
}
34383447

0 commit comments

Comments
 (0)