-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
E0603 is misleading on non-exhaustive enums #82788
Comments
Ahh looking at the tests for the corresponding RFC, this seems like desired behavior for Unit like enum Variants: rust/src/test/ui/rfc-2008-non-exhaustive/variant.rs Lines 7 to 33 in 3a5d45f
But I agree that this behavior is kind of odd. A potential fix would involve not setting the unit variants to private but treating them as a struct-like variants. If this is the desired behavior I would be happy to implement it! |
Note that the same happens with structs too: /// ```
/// let lib::Foo = lib::Foo::default();
/// ```
#[non_exhaustive]
#[derive(Default)]
pub struct Foo;
|
Document that adding `#[non_exhaustive]` on existing items is breaking. ### What does this PR try to resolve? Adding `#[non_exhaustive]` to an existing struct, enum, or variant is almost always a breaking change and requires a major version bump for semver purposes. This PR adds a section to the semver reference page that describes this and provides examples showing how `#[non_exhaustive]` can break code. ### Additional information Adding `#[non_exhaustive]` to a unit struct currently has no effect on whether that struct can be constructed in downstream crates. This is inconsistent with the behavior of `#[non_exhaustive]` on unit enum variants, which may not be constructed outside their own crate. This might be due to a similar underlying cause as: rust-lang/rust#78586 The confusing "variant is private" error messages for non-exhaustive unit and tuple variants are a known issue tracked in: rust-lang/rust#82788 Checking for the struct portion of this semver rule is done in: obi1kenobi/cargo-semver-checks#4
Given the following code: (no link, as not reproducible in a single file)
Library:
External user (in this case a test):
The current output is:
Ideally the output should look like:
Right now, the cause of the error is misleading, as it seems to imply that an enum variant is private (which is impossible). The error message should be updated to match the error provided when there are some fields present, but not the
..
as required. The exact wording might vary a bit, but I copied it verbatim here. Given the explanation of E0603, I believe that this is the wrong error code altogether.@rustbot modify labels to +A-diagnostics +T-compiler +D-confusing +D-incorrect
The text was updated successfully, but these errors were encountered: