mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
chore: apply unreachable_pub and missing_debug_implementations to all crates (#1424)
This commit is contained in:
@@ -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)]
|
||||
|
||||
|
||||
@@ -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<Entry>) -> Result<bool, Error> {
|
||||
pub(crate) fn push(&self, entry: &Arc<Entry>) -> Result<bool, Error> {
|
||||
// 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);
|
||||
|
||||
|
||||
@@ -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<Self>) {
|
||||
pub(crate) fn register(me: &mut Arc<Self>) {
|
||||
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<Self>, handle: HandlePriv) {
|
||||
pub(crate) fn register_with(me: &mut Arc<Self>, 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<u64> {
|
||||
pub(crate) fn when_internal(&self) -> Option<u64> {
|
||||
unsafe { (*self.when.get()) }
|
||||
}
|
||||
|
||||
pub fn set_when_internal(&self, when: Option<u64>) {
|
||||
pub(crate) fn set_when_internal(&self, when: Option<u64>) {
|
||||
unsafe {
|
||||
(*self.when.get()) = when;
|
||||
}
|
||||
}
|
||||
|
||||
/// Called by `Timer` to load the current value of `state` for processing
|
||||
pub fn load_state(&self) -> Option<u64> {
|
||||
pub(crate) fn load_state(&self) -> Option<u64> {
|
||||
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<Entry>) {
|
||||
pub(crate) fn cancel(entry: &Arc<Entry>) {
|
||||
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<Result<(), Error>> {
|
||||
pub(crate) fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
||||
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<Entry>) {
|
||||
pub(crate) fn reset(entry: &mut Arc<Entry>) {
|
||||
if !entry.is_registered() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<T: Send + Sync>() {}
|
||||
is_send::<Registration>();
|
||||
|
||||
@@ -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<Stream>`
|
||||
#[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<Result<(), Error>> {
|
||||
pub(crate) fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
||||
self.entry.poll_elapsed(cx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ pub(crate) struct Level<T> {
|
||||
#[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<T: Stack> Level<T> {
|
||||
pub fn new(level: usize) -> Level<T> {
|
||||
pub(crate) fn new(level: usize) -> Level<T> {
|
||||
// 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<T: Stack> Level<T> {
|
||||
|
||||
/// 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<Expiration> {
|
||||
pub(crate) fn next_expiration(&self, now: u64) -> Option<Expiration> {
|
||||
// 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<T: Stack> Level<T> {
|
||||
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<T: Stack> Level<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pop_entry_slot(&mut self, slot: usize, store: &mut T::Store) -> Option<T::Owned> {
|
||||
pub(crate) fn pop_entry_slot(&mut self, slot: usize, store: &mut T::Store) -> Option<T::Owned> {
|
||||
let ret = self.slot[slot].pop(store);
|
||||
|
||||
if ret.is_some() && self.slot[slot].is_empty() {
|
||||
|
||||
@@ -63,7 +63,7 @@ where
|
||||
T: Stack,
|
||||
{
|
||||
/// Create a new timing wheel
|
||||
pub fn new() -> Wheel<T> {
|
||||
pub(crate) fn new() -> Wheel<T> {
|
||||
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<u64> {
|
||||
pub(crate) fn poll_at(&self) -> Option<u64> {
|
||||
self.next_expiration().map(|expiration| expiration.deadline)
|
||||
}
|
||||
|
||||
pub fn poll(&mut self, poll: &mut Poll, store: &mut T::Store) -> Option<T::Owned> {
|
||||
pub(crate) fn poll(&mut self, poll: &mut Poll, store: &mut T::Store) -> Option<T::Owned> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user