Skip to content

Commit a5d2bfe

Browse files
author
Yury Krivopalov
committed
Simplify checking for all ones in int
1 parent 033c99b commit a5d2bfe

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

clippy_lints/src/identity_op.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
5858
}
5959
}
6060

61-
fn no_zeros(v: &ConstInt) -> bool {
61+
fn all_ones(v: &ConstInt) -> bool {
6262
match *v {
63-
ConstInt::I8(i) => i.count_zeros() == 0,
64-
ConstInt::I16(i) => i.count_zeros() == 0,
65-
ConstInt::I32(i) => i.count_zeros() == 0,
66-
ConstInt::I64(i) => i.count_zeros() == 0,
67-
ConstInt::I128(i) => i.count_zeros() == 0,
68-
ConstInt::U8(i) => i.count_zeros() == 0,
69-
ConstInt::U16(i) => i.count_zeros() == 0,
70-
ConstInt::U32(i) => i.count_zeros() == 0,
71-
ConstInt::U64(i) => i.count_zeros() == 0,
72-
ConstInt::U128(i) => i.count_zeros() == 0,
63+
ConstInt::I8(i) => i == !0,
64+
ConstInt::I16(i) => i == !0,
65+
ConstInt::I32(i) => i == !0,
66+
ConstInt::I64(i) => i == !0,
67+
ConstInt::I128(i) => i == !0,
68+
ConstInt::U8(i) => i == !0,
69+
ConstInt::U16(i) => i == !0,
70+
ConstInt::U32(i) => i == !0,
71+
ConstInt::U64(i) => i == !0,
72+
ConstInt::U128(i) => i == !0,
7373
_ => false
7474
}
7575
}
@@ -79,7 +79,7 @@ fn check(cx: &LateContext, e: &Expr, m: i8, span: Span, arg: Span) {
7979
if let Some(Constant::Int(v)) = constant_simple(cx, e) {
8080
if match m {
8181
0 => v.to_u128_unchecked() == 0,
82-
-1 => no_zeros(&v),
82+
-1 => all_ones(&v),
8383
1 => v.to_u128_unchecked() == 1,
8484
_ => unreachable!(),
8585
} {

0 commit comments

Comments
 (0)