@@ -9,30 +9,32 @@ use rustc_span::source_map::Spanned;
99
1010use super :: DECIMAL_BITWISE_OPERANDS ;
1111
12- fn check_bitwise_binary_expr ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
13- if let ExprKind :: Binary ( op, left , right ) = & expr . kind
14- && matches ! ( op . node , BinOpKind :: BitAnd | BinOpKind :: BitOr | BinOpKind :: BitXor )
15- {
16- for expr in [ left , right ] {
17- if let ExprKind :: Lit ( lit ) = & expr . kind
18- && is_decimal_number ( cx , lit . span )
19- && ! is_power_of_twoish ( lit)
20- {
21- emit_lint ( cx , lit . span ) ;
22- }
12+ pub ( super ) fn check_binary < ' tcx > ( cx : & LateContext < ' tcx > , op : BinOpKind , left : & ' tcx Expr < ' _ > , right : & ' tcx Expr < ' _ > ) {
13+ if ! matches ! ( op, BinOpKind :: BitAnd | BinOpKind :: BitOr | BinOpKind :: BitXor ) {
14+ return ;
15+ }
16+
17+ for expr in [ left , right ] {
18+ if let ExprKind :: Lit ( lit ) = & expr . kind
19+ && is_decimal_number ( cx , lit. span )
20+ && ! is_power_of_twoish ( lit )
21+ {
22+ emit_lint ( cx , lit . span ) ;
2323 }
2424 }
2525}
2626
27- fn check_bitwise_assign_expr ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
28- if let ExprKind :: AssignOp ( op, _, e) = & expr. kind
29- && matches ! (
30- op. node,
31- AssignOpKind :: BitAndAssign | AssignOpKind :: BitOrAssign | AssignOpKind :: BitXorAssign
32- )
33- && let ExprKind :: Lit ( lit) = e. kind
27+ pub ( super ) fn check_assign < ' tcx > ( cx : & LateContext < ' tcx > , op : AssignOpKind , rhs : & ' tcx Expr < ' _ > ) {
28+ if !matches ! (
29+ op,
30+ AssignOpKind :: BitAndAssign | AssignOpKind :: BitOrAssign | AssignOpKind :: BitXorAssign
31+ ) {
32+ return ;
33+ }
34+
35+ if let ExprKind :: Lit ( lit) = & rhs. kind
3436 && is_decimal_number ( cx, lit. span )
35- && !is_power_of_twoish ( & lit)
37+ && !is_power_of_twoish ( lit)
3638 {
3739 emit_lint ( cx, lit. span ) ;
3840 }
@@ -61,11 +63,3 @@ fn emit_lint(cx: &LateContext<'_>, span: Span) {
6163 "use binary (0b...), hex (0x...), or octal (0o...) notation for better readability" ,
6264 ) ;
6365}
64-
65- pub ( super ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
66- if expr. span . from_expansion ( ) {
67- return ;
68- }
69- check_bitwise_binary_expr ( cx, expr) ;
70- check_bitwise_assign_expr ( cx, expr) ;
71- }
0 commit comments