-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
RFC 2008: Uninhabitedness fixes for enum variants and tests #60529
Conversation
805a891
to
2121cc7
Compare
src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns_same_crate.rs
Outdated
Show resolved
Hide resolved
src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.rs
Outdated
Show resolved
Hide resolved
src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_same_crate.rs
Outdated
Show resolved
Hide resolved
2121cc7
to
5aa1f64
Compare
This comment has been minimized.
This comment has been minimized.
5aa1f64
to
ca6e9c6
Compare
src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.rs
Outdated
Show resolved
Hide resolved
ca6e9c6
to
09e3e43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the barrage of tests! :)
I don't think I understand the examples. pub enum UninhabitedVariants {
#[non_exhaustive] Struct { x: ! }
} The type already has a public uninhabited field, so no amount of added fields will make it inhabited, so it's publicly uninhabited for this crate or for other crates, doesn't matter.
|
If you have exhaustive_patterns, then the type system would let you |
// The struct is externally inhabited, the field addition doesn't change that
struct S { a: PrivDoesntmatter } -> struct S { a: PrivDoesntmatter, b: PrivDoesntmatter }
// The struct is externally inhabited, the field addition doesn't change that
struct S { a: PrivDoesntmatter } -> struct S { a: PrivDoesntmatter, pub b: PubInhabited }
// The struct is externally inhabited, the field addition changes that
struct S { a: PrivDoesntmatter } -> struct S { a: PrivDoesntmatter, pub b: PubUninhabited }
---
// The struct is externally inhabited, the field addition doesn't change that
struct S { pub a: PubInhabited } -> struct S { pub a: PubInhabited, b: PrivDoesntmatter }
// The struct is externally inhabited, the field addition doesn't change that
struct S { pub a: PubInhabited } -> struct S { pub a: PubInhabited, pub b: PubInhabited }
// The struct is externally inhabited, the field addition changes that
struct S { pub a: PubInhabited } -> struct S { pub a: PubInhabited, pub b: PubUninhabited }
---
// The struct is externally uninhabited, the field addition doesn't change that
struct S { pub a: PubUninhabited } -> struct S { pub a: PubInhabited, b: PrivDoesntmatter }
// The struct is externally uninhabited, the field addition doesn't change that
struct S { pub a: PubUninhabited } -> struct S { pub a: PubInhabited, pub b: PubInhabited }
// The struct is externally uninhabited, the field addition doesn't change that
struct S { pub a: PubUninhabited } -> struct S { pub a: PubInhabited, pub b: PubUninhabited } The situation with variants is a bit simpler since they don't have private fields: // The variant is externally inhabited, the field addition doesn't change that
variant S { pub a: PubInhabited } -> variant S { pub a: PubInhabited, pub b: PubInhabited }
// The variant is externally inhabited, the field addition changes that
variant S { pub a: PubInhabited } -> variant S { pub a: PubInhabited, pub b: PubUninhabited }
---
// The variant is externally uninhabited, the field addition doesn't change that
variant S { pub a: PubUninhabited } -> variant S { pub a: PubInhabited, pub b: PubInhabited }
// The variant is externally uninhabited, the field addition doesn't change that
variant S { pub a: PubUninhabited } -> variant S { pub a: PubInhabited, pub b: PubUninhabited } So, if Is adding a new public uninhabited field to something previously inhabited a realistic scenario? (The |
Any other properties that can change if a new field is added? |
Ok, I had some time to digest this and I agree that if addition of a new public uninhabited field can break code, then |
09e3e43
to
f9e4da0
Compare
@petrochenkov I've fixed all of your suggestions. I can't relabel from |
@bors r+ |
📌 Commit f9e4da04abc8e97cd1ae9468b6b4eff67e1c9c64 has been approved by |
⌛ Testing commit f9e4da04abc8e97cd1ae9468b6b4eff67e1c9c64 with merge 1865e9b9959474dd84d33416372a3e6aadc7224e... |
💔 Test failed - status-appveyor |
This commit adds tests checking that uninhabited non-exhaustive types are considered inhabited when used in another crate.
This commit ensures that non-exhaustive variants are considered inhabited when used in extern crates.
This commit ensures that non-exhaustive enums are considered inhabited when used in extern crates.
This commit just tries to tidy up a little.
f9e4da0
to
1f0fb03
Compare
I've rebased this and updated the tests with longer names to use the same fix as #60648 to avoid spurious failures on Windows. |
Legitimate error - file paths are too long ( |
@bors r+ |
📌 Commit 1f0fb03 has been approved by |
…etrochenkov RFC 2008: Uninhabitedness fixes for enum variants and tests Part of rust-lang#44109. At the request of @Centril, this PR adds tests asserting that uninhabited non-exhaustive types are considered inhabited in extern crates. In adding these tests, I fixed an oversight in the implementation of RFC 2008 on enum variants that resulted in non-exhaustive enum variants being considered uninhabited in extern crates. Before this PR, these lines would error: ```rust // extern crate pub enum UninhabitedVariants { #[non_exhaustive] Tuple(!), #[non_exhaustive] Struct { x: ! } } pub enum PartiallyInhabitedVariants { Tuple(u8), #[non_exhaustive] Struct { x: ! } } // current crate match uninhabited_variant() /* fn() -> Option<UninhabitedVariants> */ { Some(_x) => (), //~ ERROR unreachable pattern None => (), } while let PartiallyInhabitedVariants::Struct { x, .. } = partially_inhabited_variant() /* fn() -> PartiallyInhabitedVariants */ { //~^ ERROR unreachable pattern } ``` cc @Centril r? @petrochenkov
Rollup of 6 pull requests Successful merges: - #60529 (RFC 2008: Uninhabitedness fixes for enum variants and tests) - #60620 (Fix a couple of FIXMEs in ext::tt::transcribe) - #60659 (Tweak `Symbol` and `InternedString`) - #60692 (Extend #60676 test for nested mut patterns.) - #60697 (add regression test for #60629) - #60701 (Update mailmap for mati865) Failed merges: r? @ghost
Part of #44109.
At the request of @Centril, this PR adds tests asserting that uninhabited non-exhaustive types are considered inhabited in extern crates. In adding these tests, I fixed an oversight in the implementation of RFC 2008 on enum variants that resulted in non-exhaustive enum variants being considered uninhabited in extern crates.
Before this PR, these lines would error:
cc @Centril
r? @petrochenkov