Open
Description
Given the following code: (no link, as not reproducible in a single file)
Library:
pub enum Foo {
Alpha,
#[non_exhaustive]
Beta,
}
impl Foo {
pub fn beta() -> Self {
Self::Beta
}
}
External user (in this case a test):
use example::Foo;
#[test]
fn demo() {
assert!(matches!(
Foo::beta(),
Foo::Beta
));
}
The current output is:
error[E0603]: unit variant `Beta` is private
--> tests/demo.rs:7:14
|
7 | Foo::Beta
| ^^^^ private unit variant
|
note: the unit variant `Beta` is defined here
--> /home/jhpratt/example/src/lib.rs:4:5
|
4 | Beta,
| ^^^^
Ideally the output should look like:
error[E0638]: `..` required with variant marked as non-exhaustive
--> tests/demo.rs:7:9
|
7 | Foo::Beta
| ^^^^^^^^^
|
help: add `..` at the end of the field list to ignore all other fields
|
7 | Foo::Beta { .. }
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