-
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
Using variant on self
type with path Self::Variant
causes subpar diagnostic
#52118
Comments
It does, the issue here is rather that type aliases (which includes type Alias = MyEnum;
fn foo() {
let x = Alias::Init; // this also fails
} This has been a longstanding papercut in the language, but there are plans to fix it! An RFC was accepted back in February, and from what I can tell on the tracking issue, the feature is currently waiting for somebody to pick it up and start working on it. |
O_o ...I will agree it's quite possible that, even in the interim, the error message could probably use work. |
I think the "variant" part is fixed on nightly |
The diagnostic still needs to identify that we're referring to a variant through
Then again, one #49683 is completed, the suggestion will no longer be needed. |
The current output is correct, if verbose:
It could maybe suggest using the correct type name, but that might not be completely worth it (anyone using a |
variant::Init
? self
type with path Self::Variant
causes subpar diagnostic
Where is the line that separates "good compiler messages" and "user must know the tool" drawn? Maybe this issue should be closed, unless there is an intention to either:
The current error message is great:
That, combined with proper knowledge of the type system seems like the best approach to me. I don't know if I should close the issue, so I'll let someone with better understanding of the project decisions do it. |
Personally I push as far towards "cater for newcomers" as possible, but this indeed looks like a relatively advanced feature that now is actually supported only on nightly.
That's what what the nightly feature enables, and should be in track to be stabilized within a few versions.
I'm always for improving the errors, and the originally reported one was bad for all the reasons you stated in the original report, but that error is no longer emitted and #49683 will make the whole point mood once it's stabilized :) Grouping errors due to the same feature lint in the same scope is unlikely to happen soon, and not strictly necessary, just a nice to have improvement. On the other hand adding a suggestion or help to use the enum's name instead of |
…petrochenkov Stabilize `type_alias_enum_variants` in Rust 1.37.0 Stabilize `#![feature(type_alias_enum_variants)]` which allows type-relative resolution with highest priority to `enum` variants in both expression and pattern contexts. For example, you may now write: ```rust enum Option<T> { None, Some(T), } type OptAlias<T> = Option<T>; fn work_on_alias(x: Option<u8>) -> u8 { match x { OptAlias::Some(y) => y + 1, OptAlias::None => 0, } } ``` Closes rust-lang/rfcs#2218 Closes #52118 r? @petrochenkov
The snippet below fails to compile with the following messages of each
enum
variant:The solution is to replace
Self::Init
with explicit typeState::Init
. But the issues are:Self
instead of the explicit type)no variant named "Init" found for type "State" in the current scope
is misleadingnote: did you mean "variant::Init"?
is also a little misleading. A phrase likenote: replace "Self::Init" with "State::Init"
is much clearerAnd finally:
Self::
allowed insideimpl MyEnum
blocks?The text was updated successfully, but these errors were encountered: