You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following creates false positives Expected &dyn Trait<i32>, found &&str.
The error is reported only for the first variable _x. If the type is provided or the order is so that the type is known earlier, there are no issues.
Also if I comment out the third impl, no error is reported.
The fact that it works when the whole type is present would seem to point to that there is some issue with inference. On the other hand, the fact that this only happens with the additional item might suggest there is a problem with the type system solver like in this issue.
trait Trait<T> {}
impl<T> Trait<T> for &str {}
impl Trait<i32> for i32 {}
// Third impl
impl<T, U> Trait<T> for &U where U: Trait<T> {}
pub fn f() {
let _x: &[&dyn Trait<_>] = &[&"", &0i32];
// ^^^ Expected &dyn Trait<i32>, found &&str
let _y: &[&dyn Trait<_>] = &[&0i32, &""];
let _z: &[&dyn Trait<i32>] = &[&"", &0i32];
}
rust-analyzer version: 0.4.1633-standalone
rustc version: 1.71.0 (8ede3aae2 2023-07-12)
The text was updated successfully, but these errors were encountered:
Oh, I thought it would be something else since I tried to specify all the numbers with types and because the order of the slice items matters so the inference there sometimes works correctly. The first issue seems to be problematic because the variable type is inferred while here the trait to which the variables are coerced is inferred.
But now that I look again it is pretty similar to the last example there.
I'm not sure though, do you think I should close this as another duplicate of that issue?
The following creates false positives
Expected &dyn Trait<i32>, found &&str
.The error is reported only for the first variable
_x
. If the type is provided or the order is so that the type is known earlier, there are no issues.Also if I comment out the third
impl
, no error is reported.The fact that it works when the whole type is present would seem to point to that there is some issue with inference. On the other hand, the fact that this only happens with the additional item might suggest there is a problem with the type system solver like in this issue.
rust-analyzer version: 0.4.1633-standalone
rustc version: 1.71.0 (8ede3aae2 2023-07-12)
The text was updated successfully, but these errors were encountered: