Skip to content

Commit 36d8529

Browse files
committed
Improve E0001-E0003
1 parent 8d91bbd commit 36d8529

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/librustc/diagnostics.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ matched, one of the preceding patterns will match.
2222
2323
This means that perhaps some of the preceding patterns are too general, this one
2424
is too specific or the ordering is incorrect.
25+
26+
For example, the following `match` block has too many arms:
27+
28+
```
29+
match foo {
30+
Some(bar) => {/* ... */}
31+
None => {/* ... */}
32+
_ => {/* ... */} // All possible cases have already been handled
33+
}
34+
```
35+
36+
`match` blocks have their patterns matched in order, so, for example, putting
37+
a wildcard arm above a more specific arm will make the latter arm irrelevant.
38+
39+
Ensure the ordering of the match arm is correct and remove any superfluous
40+
checks.
2541
"##,
2642

2743
E0002: r##"
@@ -31,13 +47,40 @@ it is impossible to create an instance of an empty type, so empty match
3147
expressions are almost never desired. This error is typically fixed by adding
3248
one or more cases to the match expression.
3349
34-
An example of an empty type is `enum Empty { }`.
50+
An example of an empty type is `enum Empty { }`. So, the following will work:
51+
52+
```
53+
fn foo(x: Empty) {
54+
match x {
55+
// empty
56+
}
57+
}
58+
59+
```
60+
61+
but this won't:
62+
63+
```
64+
fn foo(x: Option<String>) {
65+
match x {
66+
// empty
67+
}
68+
}
69+
```
3570
"##,
3671

3772
E0003: r##"
3873
Not-a-Number (NaN) values cannot be compared for equality and hence can never
3974
match the input to a match expression. To match against NaN values, you should
40-
instead use the `is_nan` method in a guard, as in: `x if x.is_nan() => ...`
75+
instead use the `is_nan()` method in a guard, like so:
76+
77+
```
78+
match number {
79+
// ...
80+
x if x.is_nan() => { /* ... */ }
81+
// ...
82+
}
83+
```
4184
"##,
4285

4386
E0004: r##"

0 commit comments

Comments
 (0)