Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract single_match_else UI test #3490

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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