]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0730.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0730.md
1 An array without a fixed length was pattern-matched.
2
3 Erroneous code example:
4
5 ```compile_fail,E0730
6 fn is_123<const N: usize>(x: [u32; N]) -> bool {
7     match x {
8         [1, 2, ..] => true, // error: cannot pattern-match on an
9                             //        array without a fixed length
10         _ => false
11     }
12 }
13 ```
14
15 To fix this error, you have two solutions:
16  1. Use an array with a fixed length.
17  2. Use a slice.
18
19 Example with an array with a fixed length:
20
21 ```
22 fn is_123(x: [u32; 3]) -> bool { // We use an array with a fixed size
23     match x {
24         [1, 2, ..] => true, // ok!
25         _ => false
26     }
27 }
28 ```
29
30 Example with a slice:
31
32 ```
33 fn is_123(x: &[u32]) -> bool { // We use a slice
34     match x {
35         [1, 2, ..] => true, // ok!
36         _ => false
37     }
38 }
39 ```