-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Rust-analyzer deduces the wrong type when for a given generic type, there are multiple implementations of a same method with the same signature.
pub struct Wrapper<T>(T);
pub struct Foo<T>(T);
pub struct Bar<T>(T);
impl<T> Wrapper<Foo<T>> {
pub fn new(foo_: T) -> Self {
Wrapper(Foo(foo_))
}
}
impl<T> Wrapper<Bar<T>> {
pub fn new(bar_: T) -> Self {
Wrapper(Bar(bar_))
}
}
fn main() {
let _a = Wrapper::<Foo<f32>>::new(1.0);
let _b = Wrapper::<Bar<f32>>::new(1.0);
}In this example, type of _b is incorreclty deduced to Wrapper::<Foo<f64>> even with the turbofish type hinting.
I can add myself the type of _b, but the argument inlay hint for the new method will still be incorrect (displaying foo_ instead of bar_, and the "Go to definition" functionality will still go the the wrong definition.
It seems that rust-analyzer looks only at the first definition of the new method, even if there are better matches below.
I'm using the latest release of rust-analyzer (2020-02-11) with the latest version of the vscode extension.
I have first encountered this problem when using the method palette::rgb::Srgba::new from the palette crate.
