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 1 commit into from Dec 4, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+176 −157
Diff settings

Always

Just for now

Copy path View file
@@ -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,
Copy path View file
@@ -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);
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.