Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Or patterns, i.e Foo(Bar(x) | Baz(x)) #2535

Merged
merged 26 commits into from
Oct 7, 2018
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1cd9017
rfc, nested-disjunction-patterns: some initial notes"
Centril Apr 9, 2018
7f9ae99
rfc, or-patterns: initial version.
Centril Aug 29, 2018
99db31d
rfc, or-patterns: move file.
Centril Aug 29, 2018
27c8467
rfc, or-patterns: fix typo.
Centril Aug 29, 2018
fb37a51
rfc, or-patterns: simplify to &(p | q | ..).
Centril Aug 29, 2018
1d959b9
rfc, or-patterns: fix typo.
Centril Aug 29, 2018
6db6ac9
rfc, or-patterns: expand initialism DNF.
Centril Aug 29, 2018
61d4948
rfc, or-patterns: fix an oopsie.
Centril Aug 29, 2018
2f75fbc
rfc, or-patterns: fix inconsistency.
Centril Aug 30, 2018
a1a17bd
rfc, or-patterns: flatten list of languages.
Centril Aug 30, 2018
0501bd4
rfc, or-patterns: be more to the point.
Centril Aug 30, 2018
e410faf
rfc, or-patterns: clarify where i @ p | j @ q is allowed today.
Centril Aug 30, 2018
2c974ae
rfc, or-patterns: code using git2-rs, not from it.
Centril Aug 30, 2018
d477b2c
rfc, or-patterns: permalinks.
Centril Aug 30, 2018
55754ae
rfc, or-patterns: give example blowup.
Centril Aug 30, 2018
a00d802
rfc, or-patterns: more rationale for precedence.
Centril Aug 30, 2018
bf7a7bd
rfc, or-patterns: binding mode is important.
Centril Aug 30, 2018
a206586
rfc, or-patterns: discuss special casing E0408.
Centril Aug 30, 2018
839008b
rfc, or-patterns: fix typo.
Centril Aug 30, 2018
5a820cc
rfc, or-patterns: clarify that top_pat is permitted in fn arguments.
Centril Sep 20, 2018
3b016a3
rfc, or-patterns: discuss macros and closures.
Centril Sep 20, 2018
879fd99
rfc, or-patterns: discuss closures more + func args => pat<no_top_alt>.
Centril Sep 20, 2018
151c8a6
rfc, or-patterns: typo & grammar nit?.
Centril Sep 20, 2018
1ad3e9d
rfc, or-patterns: clarify unification semantics for p | q.
Centril Sep 25, 2018
0032122
rfc, or-patterns: note about macros in guide.
Centril Oct 7, 2018
c73692f
RFC 2535
Centril Oct 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rfc, or-patterns: discuss special casing E0408.
  • Loading branch information
Centril committed Aug 30, 2018
commit a20658609e35d31158f9677641d0adb2e4369443
50 changes: 49 additions & 1 deletion text/0000-or-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,55 @@ In other words, in all of the contexts where a pattern is currently accepted,
the compiler will now accept pattern alternations of form `p | q` where
`p` and `q` are arbitrary patterns.

### Error messages

As previously noted, the precedence of the operator `|` is lower than that of
the operator `@`. This results in `i @ p | q` being interpreted as `(i @ p) | q`.
In turn, this would result in an error because `i` is not defined in all
alternations. An example:

```rust
fn main() {
match 1 {
i @ 0 | 1 => {},
}
}
```

This would result in:

```rust
error[E0408]: variable `i` is not bound in all patterns
--> src/main.rs:3:17
|
3 | i @ 0 | 1 => {},
| - ^ pattern doesn't bind `i`
| |
| variable not in all patterns
```

However, it is quite likely that a user who wrote `i @ p | q` wanted the
semantics of `i @ (p | q)` because it would be the only thing that would
be a well formed pattern. To guide the user on the way, we recommend special
casing the error message for such circumstances with for example:

```rust
error[E0408]: variable `i` is not bound in all patterns
--> src/main.rs:3:17
|
3 | i @ 0 | 1 => {},
| - ^ pattern doesn't bind `i`
| |
| variable not in all patterns
|
| hint: if you wanted `i` to cover both cases, try adding parenthesis around:
|
| i @ 0 | 1
| ^^^^^
```

The particular design of such an error message is left open to implementations.

## Static semantics

1. Given a pattern `p | q` at some depth for some arbitrary patterns `p` and `q`,
Expand Down Expand Up @@ -525,7 +574,6 @@ match expr {
}
```


Instead, it is more likely that a one-step case analysis will be more efficient.

Which implementation technique to use is left open to each Rust compiler.
Expand Down