Skip to content

Commit 3f24cdf

Browse files
authored
Merge pull request #3490 from phansch/extract_single_match_else_ui_test
Extract single_match_else UI test
2 parents 68bb900 + 3f72d4d commit 3f24cdf

File tree

5 files changed

+176
-157
lines changed

5 files changed

+176
-157
lines changed

clippy_lints/src/matches.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,37 @@ declare_clippy_lint! {
4545
"a match statement with a single nontrivial arm (i.e. where the other arm is `_ => {}`) instead of `if let`"
4646
}
4747

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
4949
/// usually suffice.
5050
///
5151
/// **Why is this bad?** Just readability – `if let` nests less than a `match`.
5252
///
5353
/// **Known problems:** Personal style preferences may differ.
5454
///
5555
/// **Example:**
56+
///
57+
/// Using `match`:
58+
///
5659
/// ```rust
5760
/// match x {
5861
/// Some(ref foo) => bar(foo),
5962
/// _ => bar(other_ref),
6063
/// }
6164
/// ```
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+
/// ```
6275
declare_clippy_lint! {
6376
pub SINGLE_MATCH_ELSE,
6477
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"
6679
}
6780

6881
/// **What it does:** Checks for matches where all arms match a reference,

tests/ui/matches.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,12 @@
1414

1515
#![warn(clippy::all)]
1616
#![allow(unused, clippy::redundant_pattern_matching)]
17-
#![warn(clippy::single_match_else, clippy::match_same_arms)]
17+
#![warn(clippy::match_same_arms)]
1818

19-
enum ExprNode {
20-
ExprAddrOf,
21-
Butterflies,
22-
Unicorns,
23-
}
24-
25-
static NODE: ExprNode = ExprNode::Unicorns;
2619

2720
fn dummy() {
2821
}
2922

30-
fn unwrap_addr() -> Option<&'static ExprNode> {
31-
match ExprNode::Butterflies {
32-
ExprNode::ExprAddrOf => Some(&NODE),
33-
_ => { let x = 5; None },
34-
}
35-
}
36-
3723
fn ref_pats() {
3824
{
3925
let v = &Some(0);

0 commit comments

Comments
 (0)