Clean up clippy warnings about if-else blocks

This de-duplicates and (hopefully) simplifies a few if-else blocks. The
others were given an exception because I thought they were more readable
as is. I've verified that these changes don't result in larger binaries.
v0.7.x
Alex Crawford 2021-01-10 14:16:08 -08:00
parent 06d128ad22
commit 0cf0a7e386
5 changed files with 8 additions and 11 deletions

View File

@ -1026,12 +1026,9 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
!self.has_multicast_group(ipv4_repr.dst_addr) {
// Ignore IP packets not directed at us, or broadcast, or any of the multicast groups.
// If AnyIP is enabled, also check if the packet is routed locally.
if !self.any_ip {
return Ok(None);
} else if match self.routes.lookup(&IpAddress::Ipv4(ipv4_repr.dst_addr), timestamp) {
Some(router_addr) => !self.has_ip_addr(router_addr),
None => true,
} {
if !self.any_ip ||
self.routes.lookup(&IpAddress::Ipv4(ipv4_repr.dst_addr), timestamp)
.map_or(true, |router_addr| !self.has_ip_addr(router_addr)) {
return Ok(None);
}
}
@ -1188,10 +1185,9 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
let ip_addr = ip_repr.src_addr.into();
match lladdr {
Some(lladdr) if lladdr.is_unicast() && target_addr.is_unicast() => {
if flags.contains(NdiscNeighborFlags::OVERRIDE) {
if flags.contains(NdiscNeighborFlags::OVERRIDE) ||
!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)
}
},
_ => (),

View File

@ -87,8 +87,6 @@
feature = "socket-tcp")))]
compile_error!("at least one socket needs to be enabled"); */
// FIXME(dlrobertson): clippy fails with this lint
#![allow(clippy::if_same_then_else)]
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::redundant_field_names)]
#![allow(clippy::identity_op)]

View File

@ -1905,6 +1905,7 @@ impl<'a> TcpSocket<'a> {
Ok(())
}
#[allow(clippy::if_same_then_else)]
pub(crate) fn poll_at(&self) -> PollAt {
// The logic here mirrors the beginning of dispatch() closely.
if !self.remote_endpoint.is_specified() {

View File

@ -86,6 +86,7 @@ impl<T: AsRef<[u8]>> Packet<T> {
///
/// [set_hardware_len]: #method.set_hardware_len
/// [set_protocol_len]: #method.set_protocol_len
#[allow(clippy::if_same_then_else)]
pub fn check_len(&self) -> Result<()> {
let len = self.buffer.as_ref().len();
if len < field::OPER.end {

View File

@ -271,6 +271,7 @@ impl<T: AsRef<[u8]>> Packet<T> {
///
/// [set_header_len]: #method.set_header_len
/// [set_total_len]: #method.set_total_len
#[allow(clippy::if_same_then_else)]
pub fn check_len(&self) -> Result<()> {
let len = self.buffer.as_ref().len();
if len < field::DST_ADDR.end {