Browse Source

fix new clippy lints

Liam Kinne 10 months ago
parent
commit
50f5f17dca

+ 3 - 3
src/iface/interface/mod.rs

@@ -580,7 +580,7 @@ impl Interface {
 
         enum EgressError {
             Exhausted,
-            Dispatch(DispatchError),
+            Dispatch,
         }
 
         let mut emitted_any = false;
@@ -602,7 +602,7 @@ impl Interface {
 
                 inner
                     .dispatch_ip(t, meta, response, &mut self.fragmenter)
-                    .map_err(EgressError::Dispatch)?;
+                    .map_err(|_| EgressError::Dispatch)?;
 
                 emitted_any = true;
 
@@ -673,7 +673,7 @@ impl Interface {
 
             match result {
                 Err(EgressError::Exhausted) => break, // Device buffer full.
-                Err(EgressError::Dispatch(_)) => {
+                Err(EgressError::Dispatch) => {
                     // `NeighborCache` already takes care of rate limiting the neighbor discovery
                     // requests from the socket. However, without an additional rate limiting
                     // mechanism, we would spin on every socket that has yet to discover its

+ 1 - 2
src/phy/loopback.rs

@@ -80,8 +80,7 @@ impl<'a> phy::TxToken for TxToken<'a> {
     where
         F: FnOnce(&mut [u8]) -> R,
     {
-        let mut buffer = Vec::new();
-        buffer.resize(len, 0);
+        let mut buffer = vec![0; len];
         let result = f(&mut buffer);
         self.queue.push_back(buffer);
         result

+ 1 - 1
src/phy/sys/bpf.rs

@@ -172,7 +172,7 @@ impl BpfDevice {
             );
 
             if len == -1 {
-                Err(io::Error::last_os_error()).unwrap()
+                panic!("{:?}", io::Error::last_os_error())
             }
 
             Ok(len as usize)

+ 2 - 2
src/wire/dns.rs

@@ -417,9 +417,9 @@ impl<'a> Repr<'a> {
     }
 
     /// Emit a high-level representation into a DNS packet.
-    pub fn emit<T: ?Sized>(&self, packet: &mut Packet<&mut T>)
+    pub fn emit<T>(&self, packet: &mut Packet<&mut T>)
     where
-        T: AsRef<[u8]> + AsMut<[u8]>,
+        T: AsRef<[u8]> + AsMut<[u8]> + ?Sized,
     {
         packet.set_transaction_id(self.transaction_id);
         packet.set_flags(self.flags);

+ 3 - 3
src/wire/ipv6.rs

@@ -1425,7 +1425,7 @@ pub(crate) mod test {
 
     #[test]
     fn test_repr_parse_bad_version() {
-        let mut bytes = vec![0; 40];
+        let mut bytes = [0; 40];
         let mut packet = Packet::new_unchecked(&mut bytes[..]);
         packet.set_version(4);
         packet.set_payload_len(0);
@@ -1435,7 +1435,7 @@ pub(crate) mod test {
 
     #[test]
     fn test_repr_parse_smaller_than_header() {
-        let mut bytes = vec![0; 40];
+        let mut bytes = [0; 40];
         let mut packet = Packet::new_unchecked(&mut bytes[..]);
         packet.set_version(6);
         packet.set_payload_len(39);
@@ -1445,7 +1445,7 @@ pub(crate) mod test {
 
     #[test]
     fn test_repr_parse_smaller_than_payload() {
-        let mut bytes = vec![0; 40];
+        let mut bytes = [0; 40];
         let mut packet = Packet::new_unchecked(&mut bytes[..]);
         packet.set_version(6);
         packet.set_payload_len(1);

+ 2 - 2
src/wire/mld.rs

@@ -526,7 +526,7 @@ mod test {
 
     #[test]
     fn test_query_construct() {
-        let mut bytes = vec![0xff; 44];
+        let mut bytes = [0xff; 44];
         let mut packet = Packet::new_unchecked(&mut bytes[..]);
         packet.set_msg_type(Message::MldQuery);
         packet.set_msg_code(0);
@@ -567,7 +567,7 @@ mod test {
 
     #[test]
     fn test_record_construct() {
-        let mut bytes = vec![0xff; 44];
+        let mut bytes = [0xff; 44];
         let mut packet = Packet::new_unchecked(&mut bytes[..]);
         packet.set_msg_type(Message::MldReport);
         packet.set_msg_code(0);

+ 1 - 1
src/wire/ndisc.rs

@@ -534,7 +534,7 @@ mod test {
 
     #[test]
     fn test_router_advert_repr_emit() {
-        let mut bytes = vec![0x2a; 24];
+        let mut bytes = [0x2a; 24];
         let mut packet = Packet::new_unchecked(&mut bytes[..]);
         create_repr().emit(
             &MOCK_IP_ADDR_1,

+ 2 - 2
src/wire/sixlowpan/iphc.rs

@@ -176,7 +176,7 @@ impl<T: AsRef<[u8]>> Packet<T> {
     /// Return the ECN field (when it is inlined).
     pub fn ecn_field(&self) -> Option<u8> {
         match self.tf_field() {
-            0b00 | 0b01 | 0b10 => {
+            0b00..=0b10 => {
                 let start = self.ip_fields_start() as usize;
                 Some(self.buffer.as_ref()[start..][0] & 0b1100_0000)
             }
@@ -341,7 +341,7 @@ impl<T: AsRef<[u8]>> Packet<T> {
                 0,
                 AddressMode::NotSupported,
             ))),
-            (1, 1, 0b01 | 0b10 | 0b11) => Ok(UnresolvedAddress::Reserved),
+            (1, 1, 0b01..=0b11) => Ok(UnresolvedAddress::Reserved),
             _ => Err(Error),
         }
     }

+ 4 - 4
src/wire/udp.rs

@@ -255,9 +255,9 @@ impl Repr {
     /// This never calculates the checksum, and is intended for internal-use only,
     /// not for packets that are going to be actually sent over the network. For
     /// example, when decompressing 6lowpan.
-    pub(crate) fn emit_header<T: ?Sized>(&self, packet: &mut Packet<&mut T>, payload_len: usize)
+    pub(crate) fn emit_header<T>(&self, packet: &mut Packet<&mut T>, payload_len: usize)
     where
-        T: AsRef<[u8]> + AsMut<[u8]>,
+        T: AsRef<[u8]> + AsMut<[u8]> + ?Sized,
     {
         packet.set_src_port(self.src_port);
         packet.set_dst_port(self.dst_port);
@@ -266,7 +266,7 @@ impl Repr {
     }
 
     /// Emit a high-level representation into an User Datagram Protocol packet.
-    pub fn emit<T: ?Sized>(
+    pub fn emit<T>(
         &self,
         packet: &mut Packet<&mut T>,
         src_addr: &IpAddress,
@@ -275,7 +275,7 @@ impl Repr {
         emit_payload: impl FnOnce(&mut [u8]),
         checksum_caps: &ChecksumCapabilities,
     ) where
-        T: AsRef<[u8]> + AsMut<[u8]>,
+        T: AsRef<[u8]> + AsMut<[u8]> + ?Sized,
     {
         packet.set_src_port(self.src_port);
         packet.set_dst_port(self.dst_port);