mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Use both pair orders.
This commit is contained in:
parent
67aeb2eaeb
commit
14d5013314
1 changed files with 19 additions and 18 deletions
|
@ -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()
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue