-
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