Skip to content

Commit 202800d

Browse files
committed
Refactoring
1 parent d313a6d commit 202800d

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

clippy_lints/src/operators/decimal_bitwise_operands.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_data_structures::packed::Pu128;
55
use rustc_hir::{AssignOpKind, BinOpKind, Expr, ExprKind};
66
use rustc_lint::LateContext;
77
use rustc_span::Span;
8-
use rustc_span::source_map::Spanned;
98

109
use super::DECIMAL_BITWISE_OPERANDS;
1110

@@ -17,24 +16,20 @@ pub(super) fn check_binary<'tcx>(cx: &LateContext<'tcx>, op: BinOpKind, left: &'
1716
for expr in [left, right] {
1817
if let ExprKind::Lit(lit) = &expr.kind
1918
&& is_decimal_number(cx, lit.span)
20-
&& !is_power_of_twoish(lit)
19+
&& !is_power_of_twoish(lit.node)
2120
{
2221
emit_lint(cx, lit.span);
2322
}
2423
}
2524
}
2625

2726
pub(super) fn check_assign<'tcx>(cx: &LateContext<'tcx>, op: AssignOpKind, rhs: &'tcx Expr<'_>) {
28-
if !matches!(
27+
if matches!(
2928
op,
3029
AssignOpKind::BitAndAssign | AssignOpKind::BitOrAssign | AssignOpKind::BitXorAssign
31-
) {
32-
return;
33-
}
34-
35-
if let ExprKind::Lit(lit) = &rhs.kind
30+
) && let ExprKind::Lit(lit) = &rhs.kind
3631
&& is_decimal_number(cx, lit.span)
37-
&& !is_power_of_twoish(lit)
32+
&& !is_power_of_twoish(lit.node)
3833
{
3934
emit_lint(cx, lit.span);
4035
}
@@ -46,8 +41,8 @@ fn is_decimal_number(cx: &LateContext<'_>, span: Span) -> bool {
4641
})
4742
}
4843

49-
fn is_power_of_twoish(lit: &Spanned<LitKind>) -> bool {
50-
if let LitKind::Int(Pu128(val), _) = lit.node {
44+
fn is_power_of_twoish(node: LitKind) -> bool {
45+
if let LitKind::Int(Pu128(val), _) = node {
5146
return val.is_power_of_two() || val.wrapping_add(1).is_power_of_two();
5247
}
5348
false

tests/ui/decimal_bitwise_operands.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![allow(clippy::erasing_op)]
2-
#![allow(clippy::no_effect)]
1+
#![allow(clippy::erasing_op, clippy::no_effect)]
32
#![warn(clippy::decimal_bitwise_operands)]
43

54
macro_rules! bitwise_op {

tests/ui/decimal_bitwise_operands.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: using decimal literal for bitwise operation
2-
--> tests/ui/decimal_bitwise_operands.rs:16:9
2+
--> tests/ui/decimal_bitwise_operands.rs:15:9
33
|
44
LL | x & 99;
55
| ^^
@@ -9,135 +9,135 @@ LL | x & 99;
99
= help: to override `-D warnings` add `#[allow(clippy::decimal_bitwise_operands)]`
1010

1111
error: using decimal literal for bitwise operation
12-
--> tests/ui/decimal_bitwise_operands.rs:17:23
12+
--> tests/ui/decimal_bitwise_operands.rs:16:23
1313
|
1414
LL | x | (/* comment */99);
1515
| ^^
1616
|
1717
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
1818

1919
error: using decimal literal for bitwise operation
20-
--> tests/ui/decimal_bitwise_operands.rs:18:10
20+
--> tests/ui/decimal_bitwise_operands.rs:17:10
2121
|
2222
LL | x ^ (99);
2323
| ^^
2424
|
2525
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
2626

2727
error: using decimal literal for bitwise operation
28-
--> tests/ui/decimal_bitwise_operands.rs:19:10
28+
--> tests/ui/decimal_bitwise_operands.rs:18:10
2929
|
3030
LL | x &= 99;
3131
| ^^
3232
|
3333
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
3434

3535
error: using decimal literal for bitwise operation
36-
--> tests/ui/decimal_bitwise_operands.rs:20:10
36+
--> tests/ui/decimal_bitwise_operands.rs:19:10
3737
|
3838
LL | x |= 99;
3939
| ^^
4040
|
4141
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
4242

4343
error: using decimal literal for bitwise operation
44-
--> tests/ui/decimal_bitwise_operands.rs:21:11
44+
--> tests/ui/decimal_bitwise_operands.rs:20:11
4545
|
4646
LL | x ^= (99);
4747
| ^^
4848
|
4949
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
5050

5151
error: using decimal literal for bitwise operation
52-
--> tests/ui/decimal_bitwise_operands.rs:24:14
52+
--> tests/ui/decimal_bitwise_operands.rs:23:14
5353
|
5454
LL | 0b1010 & 99;
5555
| ^^
5656
|
5757
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
5858

5959
error: using decimal literal for bitwise operation
60-
--> tests/ui/decimal_bitwise_operands.rs:25:15
60+
--> tests/ui/decimal_bitwise_operands.rs:24:15
6161
|
6262
LL | 0b1010 | (99);
6363
| ^^
6464
|
6565
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
6666

6767
error: using decimal literal for bitwise operation
68-
--> tests/ui/decimal_bitwise_operands.rs:26:28
68+
--> tests/ui/decimal_bitwise_operands.rs:25:28
6969
|
7070
LL | 0b1010 ^ (/* comment */99);
7171
| ^^
7272
|
7373
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
7474

7575
error: using decimal literal for bitwise operation
76-
--> tests/ui/decimal_bitwise_operands.rs:27:5
76+
--> tests/ui/decimal_bitwise_operands.rs:26:5
7777
|
7878
LL | 99 & 0b1010;
7979
| ^^
8080
|
8181
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
8282

8383
error: using decimal literal for bitwise operation
84-
--> tests/ui/decimal_bitwise_operands.rs:28:6
84+
--> tests/ui/decimal_bitwise_operands.rs:27:6
8585
|
8686
LL | (99) | 0b1010;
8787
| ^^
8888
|
8989
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
9090

9191
error: using decimal literal for bitwise operation
92-
--> tests/ui/decimal_bitwise_operands.rs:29:19
92+
--> tests/ui/decimal_bitwise_operands.rs:28:19
9393
|
9494
LL | (/* comment */99) ^ 0b1010;
9595
| ^^
9696
|
9797
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
9898

9999
error: using decimal literal for bitwise operation
100-
--> tests/ui/decimal_bitwise_operands.rs:30:11
100+
--> tests/ui/decimal_bitwise_operands.rs:29:11
101101
|
102102
LL | 0xD | 99;
103103
| ^^
104104
|
105105
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
106106

107107
error: using decimal literal for bitwise operation
108-
--> tests/ui/decimal_bitwise_operands.rs:31:5
108+
--> tests/ui/decimal_bitwise_operands.rs:30:5
109109
|
110110
LL | 88 & 99;
111111
| ^^
112112
|
113113
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
114114

115115
error: using decimal literal for bitwise operation
116-
--> tests/ui/decimal_bitwise_operands.rs:31:10
116+
--> tests/ui/decimal_bitwise_operands.rs:30:10
117117
|
118118
LL | 88 & 99;
119119
| ^^
120120
|
121121
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
122122

123123
error: using decimal literal for bitwise operation
124-
--> tests/ui/decimal_bitwise_operands.rs:35:15
124+
--> tests/ui/decimal_bitwise_operands.rs:34:15
125125
|
126126
LL | 37 & 38 & 39;
127127
| ^^
128128
|
129129
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
130130

131131
error: using decimal literal for bitwise operation
132-
--> tests/ui/decimal_bitwise_operands.rs:35:5
132+
--> tests/ui/decimal_bitwise_operands.rs:34:5
133133
|
134134
LL | 37 & 38 & 39;
135135
| ^^
136136
|
137137
= help: use binary (0b...), hex (0x...), or octal (0o...) notation for better readability
138138

139139
error: using decimal literal for bitwise operation
140-
--> tests/ui/decimal_bitwise_operands.rs:35:10
140+
--> tests/ui/decimal_bitwise_operands.rs:34:10
141141
|
142142
LL | 37 & 38 & 39;
143143
| ^^

0 commit comments

Comments
 (0)