Open
Description
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`
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 impl
s that did not previously have this generic but should now have it. Currently this mostly goes like:
- add the generic to an
impl
- see what new errors that causes in that
impl
because code in it is calling methods that are in a not-yet-genericimpl
- Ideally, I could "go-to-defintion" on the red-underlined methods and add the generic to those methods'
impl
s1, but currently I am justctrl-F
ing forfn method_name
to find them that way.
Footnotes
-
or decide not to, and go back and refactor where it was called ↩