Bläddra i källkod

More clippy fixes.

Dario Nieuwenhuis 4 år sedan
förälder
incheckning
ac50995516
6 ändrade filer med 17 tillägg och 20 borttagningar
  1. 1 1
      src/iface/ethernet.rs
  2. 3 3
      src/parsers.rs
  3. 1 1
      src/socket/tcp.rs
  4. 7 4
      src/storage/assembler.rs
  5. 1 1
      src/storage/ring_buffer.rs
  6. 4 10
      src/wire/ipv6option.rs

+ 1 - 1
src/iface/ethernet.rs

@@ -1519,7 +1519,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
         }
     }
 
-    fn has_neighbor<'a>(&self, addr: &'a IpAddress, timestamp: Instant) -> bool {
+    fn has_neighbor(&self, addr: &IpAddress, timestamp: Instant) -> bool {
         match self.route(addr, timestamp) {
             Ok(routed_addr) => {
                 self.neighbor_cache

+ 3 - 3
src/parsers.rs

@@ -88,11 +88,11 @@ impl<'a> Parser<'a> {
 
     fn accept_digit(&mut self, hex: bool) -> Result<u8> {
         let digit = self.advance()?;
-        if digit >= b'0' && digit <= b'9' {
+        if (b'0'..=b'9').contains(&digit) {
             Ok(digit - b'0')
-        } else if hex && digit >= b'a' && digit <= b'f' {
+        } else if hex && (b'a'..=b'f').contains(&digit) {
             Ok(digit - b'a' + 10)
-        } else if hex && digit >= b'A' && digit <= b'F' {
+        } else if hex && (b'A'..=b'F').contains(&digit) {
             Ok(digit - b'A' + 10)
         } else {
             Err(())

+ 1 - 1
src/socket/tcp.rs

@@ -1416,7 +1416,7 @@ impl<'a> TcpSocket<'a> {
                            payload_len, payload_offset);
                 self.rx_buffer.write_unallocated(payload_offset, repr.payload);
             }
-            Err(()) => {
+            Err(_) => {
                 net_debug!("{}:{}:{}: assembler: too many holes to add {} octets at offset {}",
                            self.meta.handle, self.local_endpoint, self.remote_endpoint,
                            payload_len, payload_offset);

+ 7 - 4
src/storage/assembler.rs

@@ -1,5 +1,8 @@
 use core::fmt;
 
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct TooManyHolesError;
+
 /// A contiguous chunk of absent data, followed by a contiguous chunk of present data.
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 struct Contig {
@@ -148,10 +151,10 @@ impl Assembler {
     }
 
     /// Add a contig at the given index, and return a pointer to it.
-    fn add_contig_at(&mut self, at: usize) -> Result<&mut Contig, ()> {
+    fn add_contig_at(&mut self, at: usize) -> Result<&mut Contig, TooManyHolesError> {
         debug_assert!(!self.contigs[at].is_empty());
 
-        if !self.back().is_empty() { return Err(()) }
+        if !self.back().is_empty() { return Err(TooManyHolesError) }
 
         for i in (at + 1..self.contigs.len()).rev() {
             self.contigs[i] = self.contigs[i - 1];
@@ -163,7 +166,7 @@ impl Assembler {
 
     /// Add a new contiguous range to the assembler, and return `Ok(())`,
     /// or return `Err(())` if too many discontiguities are already recorded.
-    pub fn add(&mut self, mut offset: usize, mut size: usize) -> Result<(), ()> {
+    pub fn add(&mut self, mut offset: usize, mut size: usize) -> Result<(), TooManyHolesError> {
         let mut index = 0;
         while index != self.contigs.len() && size != 0 {
             let contig = self.contigs[index];
@@ -413,7 +416,7 @@ mod test {
         }
         // Maximum of allowed holes is reached
         let assr_before = assr.clone();
-        assert_eq!(assr.add(1, 3), Err(()));
+        assert_eq!(assr.add(1, 3), Err(TooManyHolesError));
         assert_eq!(assr_before, assr);
     }
 

+ 1 - 1
src/storage/ring_buffer.rs

@@ -129,7 +129,7 @@ impl<'a, T: 'a> RingBuffer<'a, T> {
     /// or return `Err(Error::Exhausted)` if the buffer is full.
     ///
     /// This function is a shortcut for `ring_buf.enqueue_one_with(Ok)`.
-    pub fn enqueue_one<'b>(&'b mut self) -> Result<&'b mut T> {
+    pub fn enqueue_one(&mut self) -> Result<&mut T> {
         self.enqueue_one_with(Ok)
     }
 

+ 4 - 10
src/wire/ipv6option.rs

@@ -307,14 +307,6 @@ impl<'a> Ipv6OptionsIterator<'a> {
             length, data
         }
     }
-
-    /// Helper function to return an error in the implementation
-    /// of `Iterator`.
-    #[inline]
-    fn return_err(&mut self, err: Error) -> Option<Result<Repr<'a>>> {
-        self.hit_error = true;
-        Some(Err(err))
-    }
 }
 
 impl<'a> Iterator for Ipv6OptionsIterator<'a> {
@@ -332,12 +324,14 @@ impl<'a> Iterator for Ipv6OptionsIterator<'a> {
                             Some(Ok(repr))
                         }
                         Err(e) => {
-                            self.return_err(e)
+                            self.hit_error = true;
+                            Some(Err(e))
                         }
                     }
                 }
                 Err(e) => {
-                    self.return_err(e)
+                    self.hit_error = true;
+                    Some(Err(e))
                 }
             }
         } else {