Skip to content

Commit cef4655

Browse files
committed
Recover type casts in patterns
1 parent 6f83cd3 commit cef4655

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+4
-2
lines changed

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,13 @@ impl<'a> Parser<'a> {
383383
// `|` is excluded as it is used in pattern alternatives and lambdas,
384384
// `?` is included for error propagation,
385385
// `[` is included for indexing operations,
386-
// `[]` is excluded as `a[]` isn't an expression and should be recovered as `a, []` (cf. `tests/ui/parser/pat-lt-bracket-7.rs`)
386+
// `[]` is excluded as `a[]` isn't an expression and should be recovered as `a, []` (cf. `tests/ui/parser/pat-lt-bracket-7.rs`),
387+
// `as` is included for type casts
387388
let has_trailing_operator = matches!(self.token.kind, token::BinOp(op) if op != BinOpToken::Or)
388389
|| self.token.kind == token::Question
389390
|| (self.token.kind == token::OpenDelim(Delimiter::Bracket)
390-
&& self.look_ahead(1, |tok| tok.kind != token::CloseDelim(Delimiter::Bracket)));
391+
&& self.look_ahead(1, |tok| tok.kind != token::CloseDelim(Delimiter::Bracket)))
392+
|| self.token.is_keyword(kw::As);
391393

392394
if !has_dot_expr && !has_trailing_operator {
393395
// Nothing to recover here.

0 commit comments

Comments
 (0)