Skip to content
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

E0599 assumes associated items of enums are variants #56517

Closed
SNCPlay42 opened this issue Dec 4, 2018 · 2 comments · Fixed by #59821
Closed

E0599 assumes associated items of enums are variants #56517

SNCPlay42 opened this issue Dec 4, 2018 · 2 comments · Fixed by #59821
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Dec 4, 2018

enum Enum { Variant }

impl Enum {
    fn misspellable() {}
}

trait Trait {
    fn misspellable_trait() {}
}

impl Trait for Enum {
    fn misspellable_trait() {}
}

fn main() {
    Enum::mispellable();
    Enum::mispellable_trait();
}

Produces the error messages

error[E0599]: no variant named `mispellable` found for type `Enum` in the current scope
  --> src/main.rs:16:5
   |
1  | enum Enum { Variant }
   | --------- variant `mispellable` not found here
...
16 |     Enum::mispellable();
   |     ^^^^^^^^^^^^^^^^^ variant not found in `Enum`
   |
   = help: did you mean `misspellable`?

error[E0599]: no variant named `mispellable_trait` found for type `Enum` in the current scope
  --> src/main.rs:17:5
   |
1  | enum Enum { Variant }
   | --------- variant `mispellable_trait` not found here
...
17 |     Enum::mispellable_trait();
   |     ^^^^^^^^^^^^^^^^^^^^^^^ variant not found in `Enum`

error: aborting due to 2 previous errors

I would expect the message to read "variant or associated item" instead of just "variant". The current message is confusing; it could lead users to believe the compiler is expecting to see a variant, and would not allow functions, in the context where the error occurred (note that no spelling suggestion is given if the item is from a trait, furthering the confusion).

Playground

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Dec 4, 2018
@SNCPlay42
Copy link
Contributor Author

Previous discussions: #28972, #46024 (comment)

@estebank
Copy link
Contributor

Current output has changed slightly:

error[E0599]: no variant named `mispellable` found for type `Enum` in the current scope
  --> file2.rs:16:11
   |
1  | enum Enum { Variant }
   | --------- variant `mispellable` not found here
...
16 |     Enum::mispellable();
   |     ------^^^^^^^^^^^
   |     |
   |     variant not found in `Enum`
   |     help: did you mean: `misspellable`

error[E0599]: no variant named `mispellable_trait` found for type `Enum` in the current scope
  --> file2.rs:17:11
   |
1  | enum Enum { Variant }
   | --------- variant `mispellable_trait` not found here
...
17 |     Enum::mispellable_trait();
   |     ------^^^^^^^^^^^^^^^^^
   |     |
   |     variant not found in `Enum`

Now it is even worse because the suggestion points at the wrong span, so when applied it creates incorrect code :-(

cramertj added a commit to cramertj/rust that referenced this issue Apr 11, 2019
…idtwco

improve unknown enum variant errors

Fixes rust-lang#56517.
Centril added a commit to Centril/rust that referenced this issue Apr 12, 2019
…idtwco

improve unknown enum variant errors

Fixes rust-lang#56517.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants