File tree Expand file tree Collapse file tree 1 file changed +21
-7
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change 11An array without a fixed length was pattern-matched.
22
3- Example of erroneous code:
3+ Erroneous code example :
44
55``` compile_fail,E0730
66#![feature(const_generics)]
@@ -14,14 +14,28 @@ fn is_123<const N: usize>(x: [u32; N]) -> bool {
1414}
1515```
1616
17- Ensure that the pattern is consistent with the size of the matched
18- array. Additional elements can be matched with ` .. ` :
17+ To fix this error, you have two solutions:
18+ 1 . Use an array with a fixed length.
19+ 2 . Use a slice.
1920
21+ Example with an array with a fixed length:
22+
23+ ```
24+ fn 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+ }
2030```
21- let r = &[1, 2, 3, 4];
22- match r {
23- &[a, b, ..] => { // ok!
24- println!("a={}, b={}", a, b);
31+
32+ Example with a slice:
33+
34+ ```
35+ fn is_123(x: &[u32]) -> bool { // We use a slice
36+ match x {
37+ [1, 2, ..] => true, // ok!
38+ _ => false
2539 }
2640}
2741```
You can’t perform that action at this time.
0 commit comments