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

Inference failure since slice patterns does not serve as type expections #16609

Open
oxalica opened this issue Feb 20, 2024 · 3 comments
Open
Labels
A-pattern pattern handling related things A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@oxalica
Copy link
Contributor

oxalica commented Feb 20, 2024

Types of a and b in this code below cannot be inferred by rust-analyzer, but it compiles fine with rustc.

// edition = "2021"
fn main() {
    let [a, b] = vec![1u32, 2u32].try_into().unwrap();
    //   ^ {unknown}
}

rust-analyzer version: 2024-02-19

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

relevant settings: N/A

@oxalica oxalica added the C-bug Category: bug label Feb 20, 2024
@Young-Flash Young-Flash added the A-ty type system / type inference / traits / method resolution label Feb 20, 2024
@Veykril
Copy link
Member

Veykril commented Feb 28, 2024

Hmm, vec![1u32, 2u32].try_into() has type Result<[{unknown}], <Vec<u32, Global> as TryInto<[{unknown}]>>::Error> here, adding the type ascription let [a, b]: [u32; 2] = vec![1u32, 2u32].try_into().unwrap(); makes us resolve the try_into result correctly though

@oxalica
Copy link
Contributor Author

oxalica commented Feb 29, 2024

adding the type ascription

Yes. But rustc can infer that without explicit type ascription.

Note: specifically, this feature is added since 1.73, in rust-lang/rust#113199

@Veykril
Copy link
Member

Veykril commented Feb 29, 2024

I am aware, I was just trying to reduce the root problem. Oh thanks for that link, would make sense that we are missing that if its such a recent inference feature.

@Veykril Veykril added the A-pattern pattern handling related things label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pattern pattern handling related things A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants