summaryrefslogtreecommitdiffstats
path: root/tokio
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-11-05 23:38:52 -0800
committerGitHub <noreply@github.com>2019-11-05 23:38:52 -0800
commit0da23aad772afb22db8edf73ac0f034c5ada3bde (patch)
treeacebe4125a39a5ee81815b19587ffad400559bb8 /tokio
parentd5c1119c881c9a8b511aa9000fd26b9bda014256 (diff)
fix clippy (#1737)
Diffstat (limited to 'tokio')
-rw-r--r--tokio/src/io/async_read.rs5
-rw-r--r--tokio/src/process/mod.rs2
-rw-r--r--tokio/src/runtime/current_thread/mod.rs2
-rw-r--r--tokio/src/runtime/thread_pool/worker.rs6
-rw-r--r--tokio/src/sync/watch.rs3
-rw-r--r--tokio/src/timer/wheel/mod.rs29
6 files changed, 25 insertions, 22 deletions
diff --git a/tokio/src/io/async_read.rs b/tokio/src/io/async_read.rs
index 2bccb17f..8f6e0b98 100644
--- a/tokio/src/io/async_read.rs
+++ b/tokio/src/io/async_read.rs
@@ -57,6 +57,11 @@ pub trait AsyncRead {
///
/// This function is called from [`poll_read_buf`].
///
+ /// # Safety
+ ///
+ /// Implementations that return `false` must never read from data slices
+ /// that they did not write to.
+ ///
/// [`io::Read`]: std::io::Read
/// [`poll_read_buf`]: #method.poll_read_buf
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
diff --git a/tokio/src/process/mod.rs b/tokio/src/process/mod.rs
index 3728c6cc..251d2ada 100644
--- a/tokio/src/process/mod.rs
+++ b/tokio/src/process/mod.rs
@@ -479,7 +479,7 @@ impl Command {
/// will be called and the spawn operation will immediately return with a
/// failure.
///
- /// # Notes and Safety
+ /// # Safety
///
/// This closure will be run in the context of the child process after a
/// `fork`. This primarily means that any modifications made to memory on
diff --git a/tokio/src/runtime/current_thread/mod.rs b/tokio/src/runtime/current_thread/mod.rs
index d63b4ccf..6c5fdda8 100644
--- a/tokio/src/runtime/current_thread/mod.rs
+++ b/tokio/src/runtime/current_thread/mod.rs
@@ -337,6 +337,8 @@ impl fmt::Debug for Scheduler {
unsafe fn sched_clone_waker(ptr: *const ()) -> RawWaker {
let s1 = ManuallyDrop::new(Arc::from_raw(ptr as *const Scheduler));
+
+ #[allow(clippy::redundant_clone)]
let s2 = s1.clone();
RawWaker::new(
diff --git a/tokio/src/runtime/thread_pool/worker.rs b/tokio/src/runtime/thread_pool/worker.rs
index 462fb2e8..986f4534 100644
--- a/tokio/src/runtime/thread_pool/worker.rs
+++ b/tokio/src/runtime/thread_pool/worker.rs
@@ -358,8 +358,6 @@ where
park: &mut impl Park<Unpark = P>,
gone: &Cell<bool>,
) -> Result<bool, WorkerGone> {
- debug_assert!(self.is_running());
-
loop {
let tick = self.tick_fetch_inc();
@@ -412,8 +410,6 @@ where
}
fn search_for_work(&mut self, gone: &Cell<bool>) -> Result<bool, WorkerGone> {
- debug_assert!(self.is_searching());
-
if let Some(task) = self.steal_work() {
self.run_task(task, gone)?;
Ok(true)
@@ -435,8 +431,6 @@ where
}
fn transition_from_searching(&mut self) {
- debug_assert!(self.is_searching());
-
self.owned().is_searching.set(false);
if self.set().idle().transition_worker_from_searching() {
diff --git a/tokio/src/sync/watch.rs b/tokio/src/sync/watch.rs
index 30f1603f..928c2c46 100644
--- a/tokio/src/sync/watch.rs
+++ b/tokio/src/sync/watch.rs
@@ -298,7 +298,6 @@ impl<T: Clone> Receiver<T> {
impl<T: Clone> futures_core::Stream for Receiver<T> {
type Item = T;
- #[allow(clippy::map_clone)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3274
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T>> {
use std::future::Future;
@@ -306,7 +305,7 @@ impl<T: Clone> futures_core::Stream for Receiver<T> {
pin_mut!(fut);
let item = ready!(fut.poll(cx));
- Ready(item.map(|v_ref| v_ref.clone()))
+ Ready(item.map(|v_ref| v_ref))
}
}
diff --git a/tokio/src/timer/wheel/mod.rs b/tokio/src/timer/wheel/mod.rs
index 6cac2a8e..c5f0f458 100644
--- a/tokio/src/timer/wheel/mod.rs
+++ b/tokio/src/timer/wheel/mod.rs
@@ -173,19 +173,7 @@ where
if let Some(expiration) = self.levels[level].next_expiration(self.elapsed) {
// There cannot be any expirations at a higher level that happen
// before this one.
- debug_assert!({
- let mut res = true;
-
- for l2 in (level + 1)..NUM_LEVELS {
- if let Some(e2) = self.levels[l2].next_expiration(self.elapsed) {
- if e2.deadline < expiration.deadline {
- res = false;
- }
- }
- }
-
- res
- });
+ debug_assert!(self.no_expirations_before(level + 1, expiration.deadline));
return Some(expiration);
}
@@ -194,6 +182,21 @@ where
None
}
+ /// Used for debug assertions
+ fn no_expirations_before(&self, start_level: usize, before: u64) -> bool {
+ let mut res = true;
+
+ for l2 in start_level..NUM_LEVELS {
+ if let Some(e2) = self.levels[l2].next_expiration(self.elapsed) {
+ if e2.deadline < before {
+ res = false;
+ }
+ }
+ }
+
+ res
+ }
+
pub(crate) fn poll_expiration(
&mut self,
expiration: &Expiration,