Explorar el Código

Clean up a couple of if-blocks

These were flagged by `cargo clippy`:

    warning: this `else { if .. }` block can be collapsed
Alex Crawford hace 4 años
padre
commit
1ff8edf201
Se han modificado 5 ficheros con 10 adiciones y 15 borrados
  1. 2 0
      examples/benchmark.rs
  2. 1 0
      examples/loopback.rs
  3. 2 4
      src/iface/ethernet.rs
  4. 2 6
      src/wire/icmpv6.rs
  5. 3 5
      src/wire/ip.rs

+ 2 - 0
examples/benchmark.rs

@@ -1,3 +1,5 @@
+#![allow(clippy::collapsible_if)]
+
 mod utils;
 
 use std::cmp;

+ 1 - 0
examples/loopback.rs

@@ -1,5 +1,6 @@
 #![cfg_attr(not(feature = "std"), no_std)]
 #![allow(unused_mut)]
+#![allow(clippy::collapsible_if)]
 
 #[cfg(feature = "std")]
 #[allow(dead_code)]

+ 2 - 4
src/iface/ethernet.rs

@@ -1192,10 +1192,8 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
                     Some(lladdr) if lladdr.is_unicast() && target_addr.is_unicast() => {
                         if flags.contains(NdiscNeighborFlags::OVERRIDE) {
                             self.neighbor_cache.fill(ip_addr, lladdr, timestamp)
-                        } else {
-                            if !self.neighbor_cache.lookup(&ip_addr, timestamp).found() {
-                                    self.neighbor_cache.fill(ip_addr, lladdr, timestamp)
-                            }
+                        } else if !self.neighbor_cache.lookup(&ip_addr, timestamp).found() {
+                                self.neighbor_cache.fill(ip_addr, lladdr, timestamp)
                         }
                     },
                     _ => (),

+ 2 - 6
src/wire/icmpv6.rs

@@ -271,14 +271,10 @@ impl<T: AsRef<[u8]>> Packet<T> {
     /// Returns `Err(Error::Truncated)` if the buffer is too short.
     pub fn check_len(&self) -> Result<()> {
         let len = self.buffer.as_ref().len();
-        if len < field::HEADER_END {
+        if len < field::HEADER_END || len < self.header_len() {
             Err(Error::Truncated)
         } else {
-            if len < self.header_len() {
-                Err(Error::Truncated)
-            } else {
-                Ok(())
-            }
+            Ok(())
         }
     }
 

+ 3 - 5
src/wire/ip.rs

@@ -201,11 +201,9 @@ impl Address {
                     } else {
                         ones = false;
                     }
-                } else {
-                    if one {
-                        // 1 where 0 was expected
-                        return None
-                    }
+                } else if one {
+                    // 1 where 0 was expected
+                    return None
                 }
                 mask >>= 1;
             }