Skip to content

Commit 7e86c8e

Browse files
authored
Rollup merge of #74751 - GuillaumeGomez:cleanup-e0730, r=jyn514
Clean up E0730 explanation r? @Dylan-DPC
2 parents 6b09c37 + 89e4fe3 commit 7e86c8e

File tree

1 file changed

+21
-7
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+21
-7
lines changed
+21-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
An 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
```

0 commit comments

Comments
 (0)