use crate::utils::{match_qpath, paths, snippet, span_lint_and_then};
+use rustc::hir::ptr::P;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use syntax::ast::LitKind;
-use syntax::ptr::P;
-use syntax::symbol::Symbol;
declare_clippy_lint! {
/// **What it does:** Lint for redundant pattern matching over `Result` or
let good_method = match arms[0].pats[0].node {
PatKind::TupleStruct(ref path, ref patterns, _) if patterns.len() == 1 => {
if let PatKind::Wild = patterns[0].node {
- if match_qpath(path, &*paths::RESULT_OK) {
+ if match_qpath(path, &paths::RESULT_OK) {
"is_ok()"
- } else if match_qpath(path, &*paths::RESULT_ERR) {
+ } else if match_qpath(path, &paths::RESULT_ERR) {
"is_err()"
- } else if match_qpath(path, &*paths::OPTION_SOME) {
+ } else if match_qpath(path, &paths::OPTION_SOME) {
"is_some()"
} else {
return;
}
},
- PatKind::Path(ref path) if match_qpath(path, &*paths::OPTION_NONE) => "is_none()",
+ PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => "is_none()",
_ => return,
};
db.span_suggestion(
span,
"try this",
- format!("if {}.{}", snippet(cx, op.span, "_"), good_method),
- Applicability::MachineApplicable, // snippet
+ format!("{}.{}", snippet(cx, op.span, "_"), good_method),
+ Applicability::MaybeIncorrect, // snippet
);
},
);
- } else {
- return;
}
}
arms,
path_left,
path_right,
- &*paths::RESULT_OK,
- &*paths::RESULT_ERR,
+ &paths::RESULT_OK,
+ &paths::RESULT_ERR,
"is_ok()",
"is_err()",
)
arms,
path_left,
path_right,
- &*paths::OPTION_SOME,
- &*paths::OPTION_NONE,
+ &paths::OPTION_SOME,
+ &paths::OPTION_NONE,
"is_some()",
"is_none()",
)
span,
"try this",
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
- Applicability::MachineApplicable, // snippet
+ Applicability::MaybeIncorrect, // snippet
);
},
);
}
- } else {
- return;
}
}
arms: &HirVec<Arm>,
path_left: &QPath,
path_right: &QPath,
- expected_left: &[Symbol],
- expected_right: &[Symbol],
+ expected_left: &[&str],
+ expected_right: &[&str],
should_be_left: &'a str,
should_be_right: &'a str,
) -> Option<&'a str> {