Skip to content

Commit b6350e9

Browse files
committed
[nonminimal_bool]: Remove NotSimplificationVisitor
1 parent 93a77f2 commit b6350e9

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

clippy_lints/src/booleans.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,25 @@ fn check_inverted_bool_in_condition(
174174
);
175175
}
176176

177+
fn check_simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) {
178+
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind
179+
&& !expr.span.from_expansion()
180+
&& !inner.span.from_expansion()
181+
&& let Some(suggestion) = simplify_not(cx, inner)
182+
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
183+
{
184+
span_lint_and_sugg(
185+
cx,
186+
NONMINIMAL_BOOL,
187+
expr.span,
188+
"this boolean expression can be simplified",
189+
"try",
190+
suggestion,
191+
Applicability::MachineApplicable,
192+
);
193+
}
194+
}
195+
177196
struct NonminimalBoolVisitor<'a, 'tcx> {
178197
cx: &'a LateContext<'tcx>,
179198
}
@@ -542,8 +561,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
542561
}
543562
};
544563
if improvements.is_empty() {
545-
let mut visitor = NotSimplificationVisitor { cx: self.cx };
546-
visitor.visit_expr(e);
564+
check_simplify_not(self.cx, e);
547565
} else {
548566
nonminimal_bool_lint(
549567
improvements
@@ -586,28 +604,3 @@ fn implements_ord(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
586604
.get_diagnostic_item(sym::Ord)
587605
.map_or(false, |id| implements_trait(cx, ty, id, &[]))
588606
}
589-
590-
struct NotSimplificationVisitor<'a, 'tcx> {
591-
cx: &'a LateContext<'tcx>,
592-
}
593-
594-
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
595-
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
596-
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind
597-
&& !expr.span.from_expansion()
598-
&& !inner.span.from_expansion()
599-
&& let Some(suggestion) = simplify_not(self.cx, inner)
600-
&& self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
601-
{
602-
span_lint_and_sugg(
603-
self.cx,
604-
NONMINIMAL_BOOL,
605-
expr.span,
606-
"this boolean expression can be simplified",
607-
"try",
608-
suggestion,
609-
Applicability::MachineApplicable,
610-
);
611-
}
612-
}
613-
}

0 commit comments

Comments
 (0)