Commit 6578441
committed
Remove exception WRT same-crate
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#150681non_exhaustive reads1 parent addd060 commit 6578441
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| |||
0 commit comments