Skip to content

tuple variant error message is confusing #65386

Closed as not planned
Closed as not planned
@ultrasaurus

Description

@ultrasaurus

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:

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

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions