]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0730.md
803a25148651c6753c860be20694c4f5eb80a2a0
[rust.git] / src / librustc_error_codes / error_codes / E0730.md
1 An array without a fixed length was pattern-matched.
2
3 Example of erroneous code:
4
5 ```compile_fail,E0730
6 #![feature(const_generics)]
7
8 fn is_123<const N: usize>(x: [u32; N]) -> bool {
9     match x {
10         [1, 2, 3] => true, // error: cannot pattern-match on an
11                            //        array without a fixed length
12         _ => false
13     }
14 }
15 ```
16
17 Ensure that the pattern is consistent with the size of the matched
18 array. Additional elements can be matched with `..`:
19
20 ```
21 #![feature(slice_patterns)]
22
23 let r = &[1, 2, 3, 4];
24 match r {
25     &[a, b, ..] => { // ok!
26         println!("a={}, b={}", a, b);
27     }
28 }
29 ```