Skip to content

Commit 89e4fe3

Browse files
Improve E0730 explanation
1 parent 1d2e3ff commit 89e4fe3

File tree

1 file changed

+20
-6
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+20
-6
lines changed

src/librustc_error_codes/error_codes/E0730.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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 array.
18-
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)