Skip to content

Commit 6578441

Browse files
committed
Remove exception WRT same-crate non_exhaustive reads
When matching against a single-variant enum marked `non_exhaustive` and defined in a different crate, we pretend that there might be multiple variants and force a read of the discriminant. In [Rust PR 150681], the lang team decided to remove the same-crate exception. Now matching against a single-variant `non_exhaustive` enum in the same crate will also cause a discriminant read. Separately, prior to [Rust PR 150681], `rustc` was eliding the discriminant read when an enum has only one *inhabited* variant. This contradicts what the Reference says in: > r[type.closure.capture.precision.discriminants.uninhabited-variants] > > 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. The lang FCP in the PR decided to confirm the behavior already encoded in the Reference, so no change is needed there. [Rust PR 150681]: rust-lang/rust#150681
1 parent addd060 commit 6578441

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/types/closure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ c();
334334
```
335335

336336
r[type.closure.capture.precision.discriminants.non_exhaustive]
337-
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.
337+
If [`#[non_exhaustive]`][attributes.type-system.non_exhaustive] is applied to an enum, 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.
338338

339339
r[type.closure.capture.precision.discriminants.uninhabited-variants]
340340
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.

0 commit comments

Comments
 (0)