Skip to content

Commit f6518de

Browse files
authored
Merge pull request #481 from ishitatsuyuki/restyle
Fix some (clippy) warnings
2 parents fc43e4a + 04f8e84 commit f6518de

19 files changed

+36
-43
lines changed

src/future/join_all.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Definition of the JoinAll combinator, waiting for all of a list of futures
1+
//! Definition of the `JoinAll` combinator, waiting for all of a list of futures
22
//! to finish.
33
44
use std::prelude::v1::*;
@@ -94,8 +94,8 @@ impl<I> Future for JoinAll<I>
9494
let mut all_done = true;
9595

9696
for idx in 0 .. self.elems.len() {
97-
let done_val = match &mut self.elems[idx] {
98-
&mut ElemState::Pending(ref mut t) => {
97+
let done_val = match self.elems[idx] {
98+
ElemState::Pending(ref mut t) => {
9999
match t.poll() {
100100
Ok(Async::Ready(v)) => Ok(v),
101101
Ok(Async::NotReady) => {
@@ -105,7 +105,7 @@ impl<I> Future for JoinAll<I>
105105
Err(e) => Err(e),
106106
}
107107
}
108-
&mut ElemState::Done(ref mut _v) => continue,
108+
ElemState::Done(ref mut _v) => continue,
109109
};
110110

111111
match done_val {

src/future/select2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ impl<A, B> Future for Select2<A, B> where A: Future, B: Future {
2323
let (mut a, mut b) = self.inner.take().expect("cannot poll Select2 twice");
2424
match a.poll() {
2525
Err(e) => Err(Either::A((e, b))),
26-
Ok(Async::Ready(x)) => Ok(Async::Ready((Either::A((x, b))))),
26+
Ok(Async::Ready(x)) => Ok(Async::Ready(Either::A((x, b)))),
2727
Ok(Async::NotReady) => match b.poll() {
2828
Err(e) => Err(Either::B((e, a))),
29-
Ok(Async::Ready(x)) => Ok(Async::Ready((Either::B((x, a))))),
29+
Ok(Async::Ready(x)) => Ok(Async::Ready(Either::B((x, a)))),
3030
Ok(Async::NotReady) => {
3131
self.inner = Some((a, b));
3232
Ok(Async::NotReady)

src/future/select_all.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Definition of the SelectAll, finding the first future in a list that
1+
//! Definition of the `SelectAll`, finding the first future in a list that
22
//! finishes.
33
44
use std::mem;

src/future/shared.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::sync::atomic::Ordering::SeqCst;
2525
use std::collections::HashMap;
2626

2727
/// A future that is cloneable and can be polled in multiple threads.
28-
/// Use Future::shared() method to convert any future into a `Shared` future.
28+
/// Use `Future::shared()` method to convert any future into a `Shared` future.
2929
#[must_use = "futures do nothing unless polled"]
3030
pub struct Shared<F: Future> {
3131
inner: Arc<Inner<F>>,

src/sink/send.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<S: Sink> Future for Send<S> {
4545
if let Some(item) = self.item.take() {
4646
if let AsyncSink::NotReady(item) = try!(self.sink_mut().start_send(item)) {
4747
self.item = Some(item);
48-
return Ok(Async::NotReady)
48+
return Ok(Async::NotReady);
4949
}
5050
}
5151

@@ -54,6 +54,6 @@ impl<S: Sink> Future for Send<S> {
5454
try_ready!(self.sink_mut().poll_complete());
5555

5656
// now everything's emptied, so return the sink for further use
57-
return Ok(Async::Ready(self.take_sink()))
57+
Ok(Async::Ready(self.take_sink()))
5858
}
5959
}

src/sink/send_all.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<T, U> SendAll<T, U>
4343
.expect("Attempted to poll Forward after completion");
4444
let fuse = self.stream.take()
4545
.expect("Attempted to poll Forward after completion");
46-
return (sink, fuse.into_inner());
46+
(sink, fuse.into_inner())
4747
}
4848

4949
fn try_start_send(&mut self, item: U::Item) -> Poll<(), T::SinkError> {

src/stream/buffered.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<S> Stream for Buffered<S>
133133
}
134134

135135
// Next, try and step all the futures forward
136-
for future in self.futures.iter_mut() {
136+
for future in &mut self.futures {
137137
let result = match *future {
138138
State::Running(ref mut s) => {
139139
match s.poll() {

src/stream/forward.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<T, U> Forward<T, U>
4545
.expect("Attempted to poll Forward after completion");
4646
let fuse = self.stream.take()
4747
.expect("Attempted to poll Forward after completion");
48-
return (fuse.into_inner(), sink)
48+
(fuse.into_inner(), sink)
4949
}
5050

5151
fn try_start_send(&mut self, item: T::Item) -> Poll<(), U::SinkError> {

src/stream/select.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ impl<S1, S2> Stream for Select<S1, S2>
5555
if !a_done {
5656
self.flag = !self.flag;
5757
}
58-
return Ok(Some(item).into())
58+
Ok(Some(item).into())
5959
}
6060
Async::Ready(None) if a_done => Ok(None.into()),
61-
Async::Ready(None) => Ok(Async::NotReady),
62-
Async::NotReady => Ok(Async::NotReady),
61+
Async::Ready(None) | Async::NotReady => Ok(Async::NotReady),
6362
}
6463
}
6564
}

src/stream/zip.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ impl<S1, S2> Stream for Zip<S1, S2>
3535
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
3636
if self.queued1.is_none() {
3737
match try!(self.stream1.poll()) {
38-
Async::NotReady => {}
3938
Async::Ready(Some(item1)) => self.queued1 = Some(item1),
40-
Async::Ready(None) => {}
39+
Async::Ready(None) | Async::NotReady => {}
4140
}
4241
}
4342
if self.queued2.is_none() {
4443
match try!(self.stream2.poll()) {
45-
Async::NotReady => {}
4644
Async::Ready(Some(item2)) => self.queued2 = Some(item2),
47-
Async::Ready(None) => {}
45+
Async::Ready(None) | Async::NotReady => {}
4846
}
4947
}
5048

tests/all.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ fn result_smoke() {
2727

2828
is_future_v::<i32, u32, _>(f_ok(1).map(|a| a + 1));
2929
is_future_v::<i32, u32, _>(f_ok(1).map_err(|a| a + 1));
30-
is_future_v::<i32, u32, _>(f_ok(1).and_then(|a| Ok(a)));
31-
is_future_v::<i32, u32, _>(f_ok(1).or_else(|a| Err(a)));
30+
is_future_v::<i32, u32, _>(f_ok(1).and_then(Ok));
31+
is_future_v::<i32, u32, _>(f_ok(1).or_else(Err));
3232
is_future_v::<(i32, i32), u32, _>(f_ok(1).join(Err(3)));
33-
is_future_v::<i32, u32, _>(f_ok(1).map(move |a| f_ok(a)).flatten());
33+
is_future_v::<i32, u32, _>(f_ok(1).map(f_ok).flatten());
3434

3535
assert_done(|| f_ok(1), r_ok(1));
3636
assert_done(|| f_err(1), r_err(1));

tests/mpsc-close.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ fn smoke() {
1010
let (mut sender, receiver) = channel(1);
1111

1212
let t = thread::spawn(move ||{
13-
loop {
14-
match sender.send(42).wait() {
15-
Ok(s) => sender = s,
16-
Err(_) => break,
17-
}
13+
while let Ok(s) = sender.send(42).wait() {
14+
sender = s;
1815
}
1916
});
2017

tests/mpsc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ fn stress_shared_unbounded() {
151151
});
152152

153153
for _ in 0..NTHREADS {
154-
let mut tx = tx.clone();
154+
let tx = tx.clone();
155155

156156
thread::spawn(move|| {
157157
for _ in 0..AMT {
158-
mpsc::UnboundedSender::send(&mut tx, 1).unwrap();
158+
mpsc::UnboundedSender::send(&tx, 1).unwrap();
159159
}
160160
});
161161
}

tests/select_all.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ fn smoke() {
2222
assert_eq!(i, 3);
2323
assert_eq!(idx, 0);
2424

25-
assert!(v.len() == 0);
25+
assert!(v.is_empty());
2626
}

tests/select_ok.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ fn ignore_err() {
1414
let (i, v) = select_ok(v).wait().ok().unwrap();
1515
assert_eq!(i, 3);
1616

17-
assert!(v.len() == 1);
17+
assert_eq!(v.len(), 1);
1818

1919
let (i, v) = select_ok(v).wait().ok().unwrap();
2020
assert_eq!(i, 4);
2121

22-
assert!(v.len() == 0);
22+
assert!(v.is_empty());
2323
}
2424

2525
#[test]
@@ -33,7 +33,7 @@ fn last_err() {
3333
let (i, v) = select_ok(v).wait().ok().unwrap();
3434
assert_eq!(i, 1);
3535

36-
assert!(v.len() == 2);
36+
assert_eq!(v.len(), 2);
3737

3838
let i = select_ok(v).wait().err().unwrap();
3939
assert_eq!(i, 3);

tests/shared.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ fn send_shared_oneshot_and_wait_on_multiple_threads(threads_number: u32) {
1616
let threads = (0..threads_number).map(|_| {
1717
let cloned_future = f.clone();
1818
thread::spawn(move || {
19-
assert!(*cloned_future.wait().unwrap() == 6);
19+
assert_eq!(*cloned_future.wait().unwrap(), 6);
2020
})
2121
}).collect::<Vec<_>>();
2222
tx.send(6).unwrap();
23-
assert!(*f.wait().unwrap() == 6);
23+
assert_eq!(*f.wait().unwrap(), 6);
2424
for f in threads {
2525
f.join().unwrap();
2626
}
@@ -57,7 +57,7 @@ fn drop_on_one_task_ok() {
5757
let (tx3, rx3) = oneshot::channel::<u32>();
5858

5959
let t2 = thread::spawn(|| {
60-
drop(f2.map(|x| tx3.send(*x).unwrap()).map_err(|_| ()).wait());
60+
let _ = f2.map(|x| tx3.send(*x).unwrap()).map_err(|_| ()).wait();
6161
});
6262

6363
tx2.send(11).unwrap(); // cancel `f1`

tests/support/local_executor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ impl Core {
7474
let mut task = if let hash_map::Entry::Occupied(x) = self.live.entry(task) { x } else { return };
7575
let result = task.get_mut().poll_future_notify(&notify, 0);
7676
match result {
77-
Ok(Async::Ready(())) => { task.remove(); }
78-
Err(()) => { task.remove(); }
77+
Ok(Async::Ready(())) | Err(()) => { task.remove(); }
7978
Ok(Async::NotReady) => {}
8079
}
8180
}

tests/support/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<F: Future> Future for DelayFuture<F> {
125125
}
126126
}
127127

128-
/// Introduces one Ok(Async::NotReady) before polling the given future
128+
/// Introduces one `Ok(Async::NotReady)` before polling the given future
129129
pub fn delay_future<F>(f: F) -> DelayFuture<F::Future>
130130
where F: IntoFuture,
131131
{

tests/unsync.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn mpsc_backpressure() {
6969
.forward(tx)
7070
.map_err(|e: SendError<i32>| panic!("{}", e))
7171
.join(rx.take(3).collect().map(|xs| {
72-
assert!(xs == [1, 2, 3]);
72+
assert_eq!(xs, [1, 2, 3]);
7373
}))
7474
}).wait().unwrap();
7575
}
@@ -82,7 +82,7 @@ fn mpsc_unbounded() {
8282
.forward(tx)
8383
.map_err(|e: SendError<i32>| panic!("{}", e))
8484
.join(rx.take(3).collect().map(|xs| {
85-
assert!(xs == [1, 2, 3]);
85+
assert_eq!(xs, [1, 2, 3]);
8686
}))
8787
}).wait().unwrap();
8888
}
@@ -92,7 +92,7 @@ fn mpsc_recv_unpark() {
9292
let mut core = Core::new();
9393
let (tx, rx) = mpsc::channel::<i32>(1);
9494
let tx2 = tx.clone();
95-
core.spawn(rx.collect().map(|xs| assert!(xs == [1, 2])));
95+
core.spawn(rx.collect().map(|xs| assert_eq!(xs, [1, 2])));
9696
core.spawn(lazy(move || tx.send(1).map(|_| ()).map_err(|e| panic!("{}", e))));
9797
core.run(lazy(move || tx2.send(2))).unwrap();
9898
}

0 commit comments

Comments
 (0)