-
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
tuple variant error message is confusing #65386
Comments
Tagging the docs team for the latter half of the ticket. |
A "unit enum" suggests an enum with a single variant rather than the unit variant of an enum; I would call this a "enum unit variant", which is albeit more verbose, also more clear. |
Missed one suggestion.. the first part of the error message is a bit misleading since it implies that Instead of:
it could be something like this:
|
@Centril would it be typical/common for someone create an enum with a single variant? seems like that would be unlikely in normal practice. If so, I would use more words to describe the less common use case, such as "enum with single variant" |
No it's not usual but e.g. "tuple enum" still makes a category mistake by conflating the data type itself with its constructors (the variant in this case). I think that paints a misleading mental model of the language, which is avoidable by including an additional word. |
hmm... I was reading "tuple" in "tuple enum" as an adjective -- a descriptor (to me) doesn't necessarily change the data type. However, I agree that this is an important clarification (that I missed in early readings of the docs) about the difference between an enum and a struct, where enum variants are all the same type and the equivalent struct syntax creates multiple types. In practice, I wasn't confused, but wasn't really conscious of this nuance in a way I could have spoken about it. FYI: in case it is useful, I ran into an example of "unit enum" used in the wild: https://users.rust-lang.org/t/what-is-a-unit-variant/18468/2 |
Looking a bit into this, procuring the @petrochenkov what do you think is the feasibility of having the prelude imports carry correct |
Bring attention to suggestions when the only difference is capitalization CC rust-lang#65386.
It's more about spans for all extern items than about spans from std prelude specifically. |
From a quick look I don't like what this issue suggests in general, we have some pretty stable terminology in place and it's used consistently. |
If you can point me in the right direction to use the original spans, I can take a look at the non-deterministic output.
Even if we don't change the terminology at all (and I think there is room for tweaks targeting newcomers to reduce confusion), the addition of better spans will make acquiring understanding of what the different concepts mean much easier. |
|
"tuple variant" is not a stable or consistent term (except where context is given that people are talking about an enum). Stand-alone in an error message, it is pretty meaningless. |
Well, it is indeed stable and consistent. |
To clarify, I'm certainly not against showing examples with spans and perhaps improving documentation, only against inventing a new terminology instead of the already established one. |
@ultrasaurus would this output have been enough for you understand what was happening? |
@estebank that would have definitely helped! If you can put some kind of break between the code from diff files, I think that would be more readable. Just in case it's nearby, the "cannot find function..." seems to conflict with "similarly named tuple variant".... would it be possible to change to "cannot find function or enum tuple variant..." at the top of your screenshot. Thanks for your attention to this detail! |
This is great! It would have helped me if "tuple variant" had the word "enum" near it. Would it be correct to say "enum tuple variant" ? Not intending to be nit-picky, just providing feedback. The given context should provide enough breadcrumbs for a novice :) |
Yeah it's correct. It just has some redundancy because a tuple variant always belongs to an enum. That said, redundancy can be useful. |
Point at local similarly named element and tweak references to variants Partially address rust-lang#65386.
Point at local similarly named element and tweak references to variants Partially address #65386.
It appears that this error message is no longer confusing and should be fine to close this issue. If there are any improvements, it will be better in a new issue. |
originally described in blog post: https://www.ultrasaurus.com/2019/10/rust-whats-a-tuple-variant/
sample code:
error message:
Error message suggestions:
Ok
(which is a tuple variant ofenum Result
)" -- then the reference to "tuple variant" has context and there's a clear reference to look up in the docsOK
has not yet been defined, perhaps you meant to refer to:Ok
, which has a similar name" (addressed in Point at local similarly named element and tweak references to variants #65421)General terminology suggestions:
(by the way, the above example is very good serving as both an introduction to the section content and an easy syntax reference that is quick to find later)
The text was updated successfully, but these errors were encountered: