Skip to content

Confusing diagnostic when use Self::Variant inside an impl #111627

Closed
@fee1-dead

Description

@fee1-dead

I tried this (play):

pub enum Uwu {
    Hi
}

impl Uwu {
    fn a() -> Uwu {
        use Self::Hi;
        Hi
    }
}

Heres the current output:

   Compiling playground v0.0.1 (/playground)
error[E0432]: unresolved import `Self`
 --> src/lib.rs:8:13
  |
8 |         use Self::Hi;
  |             ^^^^ `Self` is only available in impls, traits, and type definitions

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` due to previous error

The label that says "Self is only available in impls" is misleading since it is already in an impl.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions