Use both pair orders.

This commit is contained in:
laurent 2017-11-10 19:55:15 +00:00
parent 67aeb2eaeb
commit 14d5013314

View file

@ -44,11 +44,10 @@ declare_lint! {
"boolean expressions that contain terminals which can be eliminated"
}
const METHODS_WITH_NEGATION: [(&str, &str); 4] = [
// For each pairs, both orders are considered.
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [
("is_some", "is_none"),
("is_none", "is_some"),
("is_err", "is_ok"),
("is_ok", "is_err"),
];
#[derive(Copy, Clone)]
@ -407,21 +406,23 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
fn handle_method_call_in_not(&mut self, e: &'tcx Expr, inner: &'tcx Expr) {
if let ExprMethodCall(ref path, _, ref args) = inner.node {
if args.len() == 1 {
METHODS_WITH_NEGATION.iter().for_each(|&(method, negation_method)| {
if method == path.name.as_str() {
span_lint_and_then(
self.cx,
NONMINIMAL_BOOL,
e.span,
"this boolean expression can be simplified",
|db| {
db.span_suggestion(
e.span,
"try",
negation_method.to_owned()
);
}
)
METHODS_WITH_NEGATION.iter().for_each(|&(method1, method2)| {
for &(method, negation_method) in &[(method1, method2), (method2, method1)] {
if method == path.name.as_str() {
span_lint_and_then(
self.cx,
NONMINIMAL_BOOL,
e.span,
"this boolean expression can be simplified",
|db| {
db.span_suggestion(
e.span,
"try",
negation_method.to_owned()
);
}
)
}
}
})
}