-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-tytype system / type inference / traits / method resolutiontype system / type inference / traits / method resolutionC-bugCategory: bugCategory: bug
Description
rust-analyzer version: 9700add 2022-01-17 stable
rustc version: rustc 1.60.0-nightly (9ad5d82f8 2022-01-18)
relevant settings: Enabled #![feature(generic_associated_types)]
I've spotted a bug where rust analyzer does not correctly infer some types when generic associated types are involved. I've managed to trim down my example to the following minimal snippet:
pub trait Context {
type QueryResult<Q> : Iterator<Item=Q>;
fn query<Q>(&self) -> Self::QueryResult<Q>;
}
pub fn test(ctx: impl Context) {
for x in ctx.query::<&i32>() { // <--- Here
}
}
The type for x
in the loop is inferred as Context
, when it should be i32. If I shadow x
to itself, rustc compiles this code just fine, but the outer x
is still inferred incorrectly.
pub fn test(ctx: impl Context) {
for x in ctx.query::<&i32>() {
let x : i32 = x; // <--- New
}
}
If the type is something more complex, like a tuple, the type can no longer be inferred and is simply reported as {unknown}
pub fn test(ctx: impl Context) {
for (x, y) in ctx.query::<(&i32, &i32)>() {
// x and y reported as { unknown }
}
}
SohumB
Metadata
Metadata
Assignees
Labels
A-tytype system / type inference / traits / method resolutiontype system / type inference / traits / method resolutionC-bugCategory: bugCategory: bug
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
flodiebold commentedon Mar 18, 2022
Generic associated types aren't implemented yet.
setzer22 commentedon Mar 18, 2022
Yes, I just had used GATs unknowingly (the feature is active in my project), then thought it was due to a bug in RA, that's why I originally reported this as a bug.
I understand RA limiting itself to the stable subset of features, but generic associated types are pretty close to stabilization, so I still felt it was worth reporting.
flodiebold commentedon Mar 18, 2022
Not necessarily, there's just a lot to do 🙂
lowr commentedon Oct 29, 2022
GATs have been implmeneted in #13494. Manually tested and confirmed we can now correctly infer the variables in OP.
setzer22 commentedon Oct 30, 2022
Exciting! 🎉