@@ -174,6 +174,25 @@ fn check_inverted_bool_in_condition(
174
174
) ;
175
175
}
176
176
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
+
177
196
struct NonminimalBoolVisitor < ' a , ' tcx > {
178
197
cx : & ' a LateContext < ' tcx > ,
179
198
}
@@ -542,8 +561,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
542
561
}
543
562
} ;
544
563
if improvements. is_empty ( ) {
545
- let mut visitor = NotSimplificationVisitor { cx : self . cx } ;
546
- visitor. visit_expr ( e) ;
564
+ check_simplify_not ( self . cx , e) ;
547
565
} else {
548
566
nonminimal_bool_lint (
549
567
improvements
@@ -586,28 +604,3 @@ fn implements_ord(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
586
604
. get_diagnostic_item ( sym:: Ord )
587
605
. map_or ( false , |id| implements_trait ( cx, ty, id, & [ ] ) )
588
606
}
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