Browse Source

Various cleanups

These were flagged by `cargo clippy`:

    warning: using `clone` on a `Copy` type
    warning: passing a unit value to a function
    warning: redundant closure found
    warning: called `iter().cloned().collect()` on a slice to create a
             `Vec`. Calling `to_vec()` is both faster and more readable
Alex Crawford 4 years ago
parent
commit
b290069cc1
4 changed files with 9 additions and 8 deletions
  1. 2 2
      src/iface/ethernet.rs
  2. 1 0
      src/lib.rs
  3. 5 5
      src/socket/raw.rs
  4. 1 1
      src/storage/ring_buffer.rs

+ 2 - 2
src/iface/ethernet.rs

@@ -1757,7 +1757,7 @@ mod test {
         let mut pkts = Vec::new();
         while let Some((rx, _tx)) = iface.device.receive() {
             rx.consume(timestamp, |pkt| {
-                pkts.push(pkt.iter().cloned().collect());
+                pkts.push(pkt.to_vec());
                 Ok(())
             }).unwrap();
         }
@@ -2567,7 +2567,7 @@ mod test {
         // Leave multicast groups
         let timestamp = Instant::now();
         for group in &groups {
-            iface.leave_multicast_group(group.clone(), timestamp)
+            iface.leave_multicast_group(*group, timestamp)
                 .unwrap();
         }
 

+ 1 - 0
src/lib.rs

@@ -94,6 +94,7 @@ compile_error!("at least one socket needs to be enabled"); */
 #![allow(clippy::redundant_field_names)]
 #![allow(clippy::identity_op)]
 #![allow(clippy::option_map_unit_fn)]
+#![allow(clippy::unit_arg)]
 
 #[cfg(feature = "alloc")]
 extern crate alloc;

+ 5 - 5
src/socket/raw.rs

@@ -473,14 +473,14 @@ mod test {
         {
             let mut socket = ipv4_locals::socket(buffer(0), buffer(2));
 
-            let mut wrong_version = ipv4_locals::PACKET_BYTES.clone();
+            let mut wrong_version = ipv4_locals::PACKET_BYTES;
             Ipv4Packet::new_unchecked(&mut wrong_version).set_version(6);
 
             assert_eq!(socket.send_slice(&wrong_version[..]), Ok(()));
             assert_eq!(socket.dispatch(&checksum_caps, |_| unreachable!()),
                        Ok(()));
 
-            let mut wrong_protocol = ipv4_locals::PACKET_BYTES.clone();
+            let mut wrong_protocol = ipv4_locals::PACKET_BYTES;
             Ipv4Packet::new_unchecked(&mut wrong_protocol).set_protocol(IpProtocol::Tcp);
 
             assert_eq!(socket.send_slice(&wrong_protocol[..]), Ok(()));
@@ -491,14 +491,14 @@ mod test {
         {
             let mut socket = ipv6_locals::socket(buffer(0), buffer(2));
 
-            let mut wrong_version = ipv6_locals::PACKET_BYTES.clone();
+            let mut wrong_version = ipv6_locals::PACKET_BYTES;
             Ipv6Packet::new_unchecked(&mut wrong_version[..]).set_version(4);
 
             assert_eq!(socket.send_slice(&wrong_version[..]), Ok(()));
             assert_eq!(socket.dispatch(&checksum_caps, |_| unreachable!()),
                        Ok(()));
 
-            let mut wrong_protocol = ipv6_locals::PACKET_BYTES.clone();
+            let mut wrong_protocol = ipv6_locals::PACKET_BYTES;
             Ipv6Packet::new_unchecked(&mut wrong_protocol[..]).set_next_header(IpProtocol::Tcp);
 
             assert_eq!(socket.send_slice(&wrong_protocol[..]), Ok(()));
@@ -514,7 +514,7 @@ mod test {
             let mut socket = ipv4_locals::socket(buffer(1), buffer(0));
             assert!(!socket.can_recv());
 
-            let mut cksumd_packet = ipv4_locals::PACKET_BYTES.clone();
+            let mut cksumd_packet = ipv4_locals::PACKET_BYTES;
             Ipv4Packet::new_unchecked(&mut cksumd_packet).fill_checksum();
 
             assert_eq!(socket.recv(), Err(Error::Exhausted));

+ 1 - 1
src/storage/ring_buffer.rs

@@ -405,7 +405,7 @@ mod test {
         assert_eq!(ring.dequeue_one_with(|_| unreachable!()) as Result<()>,
                    Err(Error::Exhausted));
 
-        ring.enqueue_one_with(|e| Ok(e)).unwrap();
+        ring.enqueue_one_with(Ok).unwrap();
         assert!(!ring.is_empty());
         assert!(!ring.is_full());