Skip to content

diagnostics: suggest "Self::" on missing type not found in trait definition #62650

Closed
@matthiaskrgr

Description

@matthiaskrgr
trait A {
    type Bla;
    fn to_bla(&self) -> Bla;
}

yields

error[E0412]: cannot find type `Bla` in this scope
 --> src/main.rs:3:25
  |
3 |     fn to_bla(&self) -> Bla;
  |                         ^^^ not found in this scope

error: aborting due to previous error

it would be helpful to suggest to change the to_bla return type to Self::Bla; which fixes the error:

trait A {
    type Bla;
    fn to_bla(&self) -> Self::Bla;
}

fn main() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions