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

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

Open
zachs18 opened this issue Mar 3, 2025 · 1 comment
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request

Comments

@zachs18
Copy link
Contributor

zachs18 commented Mar 3, 2025

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

@zachs18 zachs18 added the C-feature Category: feature request label Mar 3, 2025
@ChayimFriedman2
Copy link
Contributor

The error comes from rustc, so we can't (at least easily) know that it is implemented for Foo<u32>. Of course it'll be good if rust-analyzer errors could also come with such detailed info, but we're further from that.

@ChayimFriedman2 ChayimFriedman2 added the A-diagnostics diagnostics / error reporting label Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

2 participants