File tree 5 files changed +176
-157
lines changed
5 files changed +176
-157
lines changed Original file line number Diff line number Diff line change @@ -45,24 +45,37 @@ declare_clippy_lint! {
45
45
"a match statement with a single nontrivial arm (i.e. where the other arm is `_ => {}`) instead of `if let`"
46
46
}
47
47
48
- /// **What it does:** Checks for matches with a two arms where an `if let` will
48
+ /// **What it does:** Checks for matches with a two arms where an `if let else ` will
49
49
/// usually suffice.
50
50
///
51
51
/// **Why is this bad?** Just readability – `if let` nests less than a `match`.
52
52
///
53
53
/// **Known problems:** Personal style preferences may differ.
54
54
///
55
55
/// **Example:**
56
+ ///
57
+ /// Using `match`:
58
+ ///
56
59
/// ```rust
57
60
/// match x {
58
61
/// Some(ref foo) => bar(foo),
59
62
/// _ => bar(other_ref),
60
63
/// }
61
64
/// ```
65
+ ///
66
+ /// Using `if let` with `else`:
67
+ ///
68
+ /// ```rust
69
+ /// if let Some(ref foo) = x {
70
+ /// bar(foo);
71
+ /// } else {
72
+ /// bar(other_ref);
73
+ /// }
74
+ /// ```
62
75
declare_clippy_lint ! {
63
76
pub SINGLE_MATCH_ELSE ,
64
77
pedantic,
65
- "a match statement with a two arms where the second arm's pattern is a wildcard instead of `if let` "
78
+ "a match statement with a two arms where the second arm's pattern is a placeholder instead of a specific match pattern "
66
79
}
67
80
68
81
/// **What it does:** Checks for matches where all arms match a reference,
Original file line number Diff line number Diff line change 14
14
15
15
#![ warn( clippy:: all) ]
16
16
#![ allow( unused, clippy:: redundant_pattern_matching) ]
17
- #![ warn( clippy:: single_match_else , clippy :: match_same_arms) ]
17
+ #![ warn( clippy:: match_same_arms) ]
18
18
19
- enum ExprNode {
20
- ExprAddrOf ,
21
- Butterflies ,
22
- Unicorns ,
23
- }
24
-
25
- static NODE : ExprNode = ExprNode :: Unicorns ;
26
19
27
20
fn dummy ( ) {
28
21
}
29
22
30
- fn unwrap_addr ( ) -> Option < & ' static ExprNode > {
31
- match ExprNode :: Butterflies {
32
- ExprNode :: ExprAddrOf => Some ( & NODE ) ,
33
- _ => { let x = 5 ; None } ,
34
- }
35
- }
36
-
37
23
fn ref_pats ( ) {
38
24
{
39
25
let v = & Some ( 0 ) ;
You can’t perform that action at this time.
0 commit comments