Skip to content

Commit 50157c7

Browse files
committed
clarify no intent to change binding requirements wrt disjunctions
1 parent 0581da5 commit 50157c7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

text/3637-guard-patterns.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ let (Struct { x, y } if x == y) = Struct { x: 0, y: 0 } else { /* ... */ }
157157

158158
In general, guards can, without changing meaning, "move outwards" until they reach an or-pattern where the condition can be different in other branches, and "move inwards" until they reach a level where the identifiers they reference are not bound.
159159

160+
## Bindings Must Still Match Across Disjunctions
161+
162+
This RFC does _not_ propose to change what bindings are allowed in disjunctions, even when those bindings are used only within guard patterns.
163+
164+
For example, the following code will error just like it would without any guard patterns:
165+
166+
```rust
167+
match Some(0) {
168+
Some(x if x > 0) | None => {},
169+
//~^ ERROR variable `x` is not bound in all patterns
170+
_ => {},
171+
}
172+
```
173+
160174
## As Macro Arguments
161175

162176
Currently, `if` is in the follow set of `pat` and `pat_param` fragments, so top-level guards cannot be used as arguments for the current edition. This is identical to the situation with top-level or-patterns as macro arguments, and guard patterns will take the same approach:

0 commit comments

Comments
 (0)