瀏覽代碼

Merge pull request #402 from crawford/clippy

Some more cleanup suggested by cargo clippy
Dario Nieuwenhuis 4 年之前
父節點
當前提交
38d5329353

+ 2 - 2
examples/client.rs

@@ -77,7 +77,7 @@ fn main() {
             if socket.may_recv() {
                 let data = socket.recv(|data| {
                     let mut data = data.to_owned();
-                    if data.len() > 0 {
+                    if !data.is_empty() {
                         debug!("recv data: {:?}",
                                str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)"));
                         data = data.split(|&b| b == b'\n').collect::<Vec<_>>().concat();
@@ -86,7 +86,7 @@ fn main() {
                     }
                     (data.len(), data)
                 }).unwrap();
-                if socket.can_send() && data.len() > 0 {
+                if socket.can_send() && !data.is_empty() {
                     debug!("send data: {:?}",
                            str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)"));
                     socket.send_slice(&data[..]).unwrap();

+ 4 - 4
examples/server.rs

@@ -133,7 +133,7 @@ fn main() {
                 let data = socket.recv(|buffer| {
                     let recvd_len = buffer.len();
                     let mut data = buffer.to_owned();
-                    if data.len() > 0 {
+                    if !data.is_empty() {
                         debug!("tcp:6970 recv data: {:?}",
                                str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)"));
                         data = data.split(|&b| b == b'\n').collect::<Vec<_>>().concat();
@@ -142,7 +142,7 @@ fn main() {
                     }
                     (recvd_len, data)
                 }).unwrap();
-                if socket.can_send() && data.len() > 0 {
+                if socket.can_send() && !data.is_empty() {
                     debug!("tcp:6970 send data: {:?}",
                            str::from_utf8(data.as_ref()).unwrap_or("(invalid utf8)"));
                     socket.send_slice(&data[..]).unwrap();
@@ -164,7 +164,7 @@ fn main() {
 
             if socket.may_recv() {
                 socket.recv(|buffer| {
-                    if buffer.len() > 0 {
+                    if !buffer.is_empty() {
                         debug!("tcp:6971 recv {:?} octets", buffer.len());
                     }
                     (buffer.len(), ())
@@ -183,7 +183,7 @@ fn main() {
 
             if socket.may_send() {
                 socket.send(|data| {
-                    if data.len() > 0 {
+                    if !data.is_empty() {
                         debug!("tcp:6972 send {:?} octets", data.len());
                         for (i, b) in data.iter_mut().enumerate() {
                             *b = (i % 256) as u8;

+ 5 - 11
src/iface/ethernet.rs

@@ -721,7 +721,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
     /// [RFC 4291 § 2.7.1]: https://tools.ietf.org/html/rfc4291#section-2.7.1
     #[cfg(feature = "proto-ipv6")]
     pub fn has_solicited_node(&self, addr: Ipv6Address) -> bool {
-        self.ip_addrs.iter().find(|cidr| {
+        self.ip_addrs.iter().any(|cidr| {
             match *cidr {
                 IpCidr::Ipv6(cidr) if cidr.address() != Ipv6Address::LOOPBACK=> {
                     // Take the lower order 24 bits of the IPv6 address and
@@ -730,7 +730,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
                 }
                 _ => false,
             }
-        }).is_some()
+        })
     }
 
     /// Check whether the interface has the given IP address assigned.
@@ -1522,8 +1522,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
     fn in_same_network(&self, addr: &IpAddress) -> bool {
         self.ip_addrs
             .iter()
-            .find(|cidr| cidr.contains_addr(addr))
-            .is_some()
+            .any(|cidr| cidr.contains_addr(addr))
     }
 
     fn route(&self, addr: &IpAddress, timestamp: Instant) -> Result<IpAddress> {
@@ -1578,13 +1577,8 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
                     IpAddress::__Nonexhaustive =>
                         unreachable!()
                 };
-            match hardware_addr {
-                Some(hardware_addr) =>
-                    // Destination is multicast
-                    return Ok((hardware_addr, tx_token)),
-                None =>
-                    // Continue
-                    (),
+            if let Some(hardware_addr) = hardware_addr {
+                return Ok((hardware_addr, tx_token))
             }
         }
 

+ 5 - 7
src/iface/neighbor.rs

@@ -106,7 +106,7 @@ impl<'a> Cache<'a> {
             #[cfg(any(feature = "std", feature = "alloc"))]
             ManagedMap::Owned(ref mut map) => {
                 if current_storage_size >= self.gc_threshold {
-                    let new_btree_map = map.into_iter()
+                    let new_btree_map = map.iter_mut()
                         .map(|(key, value)| (*key, *value))
                         .filter(|(_, v)| timestamp < v.expires_at)
                         .collect();
@@ -169,13 +169,11 @@ impl<'a> Cache<'a> {
             return Answer::Found(EthernetAddress::BROADCAST);
         }
 
-        match self.storage.get(protocol_addr) {
-            Some(&Neighbor { expires_at, hardware_addr }) => {
-                if timestamp < expires_at {
-                    return Answer::Found(hardware_addr)
-                }
+        if let Some(&Neighbor { expires_at, hardware_addr }) =
+                self.storage.get(protocol_addr) {
+            if timestamp < expires_at {
+                return Answer::Found(hardware_addr)
             }
-            None => ()
         }
 
         if timestamp < self.silent_until {

+ 3 - 1
src/lib.rs

@@ -88,7 +88,9 @@
 compile_error!("at least one socket needs to be enabled"); */
 
 // FIXME(dlrobertson): clippy fails with this lint
-#![cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
+#![allow(clippy::if_same_then_else)]
+#![allow(clippy::manual_non_exhaustive)]
+#![allow(clippy::match_like_matches_macro)]
 
 #[cfg(feature = "alloc")]
 extern crate alloc;

+ 6 - 0
src/parsers.rs

@@ -287,12 +287,14 @@ impl<'a> Parser<'a> {
 
     fn accept_ip(&mut self) -> Result<IpAddress> {
         #[cfg(feature = "proto-ipv4")]
+        #[allow(clippy::single_match)]
         match self.try_do(|p| p.accept_ipv4()) {
             Some(ipv4) => return Ok(IpAddress::Ipv4(ipv4)),
             None => ()
         }
 
         #[cfg(feature = "proto-ipv6")]
+        #[allow(clippy::single_match)]
         match self.try_do(|p| p.accept_ipv6(false)) {
             Some(ipv6) => return Ok(IpAddress::Ipv6(ipv6)),
             None => ()
@@ -333,12 +335,14 @@ impl<'a> Parser<'a> {
 
     fn accept_ip_endpoint(&mut self) -> Result<IpEndpoint> {
         #[cfg(feature = "proto-ipv4")]
+        #[allow(clippy::single_match)]
         match self.try_do(|p| p.accept_ipv4_endpoint()) {
             Some(ipv4) => return Ok(ipv4),
             None => ()
         }
 
         #[cfg(feature = "proto-ipv6")]
+        #[allow(clippy::single_match)]
         match self.try_do(|p| p.accept_ipv6_endpoint()) {
             Some(ipv6) => return Ok(ipv6),
             None => ()
@@ -424,12 +428,14 @@ impl FromStr for IpCidr {
     /// Parse a string representation of an IP CIDR.
     fn from_str(s: &str) -> Result<IpCidr> {
         #[cfg(feature = "proto-ipv4")]
+        #[allow(clippy::single_match)]
         match Ipv4Cidr::from_str(s) {
             Ok(cidr) => return Ok(IpCidr::Ipv4(cidr)),
             Err(_) => ()
         }
 
         #[cfg(feature = "proto-ipv6")]
+        #[allow(clippy::single_match)]
         match Ipv6Cidr::from_str(s) {
             Ok(cidr) => return Ok(IpCidr::Ipv6(cidr)),
             Err(_) => ()

+ 11 - 17
src/socket/tcp.rs

@@ -127,21 +127,16 @@ impl Timer {
     }
 
     fn set_keep_alive(&mut self) {
-        match *self {
-            Timer::Idle { ref mut keep_alive_at }
-                    if keep_alive_at.is_none() => {
+        if let Timer::Idle { ref mut keep_alive_at } = *self {
+            if keep_alive_at.is_none() {
                 *keep_alive_at = Some(Instant::from_millis(0))
             }
-            _ => ()
         }
     }
 
     fn rewind_keep_alive(&mut self, timestamp: Instant, interval: Option<Duration>) {
-        match self {
-            &mut Timer::Idle { ref mut keep_alive_at } => {
-                *keep_alive_at = interval.map(|interval| timestamp + interval)
-            }
-            _ => ()
+        if let Timer::Idle { ref mut keep_alive_at } = *self {
+            *keep_alive_at = interval.map(|interval| timestamp + interval)
         }
     }
 
@@ -685,7 +680,7 @@ impl<'a> TcpSocket<'a> {
             // we still can receive indefinitely.
             State::FinWait1 | State::FinWait2 => true,
             // If we have something in the receive buffer, we can receive that.
-            _ if self.rx_buffer.len() > 0 => true,
+            _ if !self.rx_buffer.is_empty() => true,
             _ => false
         }
     }
@@ -833,7 +828,7 @@ impl<'a> TcpSocket<'a> {
         self.recv_error_check()?;
 
         let buffer = self.rx_buffer.get_allocated(0, size);
-        if buffer.len() > 0 {
+        if !buffer.is_empty() {
             #[cfg(any(test, feature = "verbose"))]
             net_trace!("{}:{}:{}: rx buffer: peeking at {} octets",
                        self.meta.handle, self.local_endpoint, self.remote_endpoint,
@@ -966,8 +961,7 @@ impl<'a> TcpSocket<'a> {
                 reply_repr.sack_ranges[0] = self.assembler.iter_data(
                     reply_repr.ack_number.map(|s| s.0 as usize).unwrap_or(0))
                     .map(|(left, right)| (left as u32, right as u32))
-                    .skip_while(|(left, right)| *left > last_seg_seq || *right < last_seg_seq)
-                    .next();
+                    .find(|(left, right)| *left <= last_seg_seq && *right >= last_seg_seq);
             }
 
             if reply_repr.sack_ranges[0].is_none() {
@@ -1368,7 +1362,7 @@ impl<'a> TcpSocket<'a> {
                 // Increment duplicate ACK count and set for retransmit if we just recived
                 // the third duplicate ACK
                 Some(ref last_rx_ack) if
-                    repr.payload.len() == 0 &&
+                    repr.payload.is_empty() &&
                     *last_rx_ack == ack_number &&
                     ack_number < self.remote_last_seq => {
                     // Increment duplicate ACK count
@@ -1649,7 +1643,7 @@ impl<'a> TcpSocket<'a> {
                     match self.state {
                         State::FinWait1 | State::LastAck =>
                             repr.control = TcpControl::Fin,
-                        State::Established | State::CloseWait if repr.payload.len() > 0 =>
+                        State::Established | State::CloseWait if !repr.payload.is_empty() =>
                             repr.control = TcpControl::Psh,
                         _ => ()
                     }
@@ -1682,12 +1676,12 @@ impl<'a> TcpSocket<'a> {
         if is_keep_alive {
             net_trace!("{}:{}:{}: sending a keep-alive",
                        self.meta.handle, self.local_endpoint, self.remote_endpoint);
-        } else if repr.payload.len() > 0 {
+        } else if !repr.payload.is_empty() {
             net_trace!("{}:{}:{}: tx buffer: sending {} octets at offset {}",
                        self.meta.handle, self.local_endpoint, self.remote_endpoint,
                        repr.payload.len(), self.remote_last_seq - self.local_seq_no);
         }
-        if repr.control != TcpControl::None || repr.payload.len() == 0 {
+        if repr.control != TcpControl::None || repr.payload.is_empty() {
             let flags =
                 match (repr.control, repr.ack_number) {
                     (TcpControl::Syn,  None)    => "SYN",

+ 2 - 2
src/storage/assembler.rs

@@ -243,7 +243,7 @@ impl Assembler {
     /// |--- 100 ---|--- 200 ---|--- 100 ---|
     ///
     /// An offset of 1500 would return the ranges: ``(1500, 1600), (1800, 1900)``
-    pub fn iter_data<'a>(&'a self, first_offset: usize) -> AssemblerIter<'a> {
+    pub fn iter_data(&self, first_offset: usize) -> AssemblerIter {
         AssemblerIter::new(self, first_offset)
     }
 }
@@ -275,7 +275,7 @@ impl<'a> Iterator for AssemblerIter<'a> {
         let mut data_range = None;
         while data_range.is_none() && self.index < self.assembler.contigs.len() {
             let contig = self.assembler.contigs[self.index];
-            self.left = self.left + contig.hole_size;
+            self.left += contig.hole_size;
             self.right = self.left + contig.data_size;
             data_range = if self.left < self.right {
                 let data_range = (self.left + self.offset, self.right + self.offset);

+ 2 - 2
src/storage/ring_buffer.rs

@@ -190,7 +190,7 @@ impl<'a, T: 'a> RingBuffer<'a, T> {
     /// This function may return a slice smaller than the given size
     /// if the free space in the buffer is not contiguous.
     // #[must_use]
-    pub fn enqueue_many<'b>(&'b mut self, size: usize) -> &'b mut [T] {
+    pub fn enqueue_many(&mut self, size: usize) -> &mut [T] {
         self.enqueue_many_with(|buf| {
             let size = cmp::min(size, buf.len());
             (size, &mut buf[..size])
@@ -242,7 +242,7 @@ impl<'a, T: 'a> RingBuffer<'a, T> {
     /// This function may return a slice smaller than the given size
     /// if the allocated space in the buffer is not contiguous.
     // #[must_use]
-    pub fn dequeue_many<'b>(&'b mut self, size: usize) -> &'b mut [T] {
+    pub fn dequeue_many(&mut self, size: usize) -> &mut [T] {
         self.dequeue_many_with(|buf| {
             let size = cmp::min(size, buf.len());
             (size, &mut buf[..size])

+ 3 - 3
src/time.rs

@@ -71,7 +71,7 @@ impl Instant {
 impl From<::std::time::Instant> for Instant {
     fn from(other: ::std::time::Instant) -> Instant {
         let elapsed = other.elapsed();
-        Instant::from_millis((elapsed.as_secs() * 1_000) as i64 + (elapsed.subsec_nanos() / 1_000_000) as i64)
+        Instant::from_millis((elapsed.as_secs() * 1_000) as i64 + elapsed.subsec_millis() as i64)
     }
 }
 
@@ -80,7 +80,7 @@ impl From<::std::time::SystemTime> for Instant {
     fn from(other: ::std::time::SystemTime) -> Instant {
         let n = other.duration_since(::std::time::UNIX_EPOCH)
             .expect("start time must not be before the unix epoch");
-        Self::from_millis(n.as_secs() as i64 * 1000 + (n.subsec_nanos() / 1000000) as i64)
+        Self::from_millis(n.as_secs() as i64 * 1000 + n.subsec_millis() as i64)
     }
 }
 
@@ -233,7 +233,7 @@ impl ops::DivAssign<u32> for Duration {
 impl From<::core::time::Duration> for Duration {
     fn from(other: ::core::time::Duration) -> Duration {
         Duration::from_millis(
-            other.as_secs() * 1000 + (other.subsec_nanos() / 1_000_000) as u64
+            other.as_secs() * 1000 + other.subsec_millis() as u64
         )
     }
 }

+ 14 - 14
src/wire/dhcpv4.rs

@@ -135,50 +135,50 @@ impl<'a> DhcpOption<'a> {
 
     pub fn emit<'b>(&self, buffer: &'b mut [u8]) -> &'b mut [u8] {
         let skip_length;
-        match self {
-            &DhcpOption::EndOfList => {
+        match *self {
+            DhcpOption::EndOfList => {
                 skip_length = 1;
                 buffer[0] = field::OPT_END;
             }
-            &DhcpOption::Pad => {
+            DhcpOption::Pad => {
                 skip_length = 1;
                 buffer[0] = field::OPT_PAD;
             }
             _ => {
                 skip_length = self.buffer_len();
                 buffer[1] = (skip_length - 2) as u8;
-                match self {
-                    &DhcpOption::EndOfList | &DhcpOption::Pad => unreachable!(),
-                    &DhcpOption::MessageType(value) => {
+                match *self {
+                    DhcpOption::EndOfList | DhcpOption::Pad => unreachable!(),
+                    DhcpOption::MessageType(value) => {
                         buffer[0] = field::OPT_DHCP_MESSAGE_TYPE;
                         buffer[2] = value.into();
                     }
-                    &DhcpOption::ClientIdentifier(eth_addr) => {
+                    DhcpOption::ClientIdentifier(eth_addr) => {
                         buffer[0] = field::OPT_CLIENT_ID;
                         buffer[2] = u16::from(Hardware::Ethernet) as u8;
                         buffer[3..9].copy_from_slice(eth_addr.as_bytes());
                     }
-                    &DhcpOption::RequestedIp(ip)  => {
+                    DhcpOption::RequestedIp(ip)  => {
                         buffer[0] = field::OPT_REQUESTED_IP;
                         buffer[2..6].copy_from_slice(ip.as_bytes());
                     }
-                    &DhcpOption::ServerIdentifier(ip)  => {
+                    DhcpOption::ServerIdentifier(ip)  => {
                         buffer[0] = field::OPT_SERVER_IDENTIFIER;
                         buffer[2..6].copy_from_slice(ip.as_bytes());
                     }
-                    &DhcpOption::Router(ip)  => {
+                    DhcpOption::Router(ip)  => {
                         buffer[0] = field::OPT_ROUTER;
                         buffer[2..6].copy_from_slice(ip.as_bytes());
                     }
-                    &DhcpOption::SubnetMask(mask)  => {
+                    DhcpOption::SubnetMask(mask)  => {
                         buffer[0] = field::OPT_SUBNET_MASK;
                         buffer[2..6].copy_from_slice(mask.as_bytes());
                     }
-                    &DhcpOption::MaximumDhcpMessageSize(size) => {
+                    DhcpOption::MaximumDhcpMessageSize(size) => {
                         buffer[0] = field::OPT_MAX_DHCP_MESSAGE_SIZE;
                         buffer[2..4].copy_from_slice(&size.to_be_bytes()[..]);
                     }
-                    &DhcpOption::Other { kind, data: provided } => {
+                    DhcpOption::Other { kind, data: provided } => {
                         buffer[0] = kind;
                         buffer[2..skip_length].copy_from_slice(provided);
                     }
@@ -727,7 +727,7 @@ impl<'a> Repr<'a> {
         let mut max_size = None;
 
         let mut options = packet.options()?;
-        while options.len() > 0 {
+        while !options.is_empty() {
             let (next_options, option) = DhcpOption::parse(options)?;
             match option {
                 DhcpOption::EndOfList => break,

+ 3 - 3
src/wire/icmpv6.rs

@@ -420,7 +420,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
             Message::MldQuery => {
                 let data = self.buffer.as_mut();
                 NetworkEndian::write_u16(&mut data[field::QUERY_RESV], 0);
-                data[field::SQRV] = data[field::SQRV] & 0xf;
+                data[field::SQRV] &= 0xf;
             },
             Message::MldReport => {
                 let data = self.buffer.as_mut();
@@ -624,10 +624,10 @@ impl<'a> Repr<'a> {
             },
             #[cfg(feature = "ethernet")]
             (msg_type, 0) if msg_type.is_ndisc() => {
-                NdiscRepr::parse(packet).map(|repr| Repr::Ndisc(repr))
+                NdiscRepr::parse(packet).map(Repr::Ndisc)
             },
             (msg_type, 0) if msg_type.is_mld() => {
-                MldRepr::parse(packet).map(|repr| Repr::Mld(repr))
+                MldRepr::parse(packet).map(Repr::Mld)
             },
             _ => Err(Error::Unrecognized)
         }

+ 1 - 1
src/wire/ipv6fragment.rs

@@ -115,7 +115,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Header<T> {
         data[field::RESERVED] = 0;
 
         // Retain the higher order 5 bits and lower order 1 bit
-        data[3] = data[3] & 0xf9;
+        data[3] &= 0xf9;
     }
 
     /// Set the fragment offset field.

+ 1 - 1
src/wire/ipv6routing.rs

@@ -310,7 +310,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Header<T> {
             }
             Type::Rpl => {
                 // Retain the higher order 4 bits of the padding field
-                data[field::PAD] = data[field::PAD] & 0xF0;
+                data[field::PAD] &= 0xF0;
                 data[6] = 0;
                 data[7] = 0;
             }

+ 1 - 1
src/wire/mld.rs

@@ -125,7 +125,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
     #[inline]
     pub fn clear_s_flag(&mut self) {
         let data = self.buffer.as_mut();
-        data[field::SQRV] = data[field::SQRV] & 0x7;
+        data[field::SQRV] &= 0x7;
     }
 
     /// Set the Querier's Robustness Variable.

+ 3 - 3
src/wire/ndisc.rs

@@ -228,7 +228,7 @@ impl<'a> Repr<'a> {
                 where T: AsRef<[u8]> + ?Sized {
         match packet.msg_type() {
             Message::RouterSolicit => {
-                let lladdr = if packet.payload().len() > 0 {
+                let lladdr = if !packet.payload().is_empty() {
                     let opt = NdiscOption::new_checked(packet.payload())?;
                     match opt.option_type() {
                         NdiscOptionType::SourceLinkLayerAddr => Some(opt.link_layer_addr()),
@@ -263,7 +263,7 @@ impl<'a> Repr<'a> {
                 })
             },
             Message::NeighborSolicit => {
-                let lladdr = if packet.payload().len() > 0 {
+                let lladdr = if !packet.payload().is_empty() {
                     let opt = NdiscOption::new_checked(packet.payload())?;
                     match opt.option_type() {
                         NdiscOptionType::SourceLinkLayerAddr => Some(opt.link_layer_addr()),
@@ -277,7 +277,7 @@ impl<'a> Repr<'a> {
                 })
             },
             Message::NeighborAdvert => {
-                let lladdr = if packet.payload().len() > 0 {
+                let lladdr = if !packet.payload().is_empty() {
                     let opt = NdiscOption::new_checked(packet.payload())?;
                     match opt.option_type() {
                         NdiscOptionType::TargetLinkLayerAddr => Some(opt.link_layer_addr()),

+ 12 - 19
src/wire/tcp.rs

@@ -294,13 +294,10 @@ impl<T: AsRef<[u8]>> Packet<T> {
     pub fn selective_ack_permitted(&self) -> Result<bool> {
         let data = self.buffer.as_ref();
         let mut options = &data[field::OPTIONS(self.header_len())];
-        while options.len() > 0 {
+        while !options.is_empty() {
             let (next_options, option) = TcpOption::parse(options)?;
-            match option {
-                TcpOption::SackPermitted => {
-                    return Ok(true);
-                },
-                _ => {},
+            if option == TcpOption::SackPermitted {
+                return Ok(true);
             }
             options = next_options;
         }
@@ -310,18 +307,13 @@ impl<T: AsRef<[u8]>> Packet<T> {
     /// Return the selective acknowledgement ranges, if any. If there are none in the packet, an
     /// array of ``None`` values will be returned.
     ///
-    pub fn selective_ack_ranges<'s>(
-        &'s self
-    ) -> Result<[Option<(u32, u32)>; 3]> {
+    pub fn selective_ack_ranges(&self) -> Result<[Option<(u32, u32)>; 3]> {
         let data = self.buffer.as_ref();
         let mut options = &data[field::OPTIONS(self.header_len())];
-        while options.len() > 0 {
+        while !options.is_empty() {
             let (next_options, option) = TcpOption::parse(options)?;
-            match option {
-                TcpOption::SackRange(slice) => {
-                    return Ok(slice);
-                },
-                _ => {},
+            if let TcpOption::SackRange(slice) = option {
+                return Ok(slice);
             }
             options = next_options;
         }
@@ -718,6 +710,7 @@ pub enum Control {
     Rst
 }
 
+#[allow(clippy::len_without_is_empty)]
 impl Control {
     /// Return the length of a control flag, in terms of sequence space.
     pub fn len(self) -> usize {
@@ -789,7 +782,7 @@ impl<'a> Repr<'a> {
         let mut options = packet.options();
         let mut sack_permitted = false;
         let mut sack_ranges = [None, None, None];
-        while options.len() > 0 {
+        while !options.is_empty() {
             let (next_options, option) = TcpOption::parse(options)?;
             match option {
                 TcpOption::EndOfList => break,
@@ -905,7 +898,7 @@ impl<'a> Repr<'a> {
                 let tmp = options; options = TcpOption::SackRange(self.sack_ranges).emit(tmp);
             }
 
-            if options.len() > 0 {
+            if !options.is_empty() {
                 TcpOption::EndOfList.emit(options);
             }
         }
@@ -929,7 +922,7 @@ impl<'a> Repr<'a> {
     /// Return whether the segment has no flags set (except PSH) and no data.
     pub fn is_empty(&self) -> bool {
         match self.control {
-            _ if self.payload.len() != 0 => false,
+            _ if !self.payload.is_empty() => false,
             Control::Syn  | Control::Fin | Control::Rst => false,
             Control::None | Control::Psh => true
         }
@@ -959,7 +952,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Packet<&'a T> {
         write!(f, " len={}", self.payload().len())?;
 
         let mut options = self.options();
-        while options.len() > 0 {
+        while !options.is_empty() {
             let (next_options, option) =
                 match TcpOption::parse(options) {
                     Ok(res) => res,

+ 1 - 0
src/wire/udp.rs

@@ -27,6 +27,7 @@ mod field {
     }
 }
 
+#[allow(clippy::len_without_is_empty)]
 impl<T: AsRef<[u8]>> Packet<T> {
     /// Imbue a raw octet buffer with UDP packet structure.
     pub fn new_unchecked(buffer: T) -> Packet<T> {