Skip to content

Commit

Permalink
Resolve unnecessary_cast clippy lint
Browse files Browse the repository at this point in the history
    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`
  • Loading branch information
dtolnay committed Oct 8, 2022
1 parent ee53dc9 commit 48f3afb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/pretty/mantissa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions src/pretty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/s2f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn s2f(buffer: &[u8]) -> Result<f32, Error> {
// 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))
Expand Down

0 comments on commit 48f3afb

Please sign in to comment.