Closed as not planned
Description
originally described in blog post: https://www.ultrasaurus.com/2019/10/rust-whats-a-tuple-variant/
sample code:
fn get_num() -> Result<i32, &'static str> {
let result = 4;
OK(result)
}
error message:
error[E0425]: cannot find function `OK` in this scope
--> examples/tuple.rs:13:3
|
13 | OK(result)
| ^^ help: a tuple variant with a similar name exists: `Ok`
Error message suggestions:
- From @estebank playground
- point to line 2 (even if defined in standard library) and the compiled code which differs by case (addressed in Point at local similarly named element and tweak references to variants #65421, Point at the span for the definition of crate foreign ADTs #65912)
- include additional context in the error: "a similar name exists:
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 docs
- special error for a difference in captilization (from @estebank via tweet) (addressed in Bring attention to suggestions when the only difference is capitalization #65398)
- change help text to make clear that this symbol is not recognized (when I ran into this, I thought at first that perhaps I had created a conflicting definition of a tuple variant that was somehow defined elsewhere), perhaps something like "help:
OK
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) - call out the specific difference when suggesting similar term -- colors are really nice for visually-oriented people, but not super accessible. Could also include "O[K/k]" which would really help when difference is embedded in a string "foo::ba[r/z]::App" (example from @estebank tweet) -- see related Highlight only relevant parts of type path in type errors #57413
General terminology suggestions:
- stop referring to "tuple-like enum" and "tuple-like struct" and instead come up with a more precise term, such as "named tuple" (or "typed tuple" but I like the former better) which could be declared as a struct or as part of an enum.
- refer to the struct / enum use of tuples in the book, here: https://doc.rust-lang.org/1.7.0/book/primitive-types.html#tuples link to Tuple structs and create a similar titled sub-section of enum and include a link to that
- standardize naming of struct and enum and create logical parallel: unit enum / unit struct OR enum unit variant / struct unit variant (I prefer the former with fewer words)
- when you standardize on the names, consider annotate them here:
enum Message {
Quit, // unit enum
ChangeColor(i32, i32, i32), // tuple enum
Move { x: i32, y: i32 }, // struct enum
Write(String), // also a tuple enum
}
(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)
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.