File tree 1 file changed +21
-7
lines changed
src/librustc_error_codes/error_codes
1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change 1
1
An array without a fixed length was pattern-matched.
2
2
3
- Example of erroneous code:
3
+ Erroneous code example :
4
4
5
5
``` compile_fail,E0730
6
6
#![feature(const_generics)]
@@ -14,14 +14,28 @@ fn is_123<const N: usize>(x: [u32; N]) -> bool {
14
14
}
15
15
```
16
16
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.
19
20
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
+ }
20
30
```
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
25
39
}
26
40
}
27
41
```
You can’t perform that action at this time.
0 commit comments