Ver Fonte

Fix all clippy warnings

Aaron Kutch há 4 anos atrás
pai
commit
5e2b3c7b27
7 ficheiros alterados com 28 adições e 16 exclusões
  1. 2 3
      src/float/add.rs
  2. 9 12
      src/float/cmp.rs
  3. 4 0
      src/float/div.rs
  4. 1 1
      src/float/mul.rs
  5. 7 0
      src/int/specialized_div_rem/mod.rs
  6. 2 0
      src/lib.rs
  7. 3 0
      src/mem/mod.rs

+ 2 - 3
src/float/add.rs

@@ -137,9 +137,8 @@ where
             a_significand <<= shift;
             a_exponent -= shift;
         }
-    } else
-    /* addition */
-    {
+    } else {
+        // addition
         a_significand += b_significand;
 
         // If the addition carried up, we need to right-shift the result and

+ 9 - 12
src/float/cmp.rs

@@ -63,25 +63,22 @@ fn cmp<F: Float>(a: F, b: F) -> Result {
     // a and b as signed integers as we would with a fp_ting-point compare.
     if a_srep & b_srep >= szero {
         if a_srep < b_srep {
-            return Result::Less;
+            Result::Less
         } else if a_srep == b_srep {
-            return Result::Equal;
+            Result::Equal
         } else {
-            return Result::Greater;
+            Result::Greater
         }
-    }
     // Otherwise, both are negative, so we need to flip the sense of the
     // comparison to get the correct result.  (This assumes a twos- or ones-
     // complement integer representation; if integers are represented in a
     // sign-magnitude representation, then this flip is incorrect).
-    else {
-        if a_srep > b_srep {
-            return Result::Less;
-        } else if a_srep == b_srep {
-            return Result::Equal;
-        } else {
-            return Result::Greater;
-        }
+    } else if a_srep > b_srep {
+        Result::Less
+    } else if a_srep == b_srep {
+        Result::Equal
+    } else {
+        Result::Greater
     }
 }
 

+ 4 - 0
src/float/div.rs

@@ -1,3 +1,7 @@
+// The functions are complex with many branches, and explicit
+// `return`s makes it clear where function exit points are
+#![allow(clippy::needless_return)]
+
 use float::Float;
 use int::{CastInto, DInt, HInt, Int};
 

+ 1 - 1
src/float/mul.rs

@@ -181,7 +181,7 @@ where
         product_high += product_high & one;
     }
 
-    return F::from_repr(product_high);
+    F::from_repr(product_high)
 }
 
 intrinsics! {

+ 7 - 0
src/int/specialized_div_rem/mod.rs

@@ -1,5 +1,12 @@
 // TODO: when `unsafe_block_in_unsafe_fn` is stabilized, remove this
 #![allow(unused_unsafe)]
+// The functions are complex with many branches, and explicit
+// `return`s makes it clear where function exit points are
+#![allow(clippy::needless_return)]
+#![allow(clippy::comparison_chain)]
+// Clippy is confused by the complex configuration
+#![allow(clippy::if_same_then_else)]
+#![allow(clippy::needless_bool)]
 
 //! This `specialized_div_rem` module is originally from version 1.0.0 of the
 //! `specialized-div-rem` crate. Note that `for` loops with ranges are not used in this

+ 2 - 0
src/lib.rs

@@ -17,6 +17,8 @@
 // compiler on ABIs and such, so we should be "good enough" for now and changes
 // to the `u128` ABI will be reflected here.
 #![allow(improper_ctypes, improper_ctypes_definitions)]
+// `mem::swap` cannot be used because it may generate references to memcpy in unoptimized code.
+#![allow(clippy::manual_swap)]
 
 // We disable #[no_mangle] for tests so that we can verify the test results
 // against the native compiler-rt implementations of the builtins.

+ 3 - 0
src/mem/mod.rs

@@ -1,3 +1,6 @@
+// Trying to satisfy clippy here is hopeless
+#![allow(clippy::style)]
+
 #[allow(warnings)]
 #[cfg(target_pointer_width = "16")]
 type c_int = i16;