From a5d2bfebc458d0d11a1f0318ee89b1434b6d675c Mon Sep 17 00:00:00 2001 From: Yury Krivopalov Date: Sun, 15 Oct 2017 10:21:56 +0300 Subject: [PATCH] Simplify checking for all ones in int --- clippy_lints/src/identity_op.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 21aa914155e0..85dfb6b4ad09 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -58,18 +58,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { } } -fn no_zeros(v: &ConstInt) -> bool { +fn all_ones(v: &ConstInt) -> bool { match *v { - ConstInt::I8(i) => i.count_zeros() == 0, - ConstInt::I16(i) => i.count_zeros() == 0, - ConstInt::I32(i) => i.count_zeros() == 0, - ConstInt::I64(i) => i.count_zeros() == 0, - ConstInt::I128(i) => i.count_zeros() == 0, - ConstInt::U8(i) => i.count_zeros() == 0, - ConstInt::U16(i) => i.count_zeros() == 0, - ConstInt::U32(i) => i.count_zeros() == 0, - ConstInt::U64(i) => i.count_zeros() == 0, - ConstInt::U128(i) => i.count_zeros() == 0, + ConstInt::I8(i) => i == !0, + ConstInt::I16(i) => i == !0, + ConstInt::I32(i) => i == !0, + ConstInt::I64(i) => i == !0, + ConstInt::I128(i) => i == !0, + ConstInt::U8(i) => i == !0, + ConstInt::U16(i) => i == !0, + ConstInt::U32(i) => i == !0, + ConstInt::U64(i) => i == !0, + ConstInt::U128(i) => i == !0, _ => false } } @@ -79,7 +79,7 @@ fn check(cx: &LateContext, e: &Expr, m: i8, span: Span, arg: Span) { if let Some(Constant::Int(v)) = constant_simple(cx, e) { if match m { 0 => v.to_u128_unchecked() == 0, - -1 => no_zeros(&v), + -1 => all_ones(&v), 1 => v.to_u128_unchecked() == 1, _ => unreachable!(), } {