Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

False positive E0308 with &[&dyn T] inference #15507

Closed
mladedav opened this issue Aug 23, 2023 · 3 comments
Closed

False positive E0308 with &[&dyn T] inference #15507

mladedav opened this issue Aug 23, 2023 · 3 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@mladedav
Copy link
Contributor

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)

@mladedav mladedav added the C-bug Category: bug label Aug 23, 2023
@lnicola
Copy link
Member

lnicola commented Aug 24, 2023

I suspect this is #11847 again.

@lnicola lnicola added the A-ty type system / type inference / traits / method resolution label Aug 24, 2023
@mladedav
Copy link
Contributor Author

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?

@Veykril
Copy link
Member

Veykril commented Aug 29, 2023

Yes I think this is a dupe of that issue

@Veykril Veykril closed this as not planned Won't fix, can't repro, duplicate, stale Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants