Bläddra i källkod

Fix clippy warnings.

Jing Yang 4 år sedan
förälder
incheckning
983ef530f5
2 ändrade filer med 8 tillägg och 7 borttagningar
  1. 7 5
      src/election.rs
  2. 1 2
      src/log_array.rs

+ 7 - 5
src/election.rs

@@ -129,9 +129,10 @@ where
 
             let mut should_run = None;
             while this.keep_running.load(Ordering::SeqCst) {
-                let mut cancel_handle = should_run
-                    .map(|last_timer_count| this.run_election(last_timer_count))
-                    .flatten();
+                let mut cancel_handle =
+                    should_run.and_then(|last_timer_count| {
+                        this.run_election(last_timer_count)
+                    });
 
                 let mut guard = election.timer.lock();
                 let (timer_count, deadline) = *guard;
@@ -147,10 +148,11 @@ where
                 // by the election, and then reset by someone else, in that
                 // order. We should cancel the election and just wait.
                 if let Some(last_timer_count) = should_run {
-                    assert!(timer_count >= last_timer_count + 1);
+                    let expected_timer_count = last_timer_count + 1;
+                    assert!(timer_count >= expected_timer_count);
                     // If the timer was changed more than once, we know the
                     // last scheduled election should have been cancelled.
-                    if timer_count > last_timer_count + 1 {
+                    if timer_count > expected_timer_count {
                         cancel_handle.take().map(|c| c.send(()));
                     }
                 }

+ 1 - 2
src/log_array.rs

@@ -238,8 +238,7 @@ impl<C> LogArray<C> {
     }
 
     fn last_entry(&self) -> &LogEntry<C> {
-        &self
-            .inner
+        self.inner
             .last()
             .expect("There must be at least one entry in log")
     }