Skip to content

Fix clippy warning #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fs/dir_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::task::blocking;
///
/// [`os::unix::fs::DirBuilderExt`]: ../os/unix/fs/trait.DirBuilderExt.html
/// [`std::fs::DirBuilder`]: https://doc.rust-lang.org/std/fs/struct.DirBuilder.html
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct DirBuilder {
/// Set to `true` if non-existent parent directories should be created.
recursive: bool,
Expand Down
6 changes: 6 additions & 0 deletions src/fs/open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ impl OpenOptions {
}
}

impl Default for OpenOptions {
fn default() -> Self {
Self::new()
}
}

cfg_if! {
if #[cfg(feature = "docs")] {
use crate::os::unix::fs::OpenOptionsExt;
Expand Down
2 changes: 1 addition & 1 deletion src/io/stderr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Write for Stderr {

// Start the operation asynchronously.
*state = State::Busy(blocking::spawn(async move {
let res = std::io::Write::write(&mut inner.stderr, &mut inner.buf);
let res = std::io::Write::write(&mut inner.stderr, &inner.buf);
inner.last_op = Some(Operation::Write(res));
State::Idle(Some(inner))
}));
Expand Down
2 changes: 1 addition & 1 deletion src/io/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Write for Stdout {

// Start the operation asynchronously.
*state = State::Busy(blocking::spawn(async move {
let res = std::io::Write::write(&mut inner.stdout, &mut inner.buf);
let res = std::io::Write::write(&mut inner.stdout, &inner.buf);
inner.last_op = Some(Operation::Write(res));
State::Idle(Some(inner))
}));
Expand Down
10 changes: 5 additions & 5 deletions src/net/udp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,14 @@ impl UdpSocket {
/// let mdns_addr = Ipv4Addr::new(224, 0, 0, 123);
///
/// let socket = UdpSocket::bind("127.0.0.1:0").await?;
/// socket.join_multicast_v4(&mdns_addr, &interface)?;
/// socket.join_multicast_v4(mdns_addr, interface)?;
/// #
/// # Ok(()) }) }
/// ```
pub fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> {
pub fn join_multicast_v4(&self, multiaddr: Ipv4Addr, interface: Ipv4Addr) -> io::Result<()> {
self.watcher
.get_ref()
.join_multicast_v4(multiaddr, interface)
.join_multicast_v4(&multiaddr, &interface)
}

/// Executes an operation of the `IPV6_ADD_MEMBERSHIP` type.
Expand Down Expand Up @@ -435,10 +435,10 @@ impl UdpSocket {
/// For more information about this option, see [`join_multicast_v4`].
///
/// [`join_multicast_v4`]: #method.join_multicast_v4
pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> {
pub fn leave_multicast_v4(&self, multiaddr: Ipv4Addr, interface: Ipv4Addr) -> io::Result<()> {
self.watcher
.get_ref()
.leave_multicast_v4(multiaddr, interface)
.leave_multicast_v4(&multiaddr, &interface)
}

/// Executes an operation of the `IPV6_DROP_MEMBERSHIP` type.
Expand Down
12 changes: 5 additions & 7 deletions src/stream/stream/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ where
let next = futures_core::ready!(self.as_mut().stream().poll_next(cx));

match next {
Some(v) => match (self.as_mut().predicate())(&v) {
true => Poll::Ready(Some(v)),
false => {
cx.waker().wake_by_ref();
Poll::Pending
}
},
Some(v) if (self.as_mut().predicate())(&v) => Poll::Ready(Some(v)),
Some(_) => {
cx.waker().wake_by_ref();
Poll::Pending
}
None => Poll::Ready(None),
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/stream/stream/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ where
let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));

match item {
Some(v) => match (&mut self.p)(&v) {
true => Poll::Ready(Some(v)),
false => {
cx.waker().wake_by_ref();
Poll::Pending
}
},
Some(v) if (&mut self.p)(&v) => Poll::Ready(Some(v)),
Some(_) => {
cx.waker().wake_by_ref();
Poll::Pending
}
None => Poll::Ready(None),
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/stream/stream/skip_while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ where

match next {
Some(v) => match self.as_mut().predicate() {
Some(p) => match p(&v) {
true => (),
false => {
Some(p) => {
if !p(&v) {
*self.as_mut().predicate() = None;
return Poll::Ready(Some(v));
}
},
}
None => return Poll::Ready(Some(v)),
},
None => return Poll::Ready(None),
Expand Down
2 changes: 1 addition & 1 deletion src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::future::Future;
use crate::task::{Context, Poll, Waker};

/// Set if the mutex is locked.
const LOCK: usize = 1 << 0;
const LOCK: usize = 1;

/// Set if there are tasks blocked on the mutex.
const BLOCKED: usize = 1 << 1;
Expand Down
2 changes: 1 addition & 1 deletion src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::future::Future;
use crate::task::{Context, Poll, Waker};

/// Set if a write lock is held.
const WRITE_LOCK: usize = 1 << 0;
const WRITE_LOCK: usize = 1;

/// Set if there are read operations blocked on the lock.
const BLOCKED_READS: usize = 1 << 1;
Expand Down
3 changes: 1 addition & 2 deletions src/task/block_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ where
let future = task_local::add_finalizer(future);

let future = async move {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For @stjepang: This is not an equivalent transform. Reading the surrounding code, I also don't think that matters, but can you please revalidate?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks fine by me. It doesn't really matter because res is ().

let res = future.await;
future.await;
trace!("block_on completed", {
parent_id: parent_id,
child_id: child_id,
});
res
};

// Pin the future onto the stack.
Expand Down
4 changes: 2 additions & 2 deletions src/task/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn random(n: u32) -> u32 {
use std::num::Wrapping;

thread_local! {
static RNG: Cell<Wrapping<u32>> = Cell::new(Wrapping(1406868647));
static RNG: Cell<Wrapping<u32>> = Cell::new(Wrapping(1_406_868_647));
}

RNG.with(|rng| {
Expand All @@ -152,6 +152,6 @@ fn random(n: u32) -> u32 {
//
// Author: Daniel Lemire
// Source: https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
((x.0 as u64).wrapping_mul(n as u64) >> 32) as u32
((u64::from(x.0)).wrapping_mul(u64::from(n)) >> 32) as u32
})
}
2 changes: 1 addition & 1 deletion src/task/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::future::Future;
use crate::io;

/// Task builder that configures the settings of a new task.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Builder {
pub(crate) name: Option<String>,
}
Expand Down
4 changes: 2 additions & 2 deletions src/task/sleepers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ impl Sleepers {
pub fn wait(&self) {
let mut sleep = self.sleep.lock().unwrap();

if self.notified.swap(false, Ordering::SeqCst) == false {
if !self.notified.swap(false, Ordering::SeqCst) {
*sleep += 1;
let _ = self.wake.wait(sleep).unwrap();
}
}

/// Notifies one thread.
pub fn notify_one(&self) {
if self.notified.load(Ordering::SeqCst) == false {
if !self.notified.load(Ordering::SeqCst) {
let mut sleep = self.sleep.lock().unwrap();

if *sleep > 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/task/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl TaskId {
unsafe { TaskId(NonZeroU64::new_unchecked(id)) }
}

pub(crate) fn as_u64(&self) -> u64 {
pub(crate) fn as_u64(self) -> u64 {
self.0.get()
}
}
Expand Down