From 48f3afb6acf3f5996a471fff67ec94e15104b07a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 7 Oct 2022 22:14:12 -0700 Subject: [PATCH] Resolve unnecessary_cast clippy lint error: casting to the same type is unnecessary (`u32` -> `u32`) --> src/pretty/mantissa.rs:46:17 | 46 | let c = (output - 10_000 * (output / 10_000)) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(output - 10_000 * (output / 10_000))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `-D clippy::unnecessary-cast` implied by `-D clippy::all` error: casting to the same type is unnecessary (`u32` -> `u32`) --> src/pretty/mantissa.rs:63:17 | 63 | let c = ((output % 100) << 1) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `((output % 100) << 1)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast error: casting to the same type is unnecessary (`u32` -> `u32`) --> src/pretty/mantissa.rs:73:17 | 73 | let c = (output << 1) as u32; | ^^^^^^^^^^^^^^^^^^^^ help: try: `(output << 1)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast error: casting to the same type is unnecessary (`u32` -> `u32`) --> src/pretty/mod.rs:164:9 | 164 | ((bits >> FLOAT_MANTISSA_BITS) & ((1u32 << FLOAT_EXPONENT_BITS) - 1)) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `((bits >> FLOAT_MANTISSA_BITS) & ((1u32 << FLOAT_EXPONENT_BITS) - 1))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast error: casting to the same type is unnecessary (`u32` -> `u32`) --> src/s2f.rs:223:68 | 223 | let ieee = ((((signed_m as u32) << f2s::FLOAT_EXPONENT_BITS) | ieee_e2 as u32) | ^^^^^^^^^^^^^^ help: try: `ieee_e2` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `-D clippy::unnecessary-cast` implied by `-D clippy::all` --- src/pretty/mantissa.rs | 6 +++--- src/pretty/mod.rs | 3 +-- src/s2f.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pretty/mantissa.rs b/src/pretty/mantissa.rs index 150c79c..0149f5c 100644 --- a/src/pretty/mantissa.rs +++ b/src/pretty/mantissa.rs @@ -43,7 +43,7 @@ pub unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { #[cfg_attr(feature = "no-panic", inline)] pub unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) { while output >= 10_000 { - let c = (output - 10_000 * (output / 10_000)) as u32; + let c = output - 10_000 * (output / 10_000); output /= 10_000; let c0 = (c % 100) << 1; let c1 = (c / 100) << 1; @@ -60,7 +60,7 @@ pub unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) { result = result.offset(-4); } if output >= 100 { - let c = ((output % 100) << 1) as u32; + let c = (output % 100) << 1; output /= 100; ptr::copy_nonoverlapping( DIGIT_TABLE.as_ptr().offset(c as isize), @@ -70,7 +70,7 @@ pub unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) { result = result.offset(-2); } if output >= 10 { - let c = (output << 1) as u32; + let c = output << 1; ptr::copy_nonoverlapping( DIGIT_TABLE.as_ptr().offset(c as isize), result.offset(-2), diff --git a/src/pretty/mod.rs b/src/pretty/mod.rs index b196a11..da49e86 100644 --- a/src/pretty/mod.rs +++ b/src/pretty/mod.rs @@ -160,8 +160,7 @@ pub unsafe fn format32(f: f32, result: *mut u8) -> usize { let bits = f.to_bits(); let sign = ((bits >> (FLOAT_MANTISSA_BITS + FLOAT_EXPONENT_BITS)) & 1) != 0; let ieee_mantissa = bits & ((1u32 << FLOAT_MANTISSA_BITS) - 1); - let ieee_exponent = - ((bits >> FLOAT_MANTISSA_BITS) & ((1u32 << FLOAT_EXPONENT_BITS) - 1)) as u32; + let ieee_exponent = (bits >> FLOAT_MANTISSA_BITS) & ((1u32 << FLOAT_EXPONENT_BITS) - 1); let mut index = 0isize; if sign { diff --git a/src/s2f.rs b/src/s2f.rs index 37c5417..9593528 100644 --- a/src/s2f.rs +++ b/src/s2f.rs @@ -220,7 +220,7 @@ pub fn s2f(buffer: &[u8]) -> Result { // for overflow here. ieee_e2 += 1; } - let ieee = ((((signed_m as u32) << f2s::FLOAT_EXPONENT_BITS) | ieee_e2 as u32) + let ieee = ((((signed_m as u32) << f2s::FLOAT_EXPONENT_BITS) | ieee_e2) << f2s::FLOAT_MANTISSA_BITS) | ieee_m2; Ok(f32::from_bits(ieee))