From fff592621021714dcf54bf849239ca520ec3c722 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Fri, 25 Dec 2020 23:19:48 -0800 Subject: [PATCH] Clean up a couple of if-blocks These were flagged by `cargo clippy`: warning: this `else { if .. }` block can be collapsed --- examples/benchmark.rs | 2 ++ examples/loopback.rs | 1 + src/iface/ethernet.rs | 6 ++---- src/wire/icmpv6.rs | 8 ++------ src/wire/ip.rs | 8 +++----- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/examples/benchmark.rs b/examples/benchmark.rs index 92d8c46..ce307db 100644 --- a/examples/benchmark.rs +++ b/examples/benchmark.rs @@ -1,3 +1,5 @@ +#![allow(clippy::collapsible_if)] + mod utils; use std::cmp; diff --git a/examples/loopback.rs b/examples/loopback.rs index a291aa4..9d0c39b 100644 --- a/examples/loopback.rs +++ b/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)] diff --git a/src/iface/ethernet.rs b/src/iface/ethernet.rs index 2d83aaa..9ab25c2 100644 --- a/src/iface/ethernet.rs +++ b/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) } }, _ => (), diff --git a/src/wire/icmpv6.rs b/src/wire/icmpv6.rs index 14f1f52..b3e49a1 100644 --- a/src/wire/icmpv6.rs +++ b/src/wire/icmpv6.rs @@ -271,14 +271,10 @@ impl> Packet { /// 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(()) } } diff --git a/src/wire/ip.rs b/src/wire/ip.rs index 83eb4df..a675c42 100644 --- a/src/wire/ip.rs +++ b/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; }