Skip to content

Commit ba8d793

Browse files
committed
Revise ...discriminants.single-variant rule
Let's simplify the wording of the rule a bit, reiterate the effect of the rule (as we're doing elsewhere), and tighten up the example.
1 parent 336dd93 commit ba8d793

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/types/closure.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,15 @@ c();
325325
```
326326

327327
r[type.closure.capture.precision.discriminants.single-variant]
328-
Matching against the only variant of an enum does not constitute a discriminant read.
328+
Matching against the only variant of a single-variant enum does not read the discriminant and does not capture the place.
329329

330-
```rust
331-
enum Example {
332-
A(i32),
333-
}
334-
335-
let mut x = Example::A(42);
330+
```rust,no_run
331+
enum E<T> { V(T) } // A single-variant enum.
332+
let x = E::V(());
336333
let c = || {
337-
let Example::A(_) = x; // does not capture `x`
334+
let E::V(_) = x; // Does not capture `x`.
338335
};
339-
x = Example::A(57); // `x` can be modified while the closure is live
336+
x; // OK: `x` can be moved here.
340337
c();
341338
```
342339

0 commit comments

Comments
 (0)