diff options
| author | cookie-s <kcz@kcz.sh> | 2024-05-24 20:34:29 -0400 |
|---|---|---|
| committer | cookie-s <kcz@kcz.sh> | 2024-05-24 22:30:24 -0400 |
| commit | b6350e94f7cf3f16caaf163e5406fd77c1cbd070 (patch) | |
| tree | dfcefb6f3cd13add7d57f9d5af39d4d3484dece9 | |
| parent | 93a77f2812ae80fda57003a6877d09de7793541e (diff) | |
| download | rust-b6350e94f7cf3f16caaf163e5406fd77c1cbd070.tar.gz rust-b6350e94f7cf3f16caaf163e5406fd77c1cbd070.zip | |
[`nonminimal_bool`]: Remove NotSimplificationVisitor
| -rw-r--r-- | clippy_lints/src/booleans.rs | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 61e90167d81..b52d8f454ae 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -174,6 +174,25 @@ fn check_inverted_bool_in_condition( ); } +fn check_simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) { + if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind + && !expr.span.from_expansion() + && !inner.span.from_expansion() + && let Some(suggestion) = simplify_not(cx, inner) + && cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow + { + span_lint_and_sugg( + cx, + NONMINIMAL_BOOL, + expr.span, + "this boolean expression can be simplified", + "try", + suggestion, + Applicability::MachineApplicable, + ); + } +} + struct NonminimalBoolVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, } @@ -542,8 +561,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { } }; if improvements.is_empty() { - let mut visitor = NotSimplificationVisitor { cx: self.cx }; - visitor.visit_expr(e); + check_simplify_not(self.cx, e); } else { nonminimal_bool_lint( improvements @@ -586,28 +604,3 @@ fn implements_ord(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { .get_diagnostic_item(sym::Ord) .map_or(false, |id| implements_trait(cx, ty, id, &[])) } - -struct NotSimplificationVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind - && !expr.span.from_expansion() - && !inner.span.from_expansion() - && let Some(suggestion) = simplify_not(self.cx, inner) - && self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow - { - span_lint_and_sugg( - self.cx, - NONMINIMAL_BOOL, - expr.span, - "this boolean expression can be simplified", - "try", - suggestion, - Applicability::MachineApplicable, - ); - } - } -} |
