Skip to content

Commit 15302fa

Browse files
committed
Clarify main discriminant reads rule
The rule, > If pattern matching requires inspecting a discriminant, the relevant > place will get captured by `ImmBorrow`. is unclear in two ways. For one, when does pattern matching "require inspecting" the discriminant? Second, what is the "relevant" place? Let's break this up into two rules (and add rule identifiers). The first rule will state that reading the discriminant captures the place containing the discriminant (by `ImmBorrow`). The second rule will state explicitly the baseline rule for when such reads happen.
1 parent 211d2a4 commit 15302fa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/types/closure.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ let c = || {
288288
r[type.closure.capture.precision.discriminants]
289289
### Capturing for discriminant reads
290290

291-
If pattern matching requires inspecting a discriminant, the relevant place will get captured by `ImmBorrow`.
291+
r[type.closure.capture.precision.discriminants.reads]
292+
If pattern matching reads a discriminant, the place containing that discriminant is captured by `ImmBorrow`.
293+
294+
r[type.closure.capture.precision.discriminants.multiple-variant]
295+
Matching against a variant of an enum that has more than one variant reads the discriminant, capturing the place by `ImmBorrow`.
292296

293297
```rust
294298
enum Example {

0 commit comments

Comments
 (0)