@@ -22,6 +22,22 @@ matched, one of the preceding patterns will match.
22
22
23
23
This means that perhaps some of the preceding patterns are too general, this one
24
24
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.
25
41
"## ,
26
42
27
43
E0002 : r##"
@@ -31,13 +47,40 @@ it is impossible to create an instance of an empty type, so empty match
31
47
expressions are almost never desired. This error is typically fixed by adding
32
48
one or more cases to the match expression.
33
49
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
+ ```
35
70
"## ,
36
71
37
72
E0003 : r##"
38
73
Not-a-Number (NaN) values cannot be compared for equality and hence can never
39
74
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
+ ```
41
84
"## ,
42
85
43
86
E0004 : r##"
0 commit comments