11use clippy_utils:: consts:: { constant_full_int, constant_simple, Constant , FullInt } ;
22use clippy_utils:: diagnostics:: span_lint_and_sugg;
33use clippy_utils:: source:: snippet_with_applicability;
4- use clippy_utils:: { clip, unsext} ;
4+ use clippy_utils:: { clip, peel_hir_expr_refs , unsext} ;
55use rustc_errors:: Applicability ;
66use rustc_hir:: { BinOpKind , Expr , ExprKind , Node } ;
77use rustc_lint:: LateContext ;
@@ -20,20 +20,76 @@ pub(crate) fn check<'tcx>(
2020 if !is_allowed ( cx, op, left, right) {
2121 match op {
2222 BinOpKind :: Add | BinOpKind :: BitOr | BinOpKind :: BitXor => {
23- check_op ( cx, left, 0 , expr. span , right. span , needs_parenthesis ( cx, expr, right) ) ;
24- check_op ( cx, right, 0 , expr. span , left. span , Parens :: Unneeded ) ;
23+ check_op (
24+ cx,
25+ left,
26+ 0 ,
27+ expr. span ,
28+ peel_hir_expr_refs ( right) . 0 . span ,
29+ needs_parenthesis ( cx, expr, right) ,
30+ ) ;
31+ check_op (
32+ cx,
33+ right,
34+ 0 ,
35+ expr. span ,
36+ peel_hir_expr_refs ( left) . 0 . span ,
37+ Parens :: Unneeded ,
38+ ) ;
2539 } ,
2640 BinOpKind :: Shl | BinOpKind :: Shr | BinOpKind :: Sub => {
27- check_op ( cx, right, 0 , expr. span , left. span , Parens :: Unneeded ) ;
41+ check_op (
42+ cx,
43+ right,
44+ 0 ,
45+ expr. span ,
46+ peel_hir_expr_refs ( left) . 0 . span ,
47+ Parens :: Unneeded ,
48+ ) ;
2849 } ,
2950 BinOpKind :: Mul => {
30- check_op ( cx, left, 1 , expr. span , right. span , needs_parenthesis ( cx, expr, right) ) ;
31- check_op ( cx, right, 1 , expr. span , left. span , Parens :: Unneeded ) ;
51+ check_op (
52+ cx,
53+ left,
54+ 1 ,
55+ expr. span ,
56+ peel_hir_expr_refs ( right) . 0 . span ,
57+ needs_parenthesis ( cx, expr, right) ,
58+ ) ;
59+ check_op (
60+ cx,
61+ right,
62+ 1 ,
63+ expr. span ,
64+ peel_hir_expr_refs ( left) . 0 . span ,
65+ Parens :: Unneeded ,
66+ ) ;
3267 } ,
33- BinOpKind :: Div => check_op ( cx, right, 1 , expr. span , left. span , Parens :: Unneeded ) ,
68+ BinOpKind :: Div => check_op (
69+ cx,
70+ right,
71+ 1 ,
72+ expr. span ,
73+ peel_hir_expr_refs ( left) . 0 . span ,
74+ Parens :: Unneeded ,
75+ ) ,
3476 BinOpKind :: BitAnd => {
35- check_op ( cx, left, -1 , expr. span , right. span , needs_parenthesis ( cx, expr, right) ) ;
36- check_op ( cx, right, -1 , expr. span , left. span , Parens :: Unneeded ) ;
77+ check_op (
78+ cx,
79+ left,
80+ -1 ,
81+ expr. span ,
82+ peel_hir_expr_refs ( right) . 0 . span ,
83+ needs_parenthesis ( cx, expr, right) ,
84+ ) ;
85+ check_op (
86+ cx,
87+ right,
88+ -1 ,
89+ expr. span ,
90+ peel_hir_expr_refs ( left) . 0 . span ,
91+ Parens :: Unneeded ,
92+ ) ;
3793 } ,
3894 BinOpKind :: Rem => check_remainder ( cx, left, right, expr. span , left. span ) ,
3995 _ => ( ) ,
0 commit comments