Skip to content

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

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

Closed
matthiaskrgr opened this issue Jul 13, 2019 · 1 comment · Fixed by #62669
Closed

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

matthiaskrgr opened this issue Jul 13, 2019 · 1 comment · Fixed by #62669
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`

Comments

@matthiaskrgr
Copy link
Member

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() {}
@matthiaskrgr

This comment has been minimized.

@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 13, 2019
@estebank estebank added A-associated-items Area: Associated items (types, constants & functions) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Jul 13, 2019
bors added a commit that referenced this issue Jul 18, 2019
Suggest assoc type on type not found in trait method definition

Given

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

```
error[E0412]: cannot find type `Bla` in this scope
  --> file.rs:3:25
   |
LL |     fn to_bla(&self) -> Bla;
   |                         ^^^ help: try: `Self::Bla`
```

Fix #62650.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants