Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fengalin committed Nov 17, 2021
1 parent 2fd1551 commit 8b618aa
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 34 deletions.
2 changes: 1 addition & 1 deletion tokio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
rust_2018_idioms,
unreachable_pub
)]
#![deny(intra_doc_link_resolution_failure)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
Expand Down
2 changes: 1 addition & 1 deletion tokio-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
rust_2018_idioms,
unreachable_pub
)]
#![deny(intra_doc_link_resolution_failure)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
Expand Down
2 changes: 1 addition & 1 deletion tokio-tls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
rust_2018_idioms,
unreachable_pub
)]
#![deny(intra_doc_link_resolution_failure)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
Expand Down
2 changes: 1 addition & 1 deletion tokio-tls/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ async fn one_byte_at_a_time() {
match socket.read_exact(&mut buf).await {
Ok(_) => data.extend_from_slice(&buf),
Err(ref err) if err.kind() == ErrorKind::UnexpectedEof => break,
Err(err) => panic!(err),
Err(err) => panic!("{}", err),
}
}
data
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
rust_2018_idioms,
unreachable_pub
)]
#![deny(intra_doc_link_resolution_failure)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
Expand Down
6 changes: 2 additions & 4 deletions tokio/src/io/async_buf_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ pub trait AsyncBufRead: AsyncRead {

macro_rules! deref_async_buf_read {
() => {
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>)
-> Poll<io::Result<&[u8]>>
{
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
Pin::new(&mut **self.get_mut()).poll_fill_buf(cx)
}

fn consume(mut self: Pin<&mut Self>, amt: usize) {
Pin::new(&mut **self).consume(amt)
}
}
};
}

impl<T: ?Sized + AsyncBufRead + Unpin> AsyncBufRead for Box<T> {
Expand Down
10 changes: 6 additions & 4 deletions tokio/src/io/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ macro_rules! deref_async_read {
(**self).prepare_uninitialized_buffer(buf)
}

fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8])
-> Poll<io::Result<usize>>
{
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
Pin::new(&mut **self).poll_read(cx, buf)
}
}
};
}

impl<T: ?Sized + AsyncRead + Unpin> AsyncRead for Box<T> {
Expand Down
7 changes: 2 additions & 5 deletions tokio/src/io/async_seek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ macro_rules! deref_async_seek {
Pin::new(&mut **self).start_seek(cx, pos)
}

fn poll_complete(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<io::Result<u64>> {
fn poll_complete(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
Pin::new(&mut **self).poll_complete(cx)
}
}
};
}

impl<T: ?Sized + AsyncSeek + Unpin> AsyncSeek for Box<T> {
Expand Down
10 changes: 6 additions & 4 deletions tokio/src/io/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ pub trait AsyncWrite {

macro_rules! deref_async_write {
() => {
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8])
-> Poll<io::Result<usize>>
{
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
Pin::new(&mut **self).poll_write(cx, buf)
}

Expand All @@ -166,7 +168,7 @@ macro_rules! deref_async_write {
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Pin::new(&mut **self).poll_shutdown(cx)
}
}
};
}

impl<T: ?Sized + AsyncWrite + Unpin> AsyncWrite for Box<T> {
Expand Down
2 changes: 2 additions & 0 deletions tokio/src/io/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ impl<T: AsyncWrite> AsyncWrite for WriteHalf<T> {

impl<T> Inner<T> {
fn poll_lock(&self, cx: &mut Context<'_>) -> Poll<Guard<'_, T>> {
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
if !self.locked.compare_and_swap(false, true, Acquire) {
Poll::Ready(Guard { inner: self })
} else {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
rust_2018_idioms,
unreachable_pub
)]
#![deny(intra_doc_link_resolution_failure)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
Expand Down
6 changes: 4 additions & 2 deletions tokio/src/loom/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ pub(crate) mod sync {
pub(crate) use crate::loom::std::atomic_usize::AtomicUsize;

pub(crate) use std::sync::atomic::AtomicU8;
pub(crate) use std::sync::atomic::{fence, AtomicPtr};
pub(crate) use std::sync::atomic::{spin_loop_hint, AtomicBool};
pub(crate) use std::sync::atomic::{fence, AtomicBool, AtomicPtr};
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
pub(crate) use std::sync::atomic::spin_loop_hint;
}
}

Expand Down
1 change: 0 additions & 1 deletion tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ macro_rules! cfg_macros {
$(
#[cfg(feature = "macros")]
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
#[doc(inline)]
$item
)*
}
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl Command {
/// Basic usage:
///
/// ```no_run
/// use tokio::process::Command;;
/// use tokio::process::Command;
/// use std::process::Stdio;
///
/// let command = Command::new("ls")
Expand All @@ -426,7 +426,7 @@ impl Command {
/// Basic usage:
///
/// ```no_run
/// use tokio::process::Command;;
/// use tokio::process::Command;
/// use std::process::{Stdio};
///
/// let command = Command::new("ls")
Expand Down
14 changes: 14 additions & 0 deletions tokio/src/runtime/thread_pool/queue/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ impl<T> Queue<T> {
Err(v) => task = v,
}

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
atomic::spin_loop_hint();
}
}
Expand Down Expand Up @@ -107,6 +109,8 @@ impl<T> Queue<T> {
// work. This is because all tasks are pushed into the queue from the
// current thread (or memory has been acquired if the local queue handle
// moved).
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = self.head.compare_and_swap(head, head + n, Release);
if actual != head {
// We failed to claim the tasks, losing the race. Return out of
Expand Down Expand Up @@ -174,6 +178,8 @@ impl<T> Queue<T> {
});

// Attempt to claim the task read above.
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = self
.head
.compare_and_swap(head, head.wrapping_add(1), Release);
Expand All @@ -182,6 +188,8 @@ impl<T> Queue<T> {
return Some(task.assume_init());
}

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
atomic::spin_loop_hint();
}
}
Expand Down Expand Up @@ -244,6 +252,8 @@ impl<T> Queue<T> {
}

if n > LOCAL_QUEUE_CAPACITY as u32 / 2 {
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
atomic::spin_loop_hint();
// inconsistent, try again
continue;
Expand Down Expand Up @@ -273,6 +283,8 @@ impl<T> Queue<T> {
}

// Claim all of those tasks!
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = self
.head
.compare_and_swap(src_head, src_head.wrapping_add(n), Release);
Expand All @@ -282,6 +294,8 @@ impl<T> Queue<T> {
return n;
}

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
atomic::spin_loop_hint();
}
}
Expand Down
2 changes: 2 additions & 0 deletions tokio/src/runtime/thread_pool/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ impl Worker {

// The lock is only to establish mutual exclusion. Other synchronization
// handles memory orderings
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let prev = owned.generation.compare_and_swap(
self.generation,
self.generation.wrapping_add(1),
Expand Down
7 changes: 6 additions & 1 deletion tokio/src/sync/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@
use crate::loom::cell::CausalCell;
use crate::loom::future::AtomicWaker;
use crate::loom::sync::atomic::{spin_loop_hint, AtomicBool, AtomicPtr, AtomicUsize};
use crate::loom::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize};
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
use crate::loom::sync::atomic::spin_loop_hint;
use crate::loom::sync::{Arc, Condvar, Mutex};

use std::fmt;
Expand Down Expand Up @@ -671,6 +674,8 @@ impl<T> Receiver<T> {
if !slot.try_rx_lock() {
if spin {
while !slot.try_rx_lock() {
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
spin_loop_hint();
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions tokio/src/sync/mpsc/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ impl<T> Block<T> {
) -> Result<(), NonNull<Block<T>>> {
block.as_mut().start_index = self.start_index.wrapping_add(BLOCK_CAP);

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let next_ptr = self
.next
.compare_and_swap(ptr::null_mut(), block.as_ptr(), ordering);
Expand Down Expand Up @@ -308,6 +310,8 @@ impl<T> Block<T> {
//
// `Release` ensures that the newly allocated block is available to
// other threads acquiring the next pointer.
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let next = NonNull::new(self.next.compare_and_swap(
ptr::null_mut(),
new_block.as_ptr(),
Expand Down
2 changes: 2 additions & 0 deletions tokio/src/sync/mpsc/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ impl<T> Tx<T> {
//
// Acquire is not needed as any "actual" value is not accessed.
// At this point, the linked list is walked to acquire blocks.
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual =
self.block_tail
.compare_and_swap(block_ptr, next_block.as_ptr(), Release);
Expand Down
4 changes: 4 additions & 0 deletions tokio/src/sync/task/atomic_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ impl AtomicWaker {
where
W: WakerRef,
{
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
match self.state.compare_and_swap(WAITING, REGISTERING, Acquire) {
WAITING => {
unsafe {
Expand Down Expand Up @@ -220,6 +222,8 @@ impl AtomicWaker {
waker.wake();

// This is equivalent to a spin lock, so use a spin hint.
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
atomic::spin_loop_hint();
}
state => {
Expand Down
2 changes: 2 additions & 0 deletions tokio/src/time/driver/atomic_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ impl AtomicStack {
*(entry.next_atomic.get()) = curr;
}

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = self.head.compare_and_swap(curr, ptr, SeqCst);

if actual == curr {
Expand Down
6 changes: 6 additions & 0 deletions tokio/src/time/driver/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ impl Entry {
}

let next = ELAPSED | curr;
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = self.state.compare_and_swap(curr, next, SeqCst);

if curr == actual {
Expand All @@ -200,6 +202,8 @@ impl Entry {

let next = ERROR;

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = self.state.compare_and_swap(curr, next, SeqCst);

if curr == actual {
Expand Down Expand Up @@ -288,6 +292,8 @@ impl Entry {
notify = true;
}

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = entry.state.compare_and_swap(curr, next, SeqCst);

if curr == actual {
Expand Down
2 changes: 2 additions & 0 deletions tokio/src/time/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ impl Inner {
return Err(Error::at_capacity());
}

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
let actual = self.num.compare_and_swap(curr, curr + 1, SeqCst);

if curr == actual {
Expand Down
2 changes: 0 additions & 2 deletions tokio/src/time/tests/test_delay.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![warn(rust_2018_idioms)]

use crate::park::{Park, Unpark};
use crate::time::driver::{Driver, Entry, Handle};
use crate::time::Clock;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/time/throttle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use pin_project_lite::pin_project;
/// # Example
///
/// Create a throttled stream.
/// ```rust,norun
/// ```rust,no_run
/// use std::time::Duration;
/// use tokio::stream::StreamExt;
/// use tokio::time::throttle;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/time/wheel/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<T: Stack> Level<T> {
() => {
T::default()
};
};
}

Level {
level,
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/support/mock_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Read for &'_ File {
assert!(dst.len() >= data.len());
assert!(dst.len() <= 16 * 1024, "actual = {}", dst.len()); // max buffer

&mut dst[..data.len()].copy_from_slice(&data);
let _ = &mut dst[..data.len()].copy_from_slice(&data);
Ok(data.len())
}
Some(Read(Err(e))) => Err(e),
Expand Down

0 comments on commit 8b618aa

Please sign in to comment.