Skip to content

Allow going-to-definition for methods for "the method was found for" types in E0599 notes #19268

Open
@zachs18

Description

@zachs18

Consider the following code:

struct Foo<T = u32>(T);

impl Foo {
    fn bar(self) {}
}

fn quux<T>(x: Foo<T>) {
    x.bar();
}

Currently, rust-analyzer emits this diagnostic, with no code action available, and gives "no definition found for bar" when doing "Go to definition":

// rust-analyzer diagnostic
no method named `bar` found for struct `Foo<T>` in the current scope
the method was found for
- `Foo`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B0%5D?0#file%3A%2F%2F%2Ftmp%2Fra-example-1%2Fsrc%2Flib.rs)
lib.rs(1, 1): method `bar` not found for this struct

// rustc diagnostic
error[E0599]: no method named `bar` found for struct `Foo<T>` in the current scope
 --> src/lib.rs:8:7
  |
1 | struct Foo<T = u32>(T);
  | ------------------- method `bar` not found for this struct
...
8 |     x.bar();
  |       ^^^ method not found in `Foo<T>`
  |
  = note: the method was found for
          - `Foo`

Image

I think it would be useful if there was a way to "go to definition" of the method for the "the method was found for" type(s) (Foo::<u32>::bar above).

My experience with this diagnostic is that I am adding a generic to a widely-used type, and need to go around and fix the impls that did not previously have this generic but should now have it. Currently this mostly goes like:

  1. add the generic to an impl
  2. see what new errors that causes in that impl because code in it is calling methods that are in a not-yet-generic impl
  3. Ideally, I could "go-to-defintion" on the red-underlined methods and add the generic to those methods' impls1, but currently I am just ctrl-Fing for fn method_name to find them that way.

Footnotes

  1. or decide not to, and go back and refactor where it was called

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsdiagnostics / error reportingC-featureCategory: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions