Skip to content

Commit 2080f87

Browse files
committed
add section on guard patterns as macro arguments
1 parent 8b63437 commit 2080f87

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

text/3637-guard-patterns.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ 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+
## As Macro Arguments
161+
162+
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:
163+
164+
1. Update `pat` fragments to accept `PatternNoTopGuard` rather than `Pattern`.
165+
2. Introduce a new fragment specifier, `pat_no_top_guard`, which works in all editions and accepts `PatternNoTopGuard`.
166+
3. In the next edition, update `pat` fragments to accept `Pattern` once again.
167+
160168
# Drawbacks
161169
[drawbacks]: #drawbacks
162170

@@ -247,6 +255,7 @@ Guard patterns are, however, very similar to Haskell's [view patterns](https://g
247255
- Using guard patterns at the top-level of `if let` or `while let` instead of let chains?
248256
- Guard patterns within guard patterns instead of using one guard with `&&` in the condition?
249257
- `foo @ (x if guard(x))` rather than `(foo @ x) if guard(x)`? Or maybe this is valid in some cases for localizing match behavior?
258+
- Is `pat_no_top_guard` a good name, or should we use something shorter like `pat_unguarded`?
250259

251260
# Future possibilities
252261
[future-possibilities]: #future-possibilities

0 commit comments

Comments
 (0)