diff --git a/tokio-buf/src/lib.rs b/tokio-buf/src/lib.rs index 1d63c2034..0b45a376c 100644 --- a/tokio-buf/src/lib.rs +++ b/tokio-buf/src/lib.rs @@ -1,9 +1,9 @@ #![doc(html_root_url = "https://docs.rs/tokio-buf/0.2.0-alpha.1")] #![warn( - missing_docs, missing_debug_implementations, - unreachable_pub, - rust_2018_idioms + missing_docs, + rust_2018_idioms, + unreachable_pub )] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] diff --git a/tokio-codec/src/framed.rs b/tokio-codec/src/framed.rs index da131ee15..ac733d59f 100644 --- a/tokio-codec/src/framed.rs +++ b/tokio-codec/src/framed.rs @@ -23,7 +23,7 @@ pub struct Framed { inner: FramedRead2>>, } -pub struct Fuse(pub T, pub U); +pub(crate) struct Fuse(pub(crate) T, pub(crate) U); impl Framed where diff --git a/tokio-codec/src/framed_read.rs b/tokio-codec/src/framed_read.rs index 25fc26b41..85f221b9a 100644 --- a/tokio-codec/src/framed_read.rs +++ b/tokio-codec/src/framed_read.rs @@ -16,7 +16,7 @@ pub struct FramedRead { inner: FramedRead2>, } -pub struct FramedRead2 { +pub(crate) struct FramedRead2 { inner: T, eof: bool, is_readable: bool, @@ -136,7 +136,7 @@ where // ===== impl FramedRead2 ===== -pub fn framed_read2(inner: T) -> FramedRead2 { +pub(crate) fn framed_read2(inner: T) -> FramedRead2 { FramedRead2 { inner, eof: false, @@ -145,7 +145,7 @@ pub fn framed_read2(inner: T) -> FramedRead2 { } } -pub fn framed_read2_with_buffer(inner: T, mut buf: BytesMut) -> FramedRead2 { +pub(crate) fn framed_read2_with_buffer(inner: T, mut buf: BytesMut) -> FramedRead2 { if buf.capacity() < INITIAL_CAPACITY { let bytes_to_reserve = INITIAL_CAPACITY - buf.capacity(); buf.reserve(bytes_to_reserve); @@ -159,19 +159,19 @@ pub fn framed_read2_with_buffer(inner: T, mut buf: BytesMut) -> FramedRead2 FramedRead2 { - pub fn get_ref(&self) -> &T { + pub(crate) fn get_ref(&self) -> &T { &self.inner } - pub fn into_inner(self) -> T { + pub(crate) fn into_inner(self) -> T { self.inner } - pub fn into_parts(self) -> (T, BytesMut) { + pub(crate) fn into_parts(self) -> (T, BytesMut) { (self.inner, self.buffer) } - pub fn get_mut(&mut self) -> &mut T { + pub(crate) fn get_mut(&mut self) -> &mut T { &mut self.inner } } diff --git a/tokio-codec/src/framed_write.rs b/tokio-codec/src/framed_write.rs index 0ea45b5cc..f89e46112 100644 --- a/tokio-codec/src/framed_write.rs +++ b/tokio-codec/src/framed_write.rs @@ -20,7 +20,7 @@ pub struct FramedWrite { inner: FramedWrite2>, } -pub struct FramedWrite2 { +pub(crate) struct FramedWrite2 { inner: T, buffer: BytesMut, } @@ -136,14 +136,14 @@ where // ===== impl FramedWrite2 ===== -pub fn framed_write2(inner: T) -> FramedWrite2 { +pub(crate) fn framed_write2(inner: T) -> FramedWrite2 { FramedWrite2 { inner, buffer: BytesMut::with_capacity(INITIAL_CAPACITY), } } -pub fn framed_write2_with_buffer(inner: T, mut buf: BytesMut) -> FramedWrite2 { +pub(crate) fn framed_write2_with_buffer(inner: T, mut buf: BytesMut) -> FramedWrite2 { if buf.capacity() < INITIAL_CAPACITY { let bytes_to_reserve = INITIAL_CAPACITY - buf.capacity(); buf.reserve(bytes_to_reserve); @@ -152,19 +152,19 @@ pub fn framed_write2_with_buffer(inner: T, mut buf: BytesMut) -> FramedWrite2 } impl FramedWrite2 { - pub fn get_ref(&self) -> &T { + pub(crate) fn get_ref(&self) -> &T { &self.inner } - pub fn into_inner(self) -> T { + pub(crate) fn into_inner(self) -> T { self.inner } - pub fn into_parts(self) -> (T, BytesMut) { + pub(crate) fn into_parts(self) -> (T, BytesMut) { (self.inner, self.buffer) } - pub fn get_mut(&mut self) -> &mut T { + pub(crate) fn get_mut(&mut self) -> &mut T { &mut self.inner } } diff --git a/tokio-codec/src/lib.rs b/tokio-codec/src/lib.rs index 8e1802b8b..b4f4a67c1 100644 --- a/tokio-codec/src/lib.rs +++ b/tokio-codec/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-codec/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Utilities for encoding and decoding frames. diff --git a/tokio-current-thread/src/lib.rs b/tokio-current-thread/src/lib.rs index f22fb70e4..771ff4f44 100644 --- a/tokio-current-thread/src/lib.rs +++ b/tokio-current-thread/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-current-thread/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! A single-threaded executor which executes tasks on the same thread from which diff --git a/tokio-current-thread/src/scheduler.rs b/tokio-current-thread/src/scheduler.rs index 06ad2aa62..d53984eb6 100644 --- a/tokio-current-thread/src/scheduler.rs +++ b/tokio-current-thread/src/scheduler.rs @@ -16,7 +16,7 @@ use tokio_executor::park::Unpark; /// A generic task-aware scheduler. /// /// This is used both by `FuturesUnordered` and the current-thread executor. -pub struct Scheduler { +pub(crate) struct Scheduler { inner: Arc>, nodes: List, } @@ -117,7 +117,7 @@ enum Dequeue { struct Task(Pin>>); /// A task that is scheduled. `turn` must be called -pub struct Scheduled<'a, U> { +pub(crate) struct Scheduled<'a, U> { task: &'a mut Task, node: &'a Arc>, done: &'a mut bool, @@ -131,7 +131,7 @@ where /// /// The returned `Scheduler` does not contain any items and, in this /// state, `Scheduler::poll` will return `Ok(Async::Ready(None))`. - pub fn new(unpark: U) -> Self { + pub(crate) fn new(unpark: U) -> Self { let stub = Arc::new(Node { item: UnsafeCell::new(None), notified_at: AtomicUsize::new(0), @@ -156,11 +156,11 @@ where } } - pub fn waker(&self) -> Waker { + pub(crate) fn waker(&self) -> Waker { waker_inner(self.inner.clone()) } - pub fn schedule(&mut self, item: Pin>>) { + pub(crate) fn schedule(&mut self, item: Pin>>) { // Get the current scheduler tick let tick_num = self.inner.tick_num.load(SeqCst); @@ -187,7 +187,7 @@ where } /// Returns `true` if there are currently any pending futures - pub fn has_pending_futures(&mut self) -> bool { + pub(crate) fn has_pending_futures(&mut self) -> bool { // See function definition for why the unsafe is needed and // correctly used here unsafe { self.inner.has_pending_futures() } @@ -198,7 +198,7 @@ where /// /// This function should be called whenever the caller is notified via a /// wakeup. - pub fn tick(&mut self, eid: u64, num_futures: &AtomicUsize) -> bool { + pub(crate) fn tick(&mut self, eid: u64, num_futures: &AtomicUsize) -> bool { let mut ret = false; let tick = self.inner.tick_num.fetch_add(1, SeqCst).wrapping_add(1); @@ -331,7 +331,7 @@ where impl Scheduled<'_, U> { /// Polls the task, returns `true` if the task has completed. - pub fn tick(&mut self) -> bool { + pub(crate) fn tick(&mut self) -> bool { let waker = unsafe { // Safety: we don't hold this waker ref longer than // this `tick` function @@ -349,7 +349,7 @@ impl Scheduled<'_, U> { } impl Task { - pub fn new(future: Pin + 'static>>) -> Self { + pub(crate) fn new(future: Pin + 'static>>) -> Self { Task(future) } } diff --git a/tokio-executor/src/lib.rs b/tokio-executor/src/lib.rs index aceb6efe3..8f15d603e 100644 --- a/tokio-executor/src/lib.rs +++ b/tokio-executor/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-executor/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Task execution related traits and utilities. diff --git a/tokio-executor/src/park.rs b/tokio-executor/src/park.rs index 0770c50b7..86876654b 100644 --- a/tokio-executor/src/park.rs +++ b/tokio-executor/src/park.rs @@ -194,7 +194,7 @@ thread_local! { // ==== impl Parker ==== impl Parker { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { unparker: Arc::new(Inner { state: AtomicUsize::new(IDLE), @@ -204,15 +204,15 @@ impl Parker { } } - pub fn unparker(&self) -> &Arc { + pub(crate) fn unparker(&self) -> &Arc { &self.unparker } - pub fn park(&self) -> Result<(), ParkError> { + pub(crate) fn park(&self) -> Result<(), ParkError> { self.unparker.park(None) } - pub fn park_timeout(&self, timeout: Duration) -> Result<(), ParkError> { + pub(crate) fn park_timeout(&self, timeout: Duration) -> Result<(), ParkError> { self.unparker.park(Some(timeout)) } } @@ -221,16 +221,16 @@ impl Parker { impl Inner { #[allow(clippy::wrong_self_convention)] - pub fn into_raw(this: Arc) -> *const () { + pub(crate) fn into_raw(this: Arc) -> *const () { Arc::into_raw(this) as *const () } - pub unsafe fn from_raw(ptr: *const ()) -> Arc { + pub(crate) unsafe fn from_raw(ptr: *const ()) -> Arc { Arc::from_raw(ptr as *const Inner) } /// Park the current thread for at most `dur`. - pub fn park(&self, timeout: Option) -> Result<(), ParkError> { + pub(crate) fn park(&self, timeout: Option) -> Result<(), ParkError> { // If currently notified, then we skip sleeping. This is checked outside // of the lock to avoid acquiring a mutex if not necessary. match self.state.compare_and_swap(NOTIFY, IDLE, Ordering::SeqCst) { @@ -272,7 +272,7 @@ impl Inner { Ok(()) } - pub fn unpark(&self) { + pub(crate) fn unpark(&self) { // First, try transitioning from IDLE -> NOTIFY, this does not require a // lock. match self.state.compare_and_swap(IDLE, NOTIFY, Ordering::SeqCst) { diff --git a/tokio-fs/src/lib.rs b/tokio-fs/src/lib.rs index 46387e1c8..341502dc7 100644 --- a/tokio-fs/src/lib.rs +++ b/tokio-fs/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-fs/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] diff --git a/tokio-io/src/io/mod.rs b/tokio-io/src/io/mod.rs index 0b0f24fab..71904c1fe 100644 --- a/tokio-io/src/io/mod.rs +++ b/tokio-io/src/io/mod.rs @@ -52,6 +52,9 @@ mod shutdown; mod write; mod write_all; +#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 pub use self::async_buf_read_ext::AsyncBufReadExt; +#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 pub use self::async_read_ext::AsyncReadExt; +#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 pub use self::async_write_ext::AsyncWriteExt; diff --git a/tokio-io/src/lib.rs b/tokio-io/src/lib.rs index 67918b0b3..df7ffdef1 100644 --- a/tokio-io/src/lib.rs +++ b/tokio-io/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-io/0.2.0-alpha.1")] -#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Core I/O traits and combinators when working with Tokio. diff --git a/tokio-macros/src/lib.rs b/tokio-macros/src/lib.rs index 1d14f5ea6..7f1144f9e 100644 --- a/tokio-macros/src/lib.rs +++ b/tokio-macros/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-macros/0.2.0-alpha.1")] -#![warn(missing_debug_implementations, unreachable_pub, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Macros for use with Tokio diff --git a/tokio-process/src/lib.rs b/tokio-process/src/lib.rs index 31018ffec..d05b0ed27 100644 --- a/tokio-process/src/lib.rs +++ b/tokio-process/src/lib.rs @@ -1,4 +1,12 @@ #![doc(html_root_url = "https://docs.rs/tokio-process/0.3.0-alpha.1")] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] +#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] +#![feature(async_await)] //! An implementation of asynchronous process management for Tokio. //! @@ -117,11 +125,6 @@ //! `tokio_process::Child` is dropped. The behavior of the standard library can //! be regained with the `Child::forget` method. -#![doc(html_root_url = "https://docs.rs/tokio-process/0.3.0")] -#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)] -#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] -#![feature(async_await)] - #[cfg(unix)] #[macro_use] extern crate lazy_static; diff --git a/tokio-process/src/unix/mod.rs b/tokio-process/src/unix/mod.rs index 434f2d234..55497cad9 100644 --- a/tokio-process/src/unix/mod.rs +++ b/tokio-process/src/unix/mod.rs @@ -81,7 +81,7 @@ impl OrphanQueue for GlobalOrphanQueue { } #[must_use = "futures do nothing unless polled"] -pub struct Child { +pub(crate) struct Child { inner: Reaper, } @@ -112,7 +112,7 @@ pub(crate) fn spawn_child(cmd: &mut process::Command, handle: &Handle) -> io::Re } impl Child { - pub fn id(&self) -> u32 { + pub(crate) fn id(&self) -> u32 { self.inner.id() } } @@ -132,7 +132,7 @@ impl Future for Child { } #[derive(Debug)] -pub struct Fd { +pub(crate) struct Fd { inner: T, } @@ -196,9 +196,9 @@ where } } -pub type ChildStdin = PollEvented>; -pub type ChildStdout = PollEvented>; -pub type ChildStderr = PollEvented>; +pub(crate) type ChildStdin = PollEvented>; +pub(crate) type ChildStdout = PollEvented>; +pub(crate) type ChildStderr = PollEvented>; fn stdio(option: Option, handle: &Handle) -> io::Result>>> where diff --git a/tokio-process/src/windows.rs b/tokio-process/src/windows.rs index 236ea471e..f3afd44ec 100644 --- a/tokio-process/src/windows.rs +++ b/tokio-process/src/windows.rs @@ -45,7 +45,7 @@ use winapi::um::winbase::*; use winapi::um::winnt::*; #[must_use = "futures do nothing unless polled"] -pub struct Child { +pub(crate) struct Child { child: process::Child, waiting: Option, } @@ -87,7 +87,7 @@ pub(crate) fn spawn_child(cmd: &mut process::Command, handle: &Handle) -> io::Re } impl Child { - pub fn id(&self) -> u32 { + pub(crate) fn id(&self) -> u32 { self.child.id() } } @@ -161,7 +161,7 @@ unsafe extern "system" fn callback(ptr: PVOID, _timer_fired: BOOLEAN) { let _ = complete.take().unwrap().send(()); } -pub fn try_wait(child: &process::Child) -> io::Result> { +pub(crate) fn try_wait(child: &process::Child) -> io::Result> { unsafe { match WaitForSingleObject(child.as_raw_handle(), 0) { WAIT_OBJECT_0 => {} @@ -178,9 +178,9 @@ pub fn try_wait(child: &process::Child) -> io::Result> { } } -pub type ChildStdin = PollEvented; -pub type ChildStdout = PollEvented; -pub type ChildStderr = PollEvented; +pub(crate) type ChildStdin = PollEvented; +pub(crate) type ChildStdout = PollEvented; +pub(crate) type ChildStderr = PollEvented; fn stdio(option: Option, handle: &Handle) -> io::Result>> where diff --git a/tokio-reactor/src/lib.rs b/tokio-reactor/src/lib.rs index d583b1d04..bace8128f 100644 --- a/tokio-reactor/src/lib.rs +++ b/tokio-reactor/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-reactor/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Event loop that drives Tokio I/O resources. @@ -585,11 +590,11 @@ mod platform { use mio::unix::UnixReady; use mio::Ready; - pub fn hup() -> Ready { + pub(crate) fn hup() -> Ready { UnixReady::hup().into() } - pub fn is_hup(ready: Ready) -> bool { + pub(crate) fn is_hup(ready: Ready) -> bool { UnixReady::from(ready).is_hup() } } @@ -598,11 +603,11 @@ mod platform { mod platform { use mio::Ready; - pub fn hup() -> Ready { + pub(crate) fn hup() -> Ready { Ready::empty() } - pub fn is_hup(_: Ready) -> bool { + pub(crate) fn is_hup(_: Ready) -> bool { false } } diff --git a/tokio-reactor/src/sharded_rwlock.rs b/tokio-reactor/src/sharded_rwlock.rs index ec16fb13c..678924812 100644 --- a/tokio-reactor/src/sharded_rwlock.rs +++ b/tokio-reactor/src/sharded_rwlock.rs @@ -30,7 +30,7 @@ use std::thread::{self, ThreadId}; /// Read operations lock only one shard specific to the current thread, while write operations lock /// every shard in succession. This strategy makes concurrent read operations faster due to less /// contention, but write operations are slower due to increased amount of locking. -pub struct RwLock { +pub(crate) struct RwLock { /// A list of locks protecting the internal data. shards: Vec>>, @@ -43,7 +43,7 @@ unsafe impl Sync for RwLock {} impl RwLock { /// Creates a new `RwLock` initialized with `value`. - pub fn new(value: T) -> RwLock { + pub(crate) fn new(value: T) -> RwLock { // The number of shards is a power of two so that the modulo operation in `read` becomes a // simple bitwise "and". let num_shards = num_cpus::get().next_power_of_two(); @@ -65,7 +65,7 @@ impl RwLock { /// or writers will acquire the lock first. /// /// Returns an RAII guard which will release this thread's shared access once it is dropped. - pub fn read(&self) -> RwLockReadGuard<'_, T> { + pub(crate) fn read(&self) -> RwLockReadGuard<'_, T> { // Take the current thread index and map it to a shard index. Thread indices will tend to // distribute shards among threads equally, thus reducing contention due to read-locking. let shard_index = thread_index() & (self.shards.len() - 1); @@ -84,7 +84,7 @@ impl RwLock { /// the lock. /// /// Returns an RAII guard which will drop the write access of this rwlock when dropped. - pub fn write(&self) -> RwLockWriteGuard<'_, T> { + pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> { // Write-lock each shard in succession. for shard in &self.shards { // The write guard is forgotten, but the lock will be manually unlocked in `drop`. @@ -99,7 +99,7 @@ impl RwLock { } /// A guard used to release the shared read access of a `RwLock` when dropped. -pub struct RwLockReadGuard<'a, T> { +pub(crate) struct RwLockReadGuard<'a, T> { parent: &'a RwLock, _guard: parking_lot::RwLockReadGuard<'a, ()>, _marker: PhantomData>, @@ -116,7 +116,7 @@ impl<'a, T> Deref for RwLockReadGuard<'a, T> { } /// A guard used to release the exclusive write access of a `RwLock` when dropped. -pub struct RwLockWriteGuard<'a, T> { +pub(crate) struct RwLockWriteGuard<'a, T> { parent: &'a RwLock, _marker: PhantomData>, } @@ -154,7 +154,7 @@ impl<'a, T> DerefMut for RwLockWriteGuard<'a, T> { /// between 0 and the number of running threads, but there are no guarantees. During TLS teardown /// the associated index might change. #[inline] -pub fn thread_index() -> usize { +pub(crate) fn thread_index() -> usize { REGISTRATION.try_with(|reg| reg.index).unwrap_or(0) } diff --git a/tokio-signal/src/lib.rs b/tokio-signal/src/lib.rs index f7715a77b..36f265cfe 100644 --- a/tokio-signal/src/lib.rs +++ b/tokio-signal/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-signal/0.3.0-alpha.1")] -#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![cfg_attr(test, feature(async_await))] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] diff --git a/tokio-sync/src/lib.rs b/tokio-sync/src/lib.rs index be71a3e43..3e4f07b16 100644 --- a/tokio-sync/src/lib.rs +++ b/tokio-sync/src/lib.rs @@ -2,8 +2,8 @@ #![warn( missing_debug_implementations, missing_docs, - unreachable_pub, - rust_2018_idioms + rust_2018_idioms, + unreachable_pub )] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] diff --git a/tokio-tcp/src/lib.rs b/tokio-tcp/src/lib.rs index 1e8ca2f50..bcca739f0 100644 --- a/tokio-tcp/src/lib.rs +++ b/tokio-tcp/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-tcp/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] diff --git a/tokio-test/src/lib.rs b/tokio-test/src/lib.rs index 4d8539bd4..6e6a82ad4 100644 --- a/tokio-test/src/lib.rs +++ b/tokio-test/src/lib.rs @@ -1,9 +1,9 @@ #![doc(html_root_url = "https://docs.rs/tokio-test/0.2.0-alpha.1")] #![warn( - missing_docs, missing_debug_implementations, - unreachable_pub, - rust_2018_idioms + missing_docs, + rust_2018_idioms, + unreachable_pub )] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] diff --git a/tokio-threadpool/src/callback.rs b/tokio-threadpool/src/callback.rs index fe28ed712..b9d101615 100644 --- a/tokio-threadpool/src/callback.rs +++ b/tokio-threadpool/src/callback.rs @@ -8,14 +8,14 @@ pub(crate) struct Callback { } impl Callback { - pub fn new(f: F) -> Self + pub(crate) fn new(f: F) -> Self where F: Fn(&Worker) + Send + Sync + 'static, { Callback { f: Arc::new(f) } } - pub fn call(&self, worker: &Worker) { + pub(crate) fn call(&self, worker: &Worker) { (self.f)(worker) } } diff --git a/tokio-threadpool/src/config.rs b/tokio-threadpool/src/config.rs index 31a951cec..e92d2c607 100644 --- a/tokio-threadpool/src/config.rs +++ b/tokio-threadpool/src/config.rs @@ -7,14 +7,14 @@ use std::time::Duration; /// Thread pool specific configuration values #[derive(Clone)] pub(crate) struct Config { - pub keep_alive: Option, + pub(crate) keep_alive: Option, // Used to configure a worker thread - pub name_prefix: Option, - pub stack_size: Option, - pub around_worker: Option, - pub after_start: Option>, - pub before_stop: Option>, - pub panic_handler: Option, + pub(crate) name_prefix: Option, + pub(crate) stack_size: Option, + pub(crate) around_worker: Option, + pub(crate) after_start: Option>, + pub(crate) before_stop: Option>, + pub(crate) panic_handler: Option, } // Define type alias to avoid clippy::type_complexity. diff --git a/tokio-threadpool/src/lib.rs b/tokio-threadpool/src/lib.rs index 745e46c47..0ce42b6c1 100644 --- a/tokio-threadpool/src/lib.rs +++ b/tokio-threadpool/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-threadpool/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! A work-stealing based thread pool for executing futures. diff --git a/tokio-threadpool/src/park/boxed.rs b/tokio-threadpool/src/park/boxed.rs index d4daf8333..6893c2f23 100644 --- a/tokio-threadpool/src/park/boxed.rs +++ b/tokio-threadpool/src/park/boxed.rs @@ -9,7 +9,7 @@ pub(crate) type BoxUnpark = Box; pub(crate) struct BoxedPark(T); impl BoxedPark { - pub fn new(inner: T) -> Self { + pub(crate) fn new(inner: T) -> Self { BoxedPark(inner) } } diff --git a/tokio-threadpool/src/pool/backup.rs b/tokio-threadpool/src/pool/backup.rs index bba3a4f5c..dc2aadea3 100644 --- a/tokio-threadpool/src/pool/backup.rs +++ b/tokio-threadpool/src/pool/backup.rs @@ -67,18 +67,18 @@ struct State(usize); /// This flag also serves as a "notification" bit. If another thread is /// attempting to hand off a worker to the backup thread, then the pushed bit /// will not be set when the thread tries to shutdown. -pub const PUSHED: usize = 0b001; +pub(crate) const PUSHED: usize = 0b001; /// Set when the thread is running -pub const RUNNING: usize = 0b010; +pub(crate) const RUNNING: usize = 0b010; /// Set when the thread pool has terminated -pub const TERMINATED: usize = 0b100; +pub(crate) const TERMINATED: usize = 0b100; // ===== impl Backup ===== impl Backup { - pub fn new() -> Backup { + pub(crate) fn new() -> Backup { Backup { handoff: UnsafeCell::new(None), state: AtomicUsize::new(State::new().into()), @@ -88,7 +88,7 @@ impl Backup { } /// Called when the thread is starting - pub fn start(&self, worker_id: &WorkerId) { + pub(crate) fn start(&self, worker_id: &WorkerId) { debug_assert!({ let state: State = self.state.load(Relaxed).into(); @@ -107,7 +107,7 @@ impl Backup { } } - pub fn is_running(&self) -> bool { + pub(crate) fn is_running(&self) -> bool { let state: State = self.state.load(Relaxed).into(); state.is_running() } @@ -115,7 +115,7 @@ impl Backup { /// Hands off the worker to a thread. /// /// Returns `true` if the thread needs to be spawned. - pub fn worker_handoff(&self, worker_id: WorkerId) -> bool { + pub(crate) fn worker_handoff(&self, worker_id: WorkerId) -> bool { unsafe { // The backup worker should not already have been handoff a worker. debug_assert!((*self.handoff.get()).is_none()); @@ -139,7 +139,7 @@ impl Backup { } /// Terminate the worker - pub fn signal_stop(&self) { + pub(crate) fn signal_stop(&self) { let prev: State = self.state.fetch_xor(TERMINATED | PUSHED, AcqRel).into(); debug_assert!(!prev.is_terminated()); @@ -151,14 +151,14 @@ impl Backup { } /// Release the worker - pub fn release(&self) { + pub(crate) fn release(&self) { let prev: State = self.state.fetch_xor(RUNNING, AcqRel).into(); debug_assert!(prev.is_running()); } /// Wait for a worker handoff - pub fn wait_for_handoff(&self, timeout: Option) -> Handoff { + pub(crate) fn wait_for_handoff(&self, timeout: Option) -> Handoff { let sleep_until = timeout.map(|dur| Instant::now() + dur); let mut state: State = self.state.load(Acquire).into(); @@ -208,23 +208,23 @@ impl Backup { } } - pub fn is_pushed(&self) -> bool { + pub(crate) fn is_pushed(&self) -> bool { let state: State = self.state.load(Relaxed).into(); state.is_pushed() } - pub fn set_pushed(&self, ordering: Ordering) { + pub(crate) fn set_pushed(&self, ordering: Ordering) { let prev: State = self.state.fetch_or(PUSHED, ordering).into(); debug_assert!(!prev.is_pushed()); } #[inline] - pub fn next_sleeper(&self) -> BackupId { + pub(crate) fn next_sleeper(&self) -> BackupId { unsafe { *self.next_sleeper.get() } } #[inline] - pub fn set_next_sleeper(&self, val: BackupId) { + pub(crate) fn set_next_sleeper(&self, val: BackupId) { unsafe { *self.next_sleeper.get() = val; } diff --git a/tokio-threadpool/src/pool/backup_stack.rs b/tokio-threadpool/src/pool/backup_stack.rs index 52d7c3de7..f63a0b130 100644 --- a/tokio-threadpool/src/pool/backup_stack.rs +++ b/tokio-threadpool/src/pool/backup_stack.rs @@ -34,7 +34,7 @@ const ABA_GUARD_MASK: usize = (1 << (32 - ABA_GUARD_SHIFT)) - 1; // ===== impl BackupStack ===== impl BackupStack { - pub fn new() -> BackupStack { + pub(crate) fn new() -> BackupStack { let state = AtomicUsize::new(State::new().into()); BackupStack { state } } @@ -47,7 +47,7 @@ impl BackupStack { /// /// Returns `Err` if the pool has transitioned to the `TERMINATED` state. /// When terminated, pushing new entries is no longer permitted. - pub fn push(&self, entries: &[Backup], id: BackupId) -> Result<(), ()> { + pub(crate) fn push(&self, entries: &[Backup], id: BackupId) -> Result<(), ()> { let mut state: State = self.state.load(Acquire).into(); entries[id.0].set_pushed(AcqRel); @@ -91,7 +91,7 @@ impl BackupStack { /// /// * `Ok(None)` if the stack is empty. /// * `Err(_)` is returned if the pool has been shutdown. - pub fn pop(&self, entries: &[Backup], terminate: bool) -> Result, ()> { + pub(crate) fn pop(&self, entries: &[Backup], terminate: bool) -> Result, ()> { // Figure out the empty value let terminal = if terminate { TERMINATED } else { EMPTY }; diff --git a/tokio-threadpool/src/pool/mod.rs b/tokio-threadpool/src/pool/mod.rs index 62d880d60..7b347eea0 100644 --- a/tokio-threadpool/src/pool/mod.rs +++ b/tokio-threadpool/src/pool/mod.rs @@ -38,7 +38,7 @@ pub(crate) struct Pool { // // The value of this atomic is deserialized into a `pool::State` instance. // See comments for that type. - pub state: CachePadded, + pub(crate) state: CachePadded, // Stack tracking sleeping workers. sleep_stack: CachePadded, @@ -49,19 +49,19 @@ pub(crate) struct Pool { // futures. // // The number of workers will *usually* be small. - pub workers: Arc<[worker::Entry]>, + pub(crate) workers: Arc<[worker::Entry]>, // The global MPMC queue of tasks. // // Spawned tasks are pushed into this queue. Although worker threads have their own dedicated // task queues, they periodically steal tasks from this global queue, too. - pub queue: Arc>>, + pub(crate) queue: Arc>>, // Completes the shutdown process when the `ThreadPool` and all `Worker`s get dropped. // // When spawning a new `Worker`, this weak reference is upgraded and handed out to the new // thread. - pub trigger: Weak, + pub(crate) trigger: Weak, // Backup thread state // @@ -71,19 +71,19 @@ pub(crate) struct Pool { backup: Box<[Backup]>, // Stack of sleeping backup threads - pub backup_stack: BackupStack, + pub(crate) backup_stack: BackupStack, // State regarding coordinating blocking sections and tracking tasks that // are pending blocking capacity. blocking: Blocking, // Configuration - pub config: Config, + pub(crate) config: Config, } impl Pool { /// Create a new `Pool` - pub fn new( + pub(crate) fn new( workers: Arc<[worker::Entry]>, trigger: Weak, max_blocking: usize, @@ -133,7 +133,7 @@ impl Pool { /// Start shutting down the pool. This means that no new futures will be /// accepted. - pub fn shutdown(&self, now: bool, purge_queue: bool) { + pub(crate) fn shutdown(&self, now: bool, purge_queue: bool) { let mut state: State = self.state.load(Acquire).into(); trace!("shutdown; state={:?}", state); @@ -198,11 +198,11 @@ impl Pool { /// Called by `Worker` as it tries to enter a sleeping state. Before it /// sleeps, it must push itself onto the sleep stack. This enables other /// threads to see it when signaling work. - pub fn push_sleeper(&self, idx: usize) -> Result<(), ()> { + pub(crate) fn push_sleeper(&self, idx: usize) -> Result<(), ()> { self.sleep_stack.push(&self.workers, idx) } - pub fn terminate_sleeping_workers(&self) { + pub(crate) fn terminate_sleeping_workers(&self) { use crate::worker::Lifecycle::Signaled; trace!(" -> shutting down workers"); @@ -222,7 +222,7 @@ impl Pool { } } - pub fn poll_blocking_capacity( + pub(crate) fn poll_blocking_capacity( &self, task: &Arc, ) -> Poll> { @@ -233,7 +233,7 @@ impl Pool { /// /// Called from either inside or outside of the scheduler. If currently on /// the scheduler, then a fast path is taken. - pub fn submit(&self, task: Arc, pool: &Arc) { + pub(crate) fn submit(&self, task: Arc, pool: &Arc) { debug_assert_eq!(*self, **pool); Worker::with_current(|worker| { @@ -265,7 +265,7 @@ impl Pool { /// /// Called from outside of the scheduler, this function is how new tasks /// enter the system. - pub fn submit_external(&self, task: Arc, pool: &Arc) { + pub(crate) fn submit_external(&self, task: Arc, pool: &Arc) { debug_assert_eq!(*self, **pool); trace!(" -> submit external"); @@ -274,7 +274,7 @@ impl Pool { self.signal_work(pool); } - pub fn release_backup(&self, backup_id: BackupId) -> Result<(), ()> { + pub(crate) fn release_backup(&self, backup_id: BackupId) -> Result<(), ()> { // First update the state, this cannot fail because the caller must have // exclusive access to the backup token. self.backup[backup_id.0].release(); @@ -283,13 +283,13 @@ impl Pool { self.backup_stack.push(&self.backup, backup_id) } - pub fn notify_blocking_task(&self, pool: &Arc) { + pub(crate) fn notify_blocking_task(&self, pool: &Arc) { debug_assert_eq!(*self, **pool); self.blocking.notify_task(&pool); } /// Provision a thread to run a worker - pub fn spawn_thread(&self, id: WorkerId, pool: &Arc) { + pub(crate) fn spawn_thread(&self, id: WorkerId, pool: &Arc) { debug_assert_eq!(*self, **pool); let backup_id = match self.backup_stack.pop(&self.backup, false) { @@ -396,7 +396,7 @@ impl Pool { /// If there are any other workers currently relaxing, signal them that work /// is available so that they can try to find more work to process. - pub fn signal_work(&self, pool: &Arc) { + pub(crate) fn signal_work(&self, pool: &Arc) { debug_assert_eq!(*self, **pool); use crate::worker::Lifecycle::Signaled; @@ -422,7 +422,7 @@ impl Pool { /// Generates a random number /// /// Uses a thread-local random number generator based on XorShift. - pub fn rand_usize(&self) -> usize { + pub(crate) fn rand_usize(&self) -> usize { thread_local! { static RNG: Cell> = Cell::new(Wrapping(prng_seed())); } diff --git a/tokio-threadpool/src/task/blocking.rs b/tokio-threadpool/src/task/blocking.rs index 2640149f0..92d985b24 100644 --- a/tokio-threadpool/src/task/blocking.rs +++ b/tokio-threadpool/src/task/blocking.rs @@ -85,7 +85,7 @@ const NUM_SHIFT: usize = 1; // impl Blocking { /// Create a new `Blocking`. - pub fn new(capacity: usize) -> Blocking { + pub(crate) fn new(capacity: usize) -> Blocking { assert!(capacity > 0, "blocking capacity must be greater than zero"); let stub = Box::new(Task::stub()); @@ -110,7 +110,7 @@ impl Blocking { /// /// The caller must ensure that `task` has not previously been queued to be /// notified when capacity becomes available. - pub fn poll_blocking_capacity( + pub(crate) fn poll_blocking_capacity( &self, task: &Arc, ) -> Poll> { @@ -243,7 +243,7 @@ impl Blocking { (*prev).next_blocking.store(task, Release); } - pub fn notify_task(&self, pool: &Arc) { + pub(crate) fn notify_task(&self, pool: &Arc) { let prev = self.lock.fetch_add(1, AcqRel); if prev != 0 { diff --git a/tokio-threadpool/src/task/mod.rs b/tokio-threadpool/src/task/mod.rs index 2a225a145..480152bbe 100644 --- a/tokio-threadpool/src/task/mod.rs +++ b/tokio-threadpool/src/task/mod.rs @@ -40,13 +40,13 @@ pub(crate) struct Task { /// /// The worker ID is represented by a `u32` rather than `usize` in order to save some space /// on 64-bit platforms. - pub reg_worker: Cell>, + pub(crate) reg_worker: Cell>, /// The key associated with this task in the `Slab` it was registered in. /// /// This field can be a `Cell` because it's only accessed by the worker thread that has /// registered the task. - pub reg_index: Cell, + pub(crate) reg_index: Cell, /// Store the future at the head of the struct /// @@ -67,7 +67,7 @@ type BoxFuture = Pin + Send + 'static>>; impl Task { /// Create a new `Task` as a harness for `future`. - pub fn new(future: BoxFuture) -> Task { + pub(crate) fn new(future: BoxFuture) -> Task { Task { state: AtomicUsize::new(State::new().into()), blocking: AtomicUsize::new(BlockingState::new().into()), @@ -95,7 +95,7 @@ impl Task { /// Execute the task returning `Run::Schedule` if the task needs to be /// scheduled again. - pub fn run(me: &Arc, pool: &Arc) -> Run { + pub(crate) fn run(me: &Arc, pool: &Arc) -> Run { use self::State::*; // Transition task to running state. At this point, the task must be @@ -200,7 +200,7 @@ impl Task { /// /// This is called when the threadpool shuts down and the task has already beed polled but not /// completed. - pub fn abort(&self) { + pub(crate) fn abort(&self) { use self::State::*; let mut state = self.state.load(Acquire).into(); @@ -232,12 +232,12 @@ impl Task { } /// Notify the task it has been allocated blocking capacity - pub fn notify_blocking(me: Arc, pool: &Arc) { + pub(crate) fn notify_blocking(me: Arc, pool: &Arc) { BlockingState::notify_blocking(&me.blocking, AcqRel); Task::schedule(&me, pool); } - pub fn schedule(me: &Arc, pool: &Arc) { + pub(crate) fn schedule(me: &Arc, pool: &Arc) { if me.schedule2() { let task = me.clone(); pool.submit(task, &pool); @@ -281,7 +281,7 @@ impl Task { /// Consumes any allocated capacity to block. /// /// Returns `true` if capacity was allocated, `false` otherwise. - pub fn consume_blocking_allocation(&self) -> CanBlock { + pub(crate) fn consume_blocking_allocation(&self) -> CanBlock { // This flag is the primary point of coordination. The queued flag // happens "around" setting the blocking capacity. BlockingState::consume_allocation(&self.blocking, AcqRel) diff --git a/tokio-threadpool/src/waker.rs b/tokio-threadpool/src/waker.rs index 258a82a21..b1fd97d4c 100644 --- a/tokio-threadpool/src/waker.rs +++ b/tokio-threadpool/src/waker.rs @@ -10,8 +10,8 @@ use std::sync::Arc; /// to poll the future again. #[derive(Debug)] pub(crate) struct Waker { - pub pool: Arc, - pub task: Arc, + pub(crate) pool: Arc, + pub(crate) task: Arc, } unsafe impl Send for Waker {} diff --git a/tokio-threadpool/src/worker/entry.rs b/tokio-threadpool/src/worker/entry.rs index 199b9ba16..66ae1d670 100644 --- a/tokio-threadpool/src/worker/entry.rs +++ b/tokio-threadpool/src/worker/entry.rs @@ -21,13 +21,13 @@ pub(crate) struct WorkerEntry { // // The `usize` value is deserialized to a `worker::State` instance. See // comments on that type. - pub state: CachePadded, + pub(crate) state: CachePadded, // Next entry in the parked Trieber stack next_sleeper: UnsafeCell, // Worker half of deque - pub worker: Worker>, + pub(crate) worker: Worker>, // Stealer half of deque stealer: Stealer>, @@ -50,7 +50,7 @@ pub(crate) struct WorkerEntry { } impl WorkerEntry { - pub fn new(park: BoxPark, unpark: BoxUnpark) -> Self { + pub(crate) fn new(park: BoxPark, unpark: BoxUnpark) -> Self { let w = Worker::new_fifo(); let s = w.stealer(); @@ -76,14 +76,14 @@ impl WorkerEntry { /// # Ordering /// /// The specified ordering is established on the entry's state variable. - pub fn fetch_unset_pushed(&self, ordering: Ordering) -> State { + pub(crate) fn fetch_unset_pushed(&self, ordering: Ordering) -> State { self.state.fetch_and(!PUSHED_MASK, ordering).into() } /// Submit a task to this worker while currently on the same thread that is /// running the worker. #[inline] - pub fn submit_internal(&self, task: Arc) { + pub(crate) fn submit_internal(&self, task: Arc) { self.push_internal(task); } @@ -93,7 +93,7 @@ impl WorkerEntry { /// /// The `state` must have been obtained with an `Acquire` ordering. #[inline] - pub fn notify(&self, mut state: State) -> bool { + pub(crate) fn notify(&self, mut state: State) -> bool { use crate::worker::Lifecycle::*; loop { @@ -138,7 +138,7 @@ impl WorkerEntry { /// Returns `Ok` when the worker was successfully signaled. /// /// Returns `Err` if the worker has already terminated. - pub fn signal_stop(&self, mut state: State) { + pub(crate) fn signal_stop(&self, mut state: State) { use crate::worker::Lifecycle::*; // Transition the worker state to signaled @@ -189,7 +189,7 @@ impl WorkerEntry { /// This **must** only be called by the thread that owns the worker entry. /// This function is not `Sync`. #[inline] - pub fn pop_task(&self) -> Option> { + pub(crate) fn pop_task(&self) -> Option> { self.worker.pop() } @@ -201,26 +201,26 @@ impl WorkerEntry { /// At the same time, this method steals some additional tasks and moves /// them into `dest` in order to balance the work distribution among /// workers. - pub fn steal_tasks(&self, dest: &Self) -> Steal> { + pub(crate) fn steal_tasks(&self, dest: &Self) -> Steal> { self.stealer.steal_batch_and_pop(&dest.worker) } /// Drain (and drop) all tasks that are queued for work. /// /// This is called when the pool is shutting down. - pub fn drain_tasks(&self) { + pub(crate) fn drain_tasks(&self) { while self.worker.pop().is_some() {} } /// Parks the worker thread. - pub fn park(&self) { + pub(crate) fn park(&self) { if let Some(park) = unsafe { (*self.park.get()).as_mut() } { park.park().unwrap(); } } /// Parks the worker thread for at most `duration`. - pub fn park_timeout(&self, duration: Duration) { + pub(crate) fn park_timeout(&self, duration: Duration) { if let Some(park) = unsafe { (*self.park.get()).as_mut() } { park.park_timeout(duration).unwrap(); } @@ -228,7 +228,7 @@ impl WorkerEntry { /// Unparks the worker thread. #[inline] - pub fn unpark(&self) { + pub(crate) fn unpark(&self) { if let Some(park) = unsafe { (*self.unpark.get()).as_ref() } { park.unpark(); } @@ -238,7 +238,7 @@ impl WorkerEntry { /// /// Called when the task is being polled for the first time. #[inline] - pub fn register_task(&self, task: &Arc) { + pub(crate) fn register_task(&self, task: &Arc) { let running_tasks = unsafe { &mut *self.running_tasks.get() }; let key = running_tasks.insert(task.clone()); @@ -249,7 +249,7 @@ impl WorkerEntry { /// /// Called when the task is completed and was previously registered in this worker. #[inline] - pub fn unregister_task(&self, task: Arc) { + pub(crate) fn unregister_task(&self, task: Arc) { let running_tasks = unsafe { &mut *self.running_tasks.get() }; running_tasks.remove(task.reg_index.get()); self.drain_remotely_completed_tasks(); @@ -260,7 +260,7 @@ impl WorkerEntry { /// Called when the task is completed by another worker and was previously registered in this /// worker. #[inline] - pub fn remotely_complete_task(&self, task: Arc) { + pub(crate) fn remotely_complete_task(&self, task: Arc) { self.remotely_completed_tasks.push(task); self.needs_drain.store(true, Release); } @@ -268,7 +268,7 @@ impl WorkerEntry { /// Drops the remaining incomplete tasks and the parker associated with this worker. /// /// This function is called by the shutdown trigger. - pub fn shutdown(&self) { + pub(crate) fn shutdown(&self) { self.drain_remotely_completed_tasks(); // Abort all incomplete tasks. @@ -297,17 +297,17 @@ impl WorkerEntry { } #[inline] - pub fn push_internal(&self, task: Arc) { + pub(crate) fn push_internal(&self, task: Arc) { self.worker.push(task); } #[inline] - pub fn next_sleeper(&self) -> usize { + pub(crate) fn next_sleeper(&self) -> usize { unsafe { *self.next_sleeper.get() } } #[inline] - pub fn set_next_sleeper(&self, val: usize) { + pub(crate) fn set_next_sleeper(&self, val: usize) { unsafe { *self.next_sleeper.get() = val; } diff --git a/tokio-threadpool/src/worker/stack.rs b/tokio-threadpool/src/worker/stack.rs index 1d4dfad9d..47c9cdbab 100644 --- a/tokio-threadpool/src/worker/stack.rs +++ b/tokio-threadpool/src/worker/stack.rs @@ -58,7 +58,7 @@ const ABA_GUARD_MASK: usize = (1 << (32 - ABA_GUARD_SHIFT)) - 1; impl Stack { /// Create a new `Stack` representing the empty state. - pub fn new() -> Stack { + pub(crate) fn new() -> Stack { let state = AtomicUsize::new(State::new().into()); Stack { state } } @@ -71,7 +71,7 @@ impl Stack { /// /// Returns `Err` if the pool has transitioned to the `TERMINATED` state. /// When terminated, pushing new entries is no longer permitted. - pub fn push(&self, entries: &[worker::Entry], idx: usize) -> Result<(), ()> { + pub(crate) fn push(&self, entries: &[worker::Entry], idx: usize) -> Result<(), ()> { let mut state: State = self.state.load(Acquire).into(); debug_assert!(worker::State::from(entries[idx].state.load(Relaxed)).is_pushed()); @@ -113,7 +113,7 @@ impl Stack { /// Returns the index of the popped worker and the worker's observed state. /// /// `None` if the stack is empty. - pub fn pop( + pub(crate) fn pop( &self, entries: &[worker::Entry], max_lifecycle: worker::Lifecycle, diff --git a/tokio-threadpool/src/worker/state.rs b/tokio-threadpool/src/worker/state.rs index e8d35c332..68b5bc477 100644 --- a/tokio-threadpool/src/worker/state.rs +++ b/tokio-threadpool/src/worker/state.rs @@ -35,15 +35,15 @@ pub(crate) enum Lifecycle { impl State { /// Returns true if the worker entry is pushed in the sleeper stack - pub fn is_pushed(self) -> bool { + pub(crate) fn is_pushed(self) -> bool { self.0 & PUSHED_MASK == PUSHED_MASK } - pub fn set_pushed(&mut self) { + pub(crate) fn set_pushed(&mut self) { self.0 |= PUSHED_MASK } - pub fn is_notified(self) -> bool { + pub(crate) fn is_notified(self) -> bool { use self::Lifecycle::*; match self.lifecycle() { @@ -52,19 +52,19 @@ impl State { } } - pub fn lifecycle(self) -> Lifecycle { + pub(crate) fn lifecycle(self) -> Lifecycle { Lifecycle::from(self.0 & LIFECYCLE_MASK) } - pub fn set_lifecycle(&mut self, val: Lifecycle) { + pub(crate) fn set_lifecycle(&mut self, val: Lifecycle) { self.0 = (self.0 & !LIFECYCLE_MASK) | (val as usize) } - pub fn is_signaled(self) -> bool { + pub(crate) fn is_signaled(self) -> bool { self.lifecycle() == Lifecycle::Signaled } - pub fn notify(&mut self) { + pub(crate) fn notify(&mut self) { use self::Lifecycle::Signaled; if self.lifecycle() != Signaled { diff --git a/tokio-timer/src/lib.rs b/tokio-timer/src/lib.rs index 2541f03e4..a9dc07dcc 100644 --- a/tokio-timer/src/lib.rs +++ b/tokio-timer/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-timer/0.3.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] diff --git a/tokio-timer/src/timer/atomic_stack.rs b/tokio-timer/src/timer/atomic_stack.rs index 6e091cbd9..0574e939a 100644 --- a/tokio-timer/src/timer/atomic_stack.rs +++ b/tokio-timer/src/timer/atomic_stack.rs @@ -22,7 +22,7 @@ pub(crate) struct AtomicStackEntries { const SHUTDOWN: *mut Entry = 1 as *mut _; impl AtomicStack { - pub fn new() -> AtomicStack { + pub(crate) fn new() -> AtomicStack { AtomicStack { head: AtomicPtr::new(ptr::null_mut()), } @@ -32,7 +32,7 @@ impl AtomicStack { /// /// Returns `true` if the entry was pushed, `false` if the entry is already /// on the stack, `Err` if the timer is shutdown. - pub fn push(&self, entry: &Arc) -> Result { + pub(crate) fn push(&self, entry: &Arc) -> Result { // First, set the queued bit on the entry let queued = entry.queued.fetch_or(true, SeqCst); @@ -72,14 +72,14 @@ impl AtomicStack { } /// Take all entries from the stack - pub fn take(&self) -> AtomicStackEntries { + pub(crate) fn take(&self) -> AtomicStackEntries { let ptr = self.head.swap(ptr::null_mut(), SeqCst); AtomicStackEntries { ptr } } /// Drain all remaining nodes in the stack and prevent any new nodes from /// being pushed onto the stack. - pub fn shutdown(&self) { + pub(crate) fn shutdown(&self) { // Shutdown the processing queue let ptr = self.head.swap(SHUTDOWN, SeqCst); diff --git a/tokio-timer/src/timer/entry.rs b/tokio-timer/src/timer/entry.rs index 650ee071b..219d027b9 100644 --- a/tokio-timer/src/timer/entry.rs +++ b/tokio-timer/src/timer/entry.rs @@ -104,7 +104,7 @@ const ERROR: u64 = u64::MAX; // ===== impl Entry ===== impl Entry { - pub fn new(deadline: Instant, duration: Duration) -> Entry { + pub(crate) fn new(deadline: Instant, duration: Duration) -> Entry { Entry { time: CachePadded::new(UnsafeCell::new(Time { deadline, duration })), inner: None, @@ -119,24 +119,24 @@ impl Entry { } /// Only called by `Registration` - pub fn time_ref(&self) -> &Time { + pub(crate) fn time_ref(&self) -> &Time { unsafe { &*self.time.get() } } /// Only called by `Registration` #[allow(clippy::mut_from_ref)] // https://github.com/rust-lang/rust-clippy/issues/4281 - pub unsafe fn time_mut(&self) -> &mut Time { + pub(crate) unsafe fn time_mut(&self) -> &mut Time { &mut *self.time.get() } /// Returns `true` if the `Entry` is currently associated with a timer /// instance. - pub fn is_registered(&self) -> bool { + pub(crate) fn is_registered(&self) -> bool { self.inner.is_some() } /// Only called by `Registration` - pub fn register(me: &mut Arc) { + pub(crate) fn register(me: &mut Arc) { let handle = match HandlePriv::try_current() { Ok(handle) => handle, Err(_) => { @@ -152,7 +152,7 @@ impl Entry { } /// Only called by `Registration` - pub fn register_with(me: &mut Arc, handle: HandlePriv) { + pub(crate) fn register_with(me: &mut Arc, handle: HandlePriv) { assert!(!me.is_registered(), "only register an entry once"); let deadline = me.time_ref().deadline; @@ -202,18 +202,18 @@ impl Entry { /// The current entry state as known by the timer. This is not the value of /// `state`, but lets the timer know how to converge its state to `state`. - pub fn when_internal(&self) -> Option { + pub(crate) fn when_internal(&self) -> Option { unsafe { (*self.when.get()) } } - pub fn set_when_internal(&self, when: Option) { + pub(crate) fn set_when_internal(&self, when: Option) { unsafe { (*self.when.get()) = when; } } /// Called by `Timer` to load the current value of `state` for processing - pub fn load_state(&self) -> Option { + pub(crate) fn load_state(&self) -> Option { let state = self.state.load(SeqCst); if is_elapsed(state) { @@ -223,12 +223,12 @@ impl Entry { } } - pub fn is_elapsed(&self) -> bool { + pub(crate) fn is_elapsed(&self) -> bool { let state = self.state.load(SeqCst); is_elapsed(state) } - pub fn fire(&self, when: u64) { + pub(crate) fn fire(&self, when: u64) { let mut curr = self.state.load(SeqCst); loop { @@ -249,7 +249,7 @@ impl Entry { self.waker.wake(); } - pub fn error(&self) { + pub(crate) fn error(&self) { // Only transition to the error state if not currently elapsed let mut curr = self.state.load(SeqCst); @@ -272,7 +272,7 @@ impl Entry { self.waker.wake(); } - pub fn cancel(entry: &Arc) { + pub(crate) fn cancel(entry: &Arc) { let state = entry.state.fetch_or(ELAPSED, SeqCst); if is_elapsed(state) { @@ -289,7 +289,7 @@ impl Entry { let _ = inner.queue(entry); } - pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll> { + pub(crate) fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll> { let mut curr = self.state.load(SeqCst); if is_elapsed(curr) { @@ -316,7 +316,7 @@ impl Entry { } /// Only called by `Registration` - pub fn reset(entry: &mut Arc) { + pub(crate) fn reset(entry: &mut Arc) { if !entry.is_registered() { return; } diff --git a/tokio-timer/src/timer/now.rs b/tokio-timer/src/timer/now.rs index 53754427e..8e412b5eb 100644 --- a/tokio-timer/src/timer/now.rs +++ b/tokio-timer/src/timer/now.rs @@ -7,4 +7,5 @@ pub trait Now { fn now(&mut self) -> Instant; } +#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 pub use crate::clock::Clock as SystemNow; diff --git a/tokio-timer/src/timer/registration.rs b/tokio-timer/src/timer/registration.rs index 5e379d235..9d7949a38 100644 --- a/tokio-timer/src/timer/registration.rs +++ b/tokio-timer/src/timer/registration.rs @@ -14,7 +14,7 @@ pub(crate) struct Registration { } impl Registration { - pub fn new(deadline: Instant, duration: Duration) -> Registration { + pub(crate) fn new(deadline: Instant, duration: Duration) -> Registration { fn is_send() {} is_send::(); @@ -23,21 +23,21 @@ impl Registration { } } - pub fn deadline(&self) -> Instant { + pub(crate) fn deadline(&self) -> Instant { self.entry.time_ref().deadline } - pub fn register(&mut self) { + pub(crate) fn register(&mut self) { if !self.entry.is_registered() { Entry::register(&mut self.entry) } } - pub fn register_with(&mut self, handle: HandlePriv) { + pub(crate) fn register_with(&mut self, handle: HandlePriv) { Entry::register_with(&mut self.entry, handle) } - pub fn reset(&mut self, deadline: Instant) { + pub(crate) fn reset(&mut self, deadline: Instant) { unsafe { self.entry.time_mut().deadline = deadline; } @@ -46,7 +46,7 @@ impl Registration { // Used by `Timeout` #[cfg(feature = "async-traits")] - pub fn reset_timeout(&mut self) { + pub(crate) fn reset_timeout(&mut self) { let deadline = crate::clock::now() + self.entry.time_ref().duration; unsafe { self.entry.time_mut().deadline = deadline; @@ -54,11 +54,11 @@ impl Registration { Entry::reset(&mut self.entry); } - pub fn is_elapsed(&self) -> bool { + pub(crate) fn is_elapsed(&self) -> bool { self.entry.is_elapsed() } - pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll> { + pub(crate) fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll> { self.entry.poll_elapsed(cx) } } diff --git a/tokio-timer/src/wheel/level.rs b/tokio-timer/src/wheel/level.rs index 868e6a796..d403e2327 100644 --- a/tokio-timer/src/wheel/level.rs +++ b/tokio-timer/src/wheel/level.rs @@ -22,13 +22,13 @@ pub(crate) struct Level { #[derive(Debug)] pub(crate) struct Expiration { /// The level containing the slot. - pub level: usize, + pub(crate) level: usize, /// The slot index. - pub slot: usize, + pub(crate) slot: usize, /// The instant at which the slot needs to be processed. - pub deadline: u64, + pub(crate) deadline: u64, } /// Level multiplier. @@ -37,7 +37,7 @@ pub(crate) struct Expiration { const LEVEL_MULT: usize = 64; impl Level { - pub fn new(level: usize) -> Level { + pub(crate) fn new(level: usize) -> Level { // Rust's derived implementations for arrays require that the value // contained by the array be `Copy`. So, here we have to manually // initialize every single slot. @@ -123,7 +123,7 @@ impl Level { /// Finds the slot that needs to be processed next and returns the slot and /// `Instant` at which this slot must be processed. - pub fn next_expiration(&self, now: u64) -> Option { + pub(crate) fn next_expiration(&self, now: u64) -> Option { // Use the `occupied` bit field to get the index of the next slot that // needs to be processed. let slot = match self.next_occupied_slot(now) { @@ -172,14 +172,14 @@ impl Level { Some(slot) } - pub fn add_entry(&mut self, when: u64, item: T::Owned, store: &mut T::Store) { + pub(crate) fn add_entry(&mut self, when: u64, item: T::Owned, store: &mut T::Store) { let slot = slot_for(when, self.level); self.slot[slot].push(item, store); self.occupied |= occupied_bit(slot); } - pub fn remove_entry(&mut self, when: u64, item: &T::Borrowed, store: &mut T::Store) { + pub(crate) fn remove_entry(&mut self, when: u64, item: &T::Borrowed, store: &mut T::Store) { let slot = slot_for(when, self.level); self.slot[slot].remove(item, store); @@ -193,7 +193,7 @@ impl Level { } } - pub fn pop_entry_slot(&mut self, slot: usize, store: &mut T::Store) -> Option { + pub(crate) fn pop_entry_slot(&mut self, slot: usize, store: &mut T::Store) -> Option { let ret = self.slot[slot].pop(store); if ret.is_some() && self.slot[slot].is_empty() { diff --git a/tokio-timer/src/wheel/mod.rs b/tokio-timer/src/wheel/mod.rs index 81f92cd88..3a9a51e13 100644 --- a/tokio-timer/src/wheel/mod.rs +++ b/tokio-timer/src/wheel/mod.rs @@ -63,7 +63,7 @@ where T: Stack, { /// Create a new timing wheel - pub fn new() -> Wheel { + pub(crate) fn new() -> Wheel { let levels = (0..NUM_LEVELS).map(Level::new).collect(); Wheel { elapsed: 0, levels } @@ -71,7 +71,7 @@ where /// Return the number of milliseconds that have elapsed since the timing /// wheel's creation. - pub fn elapsed(&self) -> u64 { + pub(crate) fn elapsed(&self) -> u64 { self.elapsed } @@ -96,7 +96,7 @@ where /// immediately. /// /// `Err(Invalid)` indicates an invalid `when` argument as been supplied. - pub fn insert( + pub(crate) fn insert( &mut self, when: u64, item: T::Owned, @@ -124,7 +124,7 @@ where } /// Remove `item` from thee timing wheel. - pub fn remove(&mut self, item: &T::Borrowed, store: &mut T::Store) { + pub(crate) fn remove(&mut self, item: &T::Borrowed, store: &mut T::Store) { let when = T::when(item, store); let level = self.level_for(when); @@ -132,11 +132,11 @@ where } /// Instant at which to poll - pub fn poll_at(&self) -> Option { + pub(crate) fn poll_at(&self) -> Option { self.next_expiration().map(|expiration| expiration.deadline) } - pub fn poll(&mut self, poll: &mut Poll, store: &mut T::Store) -> Option { + pub(crate) fn poll(&mut self, poll: &mut Poll, store: &mut T::Store) -> Option { loop { if poll.expiration.is_none() { poll.expiration = self.next_expiration().and_then(|expiration| { @@ -194,7 +194,7 @@ where None } - pub fn poll_expiration( + pub(crate) fn poll_expiration( &mut self, expiration: &Expiration, store: &mut T::Store, @@ -249,7 +249,7 @@ fn level_for(elapsed: u64, when: u64) -> usize { } impl Poll { - pub fn new(now: u64) -> Poll { + pub(crate) fn new(now: u64) -> Poll { Poll { now, expiration: None, diff --git a/tokio-tls/src/lib.rs b/tokio-tls/src/lib.rs index 3d8900ce7..06b997ab7 100644 --- a/tokio-tls/src/lib.rs +++ b/tokio-tls/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-tls/0.3.0-alpha.1")] -#![warn(rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] @@ -21,6 +26,7 @@ //! `native-tls` crate. use native_tls::{Error, HandshakeError, MidHandshakeTlsStream}; +use std::fmt; use std::future::Future; use std::io::{self, Read, Write}; use std::marker::Unpin; @@ -270,6 +276,12 @@ impl TlsConnector { } } +impl fmt::Debug for TlsConnector { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("TlsConnector").finish() + } +} + impl From for TlsConnector { fn from(inner: native_tls::TlsConnector) -> TlsConnector { TlsConnector(inner) @@ -295,6 +307,12 @@ impl TlsAcceptor { } } +impl fmt::Debug for TlsAcceptor { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("TlsAcceptor").finish() + } +} + impl From for TlsAcceptor { fn from(inner: native_tls::TlsAcceptor) -> TlsAcceptor { TlsAcceptor(inner) diff --git a/tokio-udp/src/lib.rs b/tokio-udp/src/lib.rs index b25fc71b0..aa200bfb8 100644 --- a/tokio-udp/src/lib.rs +++ b/tokio-udp/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio-tcp/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] diff --git a/tokio-uds/src/lib.rs b/tokio-uds/src/lib.rs index a2824241a..e531e3b45 100644 --- a/tokio-uds/src/lib.rs +++ b/tokio-uds/src/lib.rs @@ -1,6 +1,11 @@ #![cfg(unix)] #![doc(html_root_url = "https://docs.rs/tokio-uds/0.3.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] diff --git a/tokio-uds/src/ucred.rs b/tokio-uds/src/ucred.rs index 10c2fc4c8..ed607cfb5 100644 --- a/tokio-uds/src/ucred.rs +++ b/tokio-uds/src/ucred.rs @@ -10,7 +10,7 @@ pub struct UCred { } #[cfg(any(target_os = "linux", target_os = "android"))] -pub use self::impl_linux::get_peer_cred; +pub(crate) use self::impl_linux::get_peer_cred; #[cfg(any( target_os = "dragonfly", @@ -20,20 +20,20 @@ pub use self::impl_linux::get_peer_cred; target_os = "netbsd", target_os = "openbsd" ))] -pub use self::impl_macos::get_peer_cred; +pub(crate) use self::impl_macos::get_peer_cred; #[cfg(any(target_os = "solaris"))] -pub use self::impl_solaris::get_peer_cred; +pub(crate) use self::impl_solaris::get_peer_cred; #[cfg(any(target_os = "linux", target_os = "android"))] -pub mod impl_linux { +pub(crate) mod impl_linux { use crate::UnixStream; use libc::{c_void, getsockopt, socklen_t, SOL_SOCKET, SO_PEERCRED}; use std::{io, mem}; use libc::ucred; - pub fn get_peer_cred(sock: &UnixStream) -> io::Result { + pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result { use std::os::unix::io::AsRawFd; unsafe { @@ -80,14 +80,14 @@ pub mod impl_linux { target_os = "netbsd", target_os = "openbsd" ))] -pub mod impl_macos { +pub(crate) mod impl_macos { use crate::UnixStream; use libc::getpeereid; use std::io; use std::mem::MaybeUninit; use std::os::unix::io::AsRawFd; - pub fn get_peer_cred(sock: &UnixStream) -> io::Result { + pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result { unsafe { let raw_fd = sock.as_raw_fd(); @@ -109,7 +109,7 @@ pub mod impl_macos { } #[cfg(any(target_os = "solaris"))] -pub mod impl_solaris { +pub(crate) mod impl_solaris { use std::io; use std::os::unix::io::AsRawFd; use std::ptr; @@ -129,7 +129,7 @@ pub mod impl_solaris { ) -> ::std::os::raw::c_int; } - pub fn get_peer_cred(sock: &UnixStream) -> io::Result { + pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result { unsafe { let raw_fd = sock.as_raw_fd(); diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 75d52073f..a20a417c7 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -1,5 +1,10 @@ #![doc(html_root_url = "https://docs.rs/tokio/0.2.0-alpha.1")] -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub +)] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![feature(async_await)] diff --git a/tokio/src/runtime/threadpool/background.rs b/tokio/src/runtime/threadpool/background.rs index 64ab54415..8e44bba9b 100644 --- a/tokio/src/runtime/threadpool/background.rs +++ b/tokio/src/runtime/threadpool/background.rs @@ -10,14 +10,14 @@ use tokio_timer::timer::{self, Timer}; use std::{io, thread}; #[derive(Debug)] -pub struct Background { +pub(crate) struct Background { reactor_handle: tokio_reactor::Handle, timer_handle: timer::Handle, shutdown_tx: Option>, thread: Option>, } -pub fn spawn(clock: &Clock) -> io::Result { +pub(crate) fn spawn(clock: &Clock) -> io::Result { let clock = clock.clone(); let reactor = Reactor::new()?; diff --git a/tokio/src/runtime/threadpool/mod.rs b/tokio/src/runtime/threadpool/mod.rs index b699bbf48..f9341f097 100644 --- a/tokio/src/runtime/threadpool/mod.rs +++ b/tokio/src/runtime/threadpool/mod.rs @@ -2,7 +2,9 @@ mod background; mod builder; mod task_executor; +#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 pub use self::builder::Builder; +#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411 pub use self::task_executor::TaskExecutor; use background::Background;