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

No type inference for slice patterns #3043

Closed
jplatte opened this issue Feb 7, 2020 · 2 comments · Fixed by #3062 or #3387
Closed

No type inference for slice patterns #3043

jplatte opened this issue Feb 7, 2020 · 2 comments · Fixed by #3062 or #3387
Labels
A-ty type system / type inference / traits / method resolution E-has-instructions Issue has some instructions and pointers to code to get started E-medium

Comments

@jplatte
Copy link
Contributor

jplatte commented Feb 7, 2020

Minimal reproduction:

let xs: &[f64] = &[0.0];
match xs {
    &[x] => {
        x; // {unknown}
    }
    _ => {}
}
@flodiebold flodiebold added the A-ty type system / type inference / traits / method resolution label Feb 7, 2020
@flodiebold
Copy link
Member

We already have a Pat::SlicePat variant, so the first step would be implementing lowering from AST to hir_def::expr::Pat here. After that, we need to implement the actual inference here; basically, check whether the expected type is a slice, then recursively call infer_pat on the parts (for the prefix and suffix patterns, the expected type should be the element type; for the rest pattern, it'll be the slice type itself.) It's a bit similar to tuple patterns, which are implemented a bit further up:
https://github.com/rust-analyzer/rust-analyzer/blob/5397f05bfe7f3b18229a65040c6685e762b2f9a3/crates/ra_hir_ty/src/infer/pat.rs#L115-L129

@flodiebold flodiebold added E-medium E-has-instructions Issue has some instructions and pointers to code to get started labels Feb 7, 2020
@bors bors bot closed this as completed in 759100f Feb 11, 2020
@jplatte
Copy link
Contributor Author

jplatte commented Feb 11, 2020

Forgot to remove the 'will fix' from the PR. Can't reopen the issue though.

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 E-has-instructions Issue has some instructions and pointers to code to get started E-medium
Projects
None yet
2 participants