mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-25 11:25:06 +00:00
Auto merge of #113199 - b-naber:slice-pattern-type-inference, r=lcnr
Infer type in irrefutable slice patterns with fixed length as array Fixes https://github.com/rust-lang/rust/issues/76342 In irrefutable slice patterns with a fixed length, we can infer the type as an array type. We now choose to prefer some implementations over others, e.g. in: ``` struct Zeroes; const ARR: [usize; 2] = [0; 2]; const ARR2: [usize; 2] = [2; 2]; impl Into<&'static [usize; 2]> for Zeroes { fn into(self) -> &'static [usize; 2] { &ARR } } impl Into<&'static [usize]> for Zeroes { fn into(self) -> &'static [usize] { &ARR2 } } fn main() { let &[a, b] = Zeroes.into(); } ``` We now prefer the impl candidate `impl Into<&'static [usize; 2]> for Zeroes`, it's not entirely clear to me that this is correct, but given that the slice impl would require a type annotation anyway, this doesn't seem unreasonable. r? `@lcnr`
This commit is contained in:
commit
f777cc5f5c