Skip to content

Commit 5408043

Browse files
committed
Revise ...discriminants.uninhabited-variants rule
Let's rename this rule identifier to the plural; we generally use the plural whenever it can make sense, and it does here. Let's make the wording of the rule more clear and self-standing. And let's tighten up the example.
1 parent 45a2381 commit 5408043

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/types/closure.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,22 +340,16 @@ c();
340340
r[type.closure.capture.precision.discriminants.non_exhaustive]
341341
If [`#[non_exhaustive]`][attributes.type-system.non_exhaustive] is applied to an enum defined in an external crate, the enum is treated as having multiple variants for the purpose of deciding whether a read occurs, even if it actually has only one variant.
342342

343-
r[type.closure.capture.precision.discriminants.uninhabited-variant]
344-
Even if all other variants are uninhabited, the discriminant read still occurs.
343+
r[type.closure.capture.precision.discriminants.uninhabited-variants]
344+
Even if all variants but the one being matched against are uninhabited, making the pattern [irrefutable][patterns.refutable], the discriminant is still read if it otherwise would be.
345345

346-
```rust,compile_fail,E0506
347-
enum Void {}
348-
349-
enum Example {
350-
A(i32),
351-
B(Void),
352-
}
353-
354-
let mut x = Example::A(42);
346+
```rust,compile_fail,E0502
347+
enum Empty {}
348+
let mut x = Ok::<_, Empty>(42);
355349
let c = || {
356-
let Example::A(_) = x; // captures `x` by ImmBorrow
350+
let Ok(_) = x; // Captures `x` by `ImmBorrow`.
357351
};
358-
x = Example::A(57); // ERROR: cannot assign to `x` because it is borrowed
352+
let _ = &mut x; // ERROR: Cannot borrow `x` as mutable.
359353
c();
360354
```
361355

0 commit comments

Comments
 (0)