rust/src/libsyntax/parse/parser
Tyler Mandry 1b182371e1
Rollup merge of #65410 - Centril:intersection-pat-recover, r=davidtwco,varkor
syntax: add parser recovery for intersection- / and-patterns `p1 @ p2`

Fixes https://github.com/rust-lang/rust/issues/65400.

The recovery comes in two flavors:

1. We know that `p2` is a binding so we can invert as `p2 @ p1`:

```rust
error: pattern on wrong side of `@`
  --> $DIR/intersection-patterns.rs:13:9
   |
LL |         Some(x) @ y => {}
   |         -------^^^-
   |         |         |
   |         |         binding on the right, should be to the left
   |         pattern on the left, should be to the right
   |         help: switch the order: `y @ Some(x)`
```

2. Otherwise we emit a generic diagnostic for the lack of support for intersection patterns:

```rust
error: left-hand side of `@` must be a binding
  --> $DIR/intersection-patterns.rs:23:9
   |
LL |         Some(x) @ Some(y) => {}
   |         -------^^^-------
   |         |         |
   |         |         also a pattern
   |         interpreted as a pattern, not a binding
   |
   = note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
```

For more on and-patterns, see e.g. https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/pattern-matching#and-pattern.

r? @davidtwco
cc @varkor @lzutao
2019-10-14 17:52:42 -07:00
..
expr.rs ast: remove implicit pprust dependency via Display. 2019-10-13 06:58:51 +02:00
generics.rs review comments: wording 2019-09-21 18:57:37 -07:00
item.rs syntax: consolidate function parsing in item.rs 2019-10-13 14:32:12 +02:00
module.rs Aggregation of cosmetic changes made during work on REPL PRs: libsyntax 2019-09-07 16:29:04 +01:00
pat.rs recover_intersection_pat: adjust wording 2019-10-14 18:02:49 +02:00
path.rs syntax: Support modern attribute syntax in the meta matcher 2019-09-30 22:58:22 +03:00
stmt.rs Rename Stmt.node to Stmt.kind 2019-09-26 18:21:10 +01:00
ty.rs syntax: consolidate function parsing in item.rs 2019-10-13 14:32:12 +02:00