]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0730.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0730.md
CommitLineData
60c5eb7d
XL
1An array without a fixed length was pattern-matched.
2
3dfed10e 3Erroneous code example:
60c5eb7d
XL
4
5```compile_fail,E0730
6#![feature(const_generics)]
7
8fn is_123<const N: usize>(x: [u32; N]) -> bool {
9 match x {
ba9703b0
XL
10 [1, 2, ..] => true, // error: cannot pattern-match on an
11 // array without a fixed length
60c5eb7d
XL
12 _ => false
13 }
14}
15```
16
3dfed10e
XL
17To fix this error, you have two solutions:
18 1. Use an array with a fixed length.
19 2. Use a slice.
60c5eb7d 20
3dfed10e
XL
21Example with an array with a fixed length:
22
23```
24fn is_123(x: [u32; 3]) -> bool { // We use an array with a fixed size
25 match x {
26 [1, 2, ..] => true, // ok!
27 _ => false
28 }
29}
60c5eb7d 30```
3dfed10e
XL
31
32Example with a slice:
33
34```
35fn is_123(x: &[u32]) -> bool { // We use a slice
36 match x {
37 [1, 2, ..] => true, // ok!
38 _ => false
60c5eb7d
XL
39 }
40}
41```