Browse Source

various clippy fix

qiujiangkun 3 years ago
parent
commit
7dda148ad5

+ 2 - 2
src/iface/interface.rs

@@ -1082,7 +1082,7 @@ impl<'a> InterfaceInner<'a> {
 
         // Pass every IP packet to all raw sockets we have registered.
         for mut raw_socket in sockets.iter_mut().filter_map(RawSocket::downcast) {
-            if !raw_socket.accepts(&ip_repr) {
+            if !raw_socket.accepts(ip_repr) {
                 continue;
             }
 
@@ -1105,7 +1105,7 @@ impl<'a> InterfaceInner<'a> {
         sockets: &mut SocketSet,
         ipv6_packet: &Ipv6Packet<&'frame T>,
     ) -> Result<Option<IpPacket<'frame>>> {
-        let ipv6_repr = Ipv6Repr::parse(&ipv6_packet)?;
+        let ipv6_repr = Ipv6Repr::parse(ipv6_packet)?;
 
         if !ipv6_repr.src_addr.is_unicast() {
             // Discard packets with non-unicast source addresses.

+ 1 - 1
src/parsers.rs

@@ -472,7 +472,7 @@ impl FromStr for IpEndpoint {
     type Err = ();
 
     fn from_str(s: &str) -> Result<IpEndpoint> {
-        Parser::new(s).until_eof(|p| Ok(p.accept_ip_endpoint()?))
+        Parser::new(s).until_eof(|p| p.accept_ip_endpoint())
     }
 }
 

+ 8 - 8
src/phy/fault_injector.rs

@@ -111,7 +111,7 @@ impl<D: for<'a> Device<'a>> FaultInjector<D> {
             rx_bucket: 0,
         };
         FaultInjector {
-            inner: inner,
+            inner,
             state: RefCell::new(state),
             config: Config::default(),
         }
@@ -219,14 +219,14 @@ where
         } = self;
         inner.receive().map(|(rx_token, tx_token)| {
             let rx = RxToken {
-                state: &state,
-                config: config,
+                state,
+                config,
                 token: rx_token,
                 corrupt: [0; MTU],
             };
             let tx = TxToken {
-                state: &state,
-                config: config,
+                state,
+                config,
                 token: tx_token,
                 junk: [0; MTU],
             };
@@ -241,9 +241,9 @@ where
             config,
         } = self;
         inner.transmit().map(|token| TxToken {
-            state: &state,
-            config: config,
-            token: token,
+            state,
+            config,
+            token,
             junk: [0; MTU],
         })
     }

+ 1 - 1
src/phy/pcap_writer.rs

@@ -229,7 +229,7 @@ impl<Tx: phy::TxToken, S: PcapSink> phy::TxToken for TxToken<Tx, S> {
         token.consume(timestamp, len, |buffer| {
             let result = f(buffer);
             match mode {
-                PcapMode::Both | PcapMode::TxOnly => sink.packet(timestamp, &buffer),
+                PcapMode::Both | PcapMode::TxOnly => sink.packet(timestamp, buffer),
                 PcapMode::RxOnly => (),
             };
             result

+ 1 - 1
src/phy/tracer.rs

@@ -171,7 +171,7 @@ impl<'a> fmt::Display for Packet<'a> {
                 &mut indent,
             ),
             #[cfg(feature = "medium-ip")]
-            Medium::Ip => match crate::wire::IpVersion::of_packet(&self.buffer) {
+            Medium::Ip => match crate::wire::IpVersion::of_packet(self.buffer) {
                 #[cfg(feature = "proto-ipv4")]
                 Ok(crate::wire::IpVersion::Ipv4) => {
                     crate::wire::Ipv4Packet::<&'static [u8]>::pretty_print(

+ 5 - 7
src/socket/dhcpv4.rs

@@ -307,13 +307,11 @@ impl Dhcpv4Socket {
         let mut dns_servers = [None; DHCP_MAX_DNS_SERVER_COUNT];
         if let Some(received) = dhcp_repr.dns_servers {
             let mut i = 0;
-            for addr in received.iter() {
-                if let Some(addr) = addr {
-                    if addr.is_unicast() {
-                        // This can never be out-of-bounds since both arrays have length DHCP_MAX_DNS_SERVER_COUNT
-                        dns_servers[i] = Some(*addr);
-                        i += 1;
-                    }
+            for addr in received.iter().flatten() {
+                if addr.is_unicast() {
+                    // This can never be out-of-bounds since both arrays have length DHCP_MAX_DNS_SERVER_COUNT
+                    dns_servers[i] = Some(*addr);
+                    i += 1;
                 }
             }
         }

+ 2 - 2
src/socket/set.rs

@@ -201,7 +201,7 @@ impl<'a, 'b: 'a> Iterator for Iter<'a, 'b> {
     type Item = &'a Socket<'b>;
 
     fn next(&mut self) -> Option<Self::Item> {
-        while let Some(item_opt) = self.lower.next() {
+        for item_opt in &mut self.lower {
             if let Some(item) = item_opt.as_ref() {
                 return Some(&item.socket);
             }
@@ -222,7 +222,7 @@ impl<'a, 'b: 'a> Iterator for IterMut<'a, 'b> {
     type Item = SocketRef<'a, Socket<'b>>;
 
     fn next(&mut self) -> Option<Self::Item> {
-        while let Some(item_opt) = self.lower.next() {
+        for item_opt in &mut self.lower {
             if let Some(item) = item_opt.as_mut() {
                 return Some(SocketRef::new(&mut item.socket));
             }

+ 1 - 1
src/socket/tcp.rs

@@ -1424,7 +1424,7 @@ impl<'a> TcpSocket<'a> {
                         ack_min,
                         ack_max
                     );
-                    return Ok(Some(self.ack_reply(ip_repr, &repr)));
+                    return Ok(Some(self.ack_reply(ip_repr, repr)));
                 }
             }
         }

+ 1 - 1
src/wire/icmpv4.rs

@@ -485,7 +485,7 @@ impl<'a> Repr<'a> {
                 let mut ip_packet = Ipv4Packet::new_unchecked(packet.data_mut());
                 header.emit(&mut ip_packet, checksum_caps);
                 let payload = &mut ip_packet.into_inner()[header.buffer_len()..];
-                payload.copy_from_slice(&data[..])
+                payload.copy_from_slice(data)
             }
         }
 

+ 5 - 5
src/wire/icmpv6.rs

@@ -657,7 +657,7 @@ impl<'a> Repr<'a> {
             let mut ip_packet = Ipv6Packet::new_unchecked(buffer);
             header.emit(&mut ip_packet);
             let payload = &mut ip_packet.into_inner()[header.buffer_len()..];
-            payload.copy_from_slice(&data[..]);
+            payload.copy_from_slice(data);
         }
 
         match *self {
@@ -669,7 +669,7 @@ impl<'a> Repr<'a> {
                 packet.set_msg_type(Message::DstUnreachable);
                 packet.set_msg_code(reason.into());
 
-                emit_contained_packet(packet.payload_mut(), header, &data);
+                emit_contained_packet(packet.payload_mut(), header, data);
             }
 
             Repr::PktTooBig { mtu, header, data } => {
@@ -677,7 +677,7 @@ impl<'a> Repr<'a> {
                 packet.set_msg_code(0);
                 packet.set_pkt_too_big_mtu(mtu);
 
-                emit_contained_packet(packet.payload_mut(), header, &data);
+                emit_contained_packet(packet.payload_mut(), header, data);
             }
 
             Repr::TimeExceeded {
@@ -688,7 +688,7 @@ impl<'a> Repr<'a> {
                 packet.set_msg_type(Message::TimeExceeded);
                 packet.set_msg_code(reason.into());
 
-                emit_contained_packet(packet.payload_mut(), header, &data);
+                emit_contained_packet(packet.payload_mut(), header, data);
             }
 
             Repr::ParamProblem {
@@ -701,7 +701,7 @@ impl<'a> Repr<'a> {
                 packet.set_msg_code(reason.into());
                 packet.set_param_problem_ptr(pointer);
 
-                emit_contained_packet(packet.payload_mut(), header, &data);
+                emit_contained_packet(packet.payload_mut(), header, data);
             }
 
             Repr::EchoRequest {

+ 3 - 3
src/wire/ip.rs

@@ -433,7 +433,7 @@ impl From<::std::net::SocketAddr> for Endpoint {
 impl From<::std::net::SocketAddrV4> for Endpoint {
     fn from(x: ::std::net::SocketAddrV4) -> Endpoint {
         Endpoint {
-            addr: x.ip().clone().into(),
+            addr: (*x.ip()).into(),
             port: x.port(),
         }
     }
@@ -443,7 +443,7 @@ impl From<::std::net::SocketAddrV4> for Endpoint {
 impl From<::std::net::SocketAddrV6> for Endpoint {
     fn from(x: ::std::net::SocketAddrV6) -> Endpoint {
         Endpoint {
-            addr: x.ip().clone().into(),
+            addr: (*x.ip()).into(),
             port: x.port(),
         }
     }
@@ -772,7 +772,7 @@ impl Repr {
         match *self {
             Repr::Unspecified { .. } => panic!("unspecified IP representation"),
             #[cfg(feature = "proto-ipv4")]
-            Repr::Ipv4(repr) => repr.emit(&mut Ipv4Packet::new_unchecked(buffer), &_checksum_caps),
+            Repr::Ipv4(repr) => repr.emit(&mut Ipv4Packet::new_unchecked(buffer), _checksum_caps),
             #[cfg(feature = "proto-ipv6")]
             Repr::Ipv6(repr) => repr.emit(&mut Ipv6Packet::new_unchecked(buffer)),
         }

+ 1 - 1
src/wire/ipv6.rs

@@ -168,7 +168,7 @@ impl Address {
         let idx = (mask as usize) / 8;
         let modulus = (mask as usize) % 8;
         let (first, second) = self.0.split_at(idx);
-        bytes[0..idx].copy_from_slice(&first);
+        bytes[0..idx].copy_from_slice(first);
         if idx < 16 {
             let part = second[0];
             bytes[idx] = part & (!(0xff >> modulus) as u8);