-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ignore uninhabited non-exhaustive variant fields #65414
ignore uninhabited non-exhaustive variant fields #65414
Conversation
I'm not sure if this is the best way to fix this, so I'm happy to take an alternate approach if anyone has a better solution. |
Yeah, I'd think there must be a better solution. |
The idea is that with |
So this is about ignoring uninhabitedness when the variant is marked |
Okay I figured it out. I'll take this line as an example:
That line would be detected as unreachable if the variant wasn't declared non_exhaustive . The reason for this behaviour is that we start with v = [PartiallyInhabitedVariants::Struct { x, .. }] , then we specialize it by the PartiallyInhabitedVariants::Struct constructor. Then v = [_] where the wildcard has type ! . So it is detected as unreachable.
We can't avoid expanding
So I'd say a good solution might be to specifically ignore the fields of Does that make sense ? PS: @davidtwco would you mind waiting for #65160 to get merged before merging this PR ? Otherwise I'd have to rebase the fix and it will be a pain. |
I haven’t read this yet, will do later.
No worries, I just wanted to put something up to get review. |
11a0114
to
dd5bd7b
Compare
Thanks @Nadrieril, I've updated the PR with your suggested approach. |
This comment has been minimized.
This comment has been minimized.
dd5bd7b
to
1bf1236
Compare
r? @varkor |
This commit modifies the uninhabitedness checking so that the fields of a non-exhaustive variant (which is not local) are ignored if they are uninhabited. This is an improvement over the previous behaviour which considered all non-local non-exhaustive variants useful because unreachable patterns are now detected. Signed-off-by: David Wood <david@davidtw.co>
1bf1236
to
7ffbd62
Compare
Sounds reasonable; it does enhance the rationale for @Nadrieril to split their PR into parts. ;) |
@bors r+ rollup |
📌 Commit 7ffbd62 has been approved by |
…e-always-useful, r=varkor ignore uninhabited non-exhaustive variant fields Fixes rust-lang#65157. This PR modifies the uninhabitedness checking so that the fields of a non-exhaustive variant (which is not local) are ignored if they are uninhabited. This is an improvement over the previous behaviour which considered all non-local non-exhaustive variants useful because unreachable patterns are now detected. r? @arielb1 cc @varkor
Rollup of 9 pull requests Successful merges: - #62959 (Add by-value iterator for arrays ) - #65390 (Add long error explanation for E0576) - #65408 (reorder config.toml.example options and add one missing option) - #65414 (ignore uninhabited non-exhaustive variant fields) - #65666 (Deprecated proc_macro doesn't trigger warning on build library) - #65742 (Pre-expansion gate most of the things) - #65747 (Adjust the tracking issue for `untagged_unions`.) - #65763 (Changed APIT with explicit generic args span to specific arg spans) - #65775 (Fix more `ReEmpty` ICEs) Failed merges: - #65519 (trait-based structural match implementation) r? @ghost
Fixes #65157.
This PR modifies the uninhabitedness checking so that the fields of
a non-exhaustive variant (which is not local) are ignored if they are
uninhabited. This is an improvement over the previous behaviour which
considered all non-local non-exhaustive variants useful because
unreachable patterns are now detected.
r? @arielb1
cc @varkor