Skip to content

Commit

Permalink
Merge pull request #3490 from phansch/extract_single_match_else_ui_test
Browse files Browse the repository at this point in the history
Extract single_match_else UI test
  • Loading branch information
flip1995 authored Dec 4, 2018
2 parents 68bb900 + 3f72d4d commit 3f24cdf
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 157 deletions.
17 changes: 15 additions & 2 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,37 @@ declare_clippy_lint! {
"a match statement with a single nontrivial arm (i.e. where the other arm is `_ => {}`) instead of `if let`"
}

/// **What it does:** Checks for matches with a two arms where an `if let` will
/// **What it does:** Checks for matches with a two arms where an `if let else` will
/// usually suffice.
///
/// **Why is this bad?** Just readability – `if let` nests less than a `match`.
///
/// **Known problems:** Personal style preferences may differ.
///
/// **Example:**
///
/// Using `match`:
///
/// ```rust
/// match x {
/// Some(ref foo) => bar(foo),
/// _ => bar(other_ref),
/// }
/// ```
///
/// Using `if let` with `else`:
///
/// ```rust
/// if let Some(ref foo) = x {
/// bar(foo);
/// } else {
/// bar(other_ref);
/// }
/// ```
declare_clippy_lint! {
pub SINGLE_MATCH_ELSE,
pedantic,
"a match statement with a two arms where the second arm's pattern is a wildcard instead of `if let`"
"a match statement with a two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
}

/// **What it does:** Checks for matches where all arms match a reference,
Expand Down
16 changes: 1 addition & 15 deletions tests/ui/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,12 @@

#![warn(clippy::all)]
#![allow(unused, clippy::redundant_pattern_matching)]
#![warn(clippy::single_match_else, clippy::match_same_arms)]
#![warn(clippy::match_same_arms)]

enum ExprNode {
ExprAddrOf,
Butterflies,
Unicorns,
}

static NODE: ExprNode = ExprNode::Unicorns;

fn dummy() {
}

fn unwrap_addr() -> Option<&'static ExprNode> {
match ExprNode::Butterflies {
ExprNode::ExprAddrOf => Some(&NODE),
_ => { let x = 5; None },
}
}

fn ref_pats() {
{
let v = &Some(0);
Expand Down
Loading

0 comments on commit 3f24cdf

Please sign in to comment.