@@ -7,7 +7,7 @@ use clippy_utils::{
77} ;
88use rustc_ast:: ast:: LitKind ;
99use rustc_errors:: Applicability ;
10- use rustc_hir:: { BinOpKind , Expr , ExprKind , UnOp } ;
10+ use rustc_hir:: { BinOpKind , Expr , ExprKind } ;
1111use rustc_lint:: { LateContext , LateLintPass } ;
1212use rustc_session:: declare_lint_pass;
1313use rustc_span:: Span ;
@@ -293,30 +293,6 @@ impl<'tcx> LateLintPass<'tcx> for BoolComparison {
293293 }
294294}
295295
296- struct ExpressionInfoWithSpan {
297- one_side_is_unary_not : bool ,
298- left_span : Span ,
299- right_span : Span ,
300- }
301-
302- fn is_unary_not ( e : & Expr < ' _ > ) -> ( bool , Span ) {
303- if let ExprKind :: Unary ( UnOp :: Not , operand) = e. kind {
304- return ( true , operand. span ) ;
305- }
306- ( false , e. span )
307- }
308-
309- fn one_side_is_unary_not < ' tcx > ( left_side : & ' tcx Expr < ' _ > , right_side : & ' tcx Expr < ' _ > ) -> ExpressionInfoWithSpan {
310- let left = is_unary_not ( left_side) ;
311- let right = is_unary_not ( right_side) ;
312-
313- ExpressionInfoWithSpan {
314- one_side_is_unary_not : left. 0 != right. 0 ,
315- left_span : left. 1 ,
316- right_span : right. 1 ,
317- }
318- }
319-
320296fn check_comparison < ' a , ' tcx > (
321297 cx : & LateContext < ' tcx > ,
322298 e : & ' tcx Expr < ' _ > ,
@@ -326,41 +302,12 @@ fn check_comparison<'a, 'tcx>(
326302 right_false : Option < ( impl FnOnce ( Sugg < ' a > ) -> Sugg < ' a > , & ' static str ) > ,
327303 no_literal : Option < ( impl FnOnce ( Sugg < ' a > , Sugg < ' a > ) -> Sugg < ' a > , & ' static str ) > ,
328304) {
329- if let ExprKind :: Binary ( op , left_side, right_side) = e. kind {
305+ if let ExprKind :: Binary ( _ , left_side, right_side) = e. kind {
330306 let mut applicability = Applicability :: MachineApplicable ;
331307 // Eliminate parentheses in `e` by using the lo pos of lhs and hi pos of rhs,
332308 // calling `source_callsite` make sure macros are handled correctly, see issue #9907
333309 let binop_span = left_side. span . source_callsite ( ) . to ( right_side. span . source_callsite ( ) ) ;
334310
335- if op. node == BinOpKind :: Eq {
336- let expression_info = one_side_is_unary_not ( left_side, right_side) ;
337- if expression_info. one_side_is_unary_not {
338- span_lint_and_sugg (
339- cx,
340- BOOL_COMPARISON ,
341- binop_span,
342- "this comparison might be written more concisely" ,
343- "try simplifying it" ,
344- format ! (
345- "{} != {}" ,
346- snippet_with_applicability(
347- cx,
348- expression_info. left_span. source_callsite( ) ,
349- ".." ,
350- & mut applicability
351- ) ,
352- snippet_with_applicability(
353- cx,
354- expression_info. right_span. source_callsite( ) ,
355- ".." ,
356- & mut applicability
357- )
358- ) ,
359- applicability,
360- ) ;
361- }
362- }
363-
364311 match ( fetch_bool_expr ( left_side) , fetch_bool_expr ( right_side) ) {
365312 ( Some ( true ) , None ) => left_true. map_or ( ( ) , |( h, m) | {
366313 suggest_bool_comparison ( cx, binop_span, right_side, applicability, m, h) ;
0 commit comments