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

Error reporting when using enum variants of Self is not making any sense #48743

Closed
glandium opened this issue Mar 5, 2018 · 2 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@glandium
Copy link
Contributor

glandium commented Mar 5, 2018

Take the following code:

pub enum Foo { A }

impl Foo {
    pub fn new() -> Self {
        Self::A
    }
}

This is known to not work (I don't know if it's on file or not, but will report separately), but the error reported is really not helping developers:

error[E0599]: no variant named `A` found for type `Foo` in the current scope
 --> <source>:5:9
  |
1 | pub enum Foo { A }
  | ------------ variant `A` not found here
...
5 |         Self::A
  |         ^^^^^^^ variant not found in `Foo`
error: aborting due to previous error
Compiler returned: 101

Not only is it reporting the right type, but it's also pointing to the definition where the variant is defined.

This actually got worse in 1.24. 1.23 and older versions only reported the following, which was already bad, but the new message is significantly worse:

error[E0599]: no associated item named `A` found for type `Foo` in the current scope
 --> <source>:5:9
  |
5 |         Self::A
  |         ^^^^^^^
error: aborting due to previous error
Compiler returned: 101
@glandium
Copy link
Contributor Author

glandium commented Mar 5, 2018

This is known to not work (I don't know if it's on file or not, but will report separately)

Found it in issue #26264. Which means it's been pending for very long, and the error should be changed rather than wait some more for that to be implemented.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 5, 2018
@TimNN TimNN added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Mar 6, 2018
@estebank
Copy link
Contributor

Current error:

error: enum variants on type aliases are experimental
 --> src/lib.rs:5:9
  |
5 |         Self::A
  |         ^^^^^^^
  |
  = help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable

Duplicate of #56104 and #52118

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 C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants