Skip to content

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

Closed
@oli-obk

Description

@oli-obk
Contributor

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`.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jul 30, 2021
Kobzol

Kobzol commented on Aug 4, 2021

@Kobzol
Member

@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).

added a commit that references this issue on Aug 6, 2021

Rollup merge of rust-lang#87775 - Kobzol:single-associated-item-hint,…

8ee962f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @oli-obk@Kobzol

    Issue actions

      "cannot find associated type" could hint existing associated types · Issue #87638 · rust-lang/rust