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

"cannot find associated type" could hint existing associated types #87638

Closed
oli-obk opened this issue Jul 30, 2021 · 1 comment · Fixed by #87775
Closed

"cannot find associated type" could hint existing associated types #87638

oli-obk opened this issue Jul 30, 2021 · 1 comment · Fixed by #87775
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jul 30, 2021

The following error gives no hints for resolving it, even though there is an obvious solution, in this case the only existing associated type of std::ops::Deref.

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=976e4a98c62d7a0efb2d0d6325774495

fn main() {
    let s : <String as std::ops::Deref>::Output = "hey";
}

The current output is:

error[E0576]: cannot find associated type `Output` in trait `std::ops::Deref`
 --> src/main.rs:2:42
  |
2 |     let s : <String as std::ops::Deref>::Output = "hey";
  |                                          ^^^^^^ not found in `std::ops::Deref`

For more information about this error, try `rustc --explain E0576`.

Ideally the output should look like:

error[E0576]: cannot find associated type `Output` in trait `std::ops::Deref`
 --> src/main.rs:2:42
  |
2 |     let s : <String as std::ops::Deref>::Output = "hey";
  |                                          ^^^^^^ not found in `std::ops::Deref`

note: Did you mean `Target`?

For more information about this error, try `rustc --explain E0576`.
@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 30, 2021
@Kobzol
Copy link
Contributor

Kobzol commented Aug 4, 2021

@rustbot claim

I'd like to take a shot at this. I suppose that the note should only be shown if there is exactly a single associated type in the trait? (or a single constant/function, depending on the namespace).

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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants