Skip to content

Associated type incorrectly annotated with generic syntax #6191

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
cole-miller opened this issue Oct 9, 2020 · 3 comments · Fixed by #6387
Closed

Associated type incorrectly annotated with generic syntax #6191

cole-miller opened this issue Oct 9, 2020 · 3 comments · Fixed by #6387
Labels
A-ty type system / type inference / traits / method resolution E-easy E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now

Comments

@cole-miller
Copy link

cole-miller commented Oct 9, 2020

First of all, thanks for a very useful tool!

When I edit the following code:

pub trait Foo {
    type Bar: Default;
}

pub fn quux<T: Foo>() -> T::Bar {
    let y = Default::default();

    y
}

rust-analyzer annotates y with the nonsensical type Foo::Bar<T>, instead of the correct <T as Foo>::Bar. Clicking to insert this annotation results in a compilation error as expected (E0223).

I'm using Visual Studio Code 1.47.2 with version 0.2.336 of the rust-analyzer plugin (installed from the marketplace) and the latest stable rustc. I have not installed the official Rust plugin.

@flodiebold
Copy link
Member

flodiebold commented Oct 9, 2020

Foo::Bar<T> is how RA and Chalk internally represent the placeholder type that gets used when the projection <T as Foo>::Bar can't be normalized to any concrete type. The problem here is that the code that displays the type hints wasn't originally intended to produce actual syntax, rather to accurately represent each type. We could special case the code here to print a projection if f.display_target.is_source_code(), though long-term my idea is to do this by turning the Ty back into a HIR that's closer to actual source code.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution E-easy E-has-instructions Issue has some instructions and pointers to code to get started labels Oct 9, 2020
@lnicola
Copy link
Member

lnicola commented Oct 9, 2020

CC #5003 (comment)

@bnjjj
Copy link
Contributor

bnjjj commented Oct 10, 2020

I will try to resolve this issue if you don't mind, as there is some instructions thanks to @flodiebold and I haven't already explore this part of the codebase

@matklad matklad added the S-actionable Someone could pick this issue up and work on it right now label Oct 14, 2020
bnjjj added a commit to bnjjj/rust-analyzer that referenced this issue Oct 27, 2020
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bors bors bot closed this as completed in e341832 Oct 28, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-ty type system / type inference / traits / method resolution E-easy E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants