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

Improve error message when using Self in impl enum #56104

Closed
0xrgb opened this issue Nov 20, 2018 · 3 comments
Closed

Improve error message when using Self in impl enum #56104

0xrgb opened this issue Nov 20, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution

Comments

@0xrgb
Copy link
Contributor

0xrgb commented Nov 20, 2018

#[derive(Debug)]
enum MainError {
    IO(std::io::Error),
    Parse(std::num::ParseIntError),
}

impl From<std::io::Error> for MainError {
    fn from(e: std::io::Error) -> Self {
        Self::IO(e)
    }
}

impl From<std::num::ParseIntError> for MainError {
    fn from(e: std::num::ParseIntError) -> Self {
        Self::Parse(e)
    }
}

Compiling above code give errors,

error[E0599]: no variant named `IO` found for type `MainError` in the current scope
  --> src\main.rs:12:9
   |
5  | enum MainError {
   | -------------- variant `IO` not found here
...
12 |         Self::IO(e)
   |         ^^^^^^^^ variant not found in `MainError`
   |
   = note: did you mean `MainError::IO`?

The error message is helpful (it indicates correct code, MainError::IO). However, the first line of message is confusing, and E0599 does not help much to understand why this code is not working.

Can we improve error messages for such situations?

@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 21, 2018
@csmoe
Copy link
Member

csmoe commented Nov 21, 2018

enum variants through Self is not allowed right now
cc #51994 (comment)
@Centril is there any plan to make it possible?

@Centril
Copy link
Contributor

Centril commented Nov 21, 2018

@csmoe Yes; Self::Variant(...) should become legal eventually but this is #49683.

@estebank
Copy link
Contributor

Current output:

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

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

Duplicate of #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 A-resolve Area: Name resolution
Projects
None yet
Development

No branches or pull requests

4 participants