forked from ROMEO/nexosim
Merge pull request #75 from Ben-PH/clippy_all
(chore) clear up some `clippy --all-targets` warns
This commit is contained in:
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -169,7 +169,10 @@ jobs:
|
|||||||
run: cargo fmt --all -- --check
|
run: cargo fmt --all -- --check
|
||||||
|
|
||||||
- name: Run cargo clippy
|
- name: Run cargo clippy
|
||||||
run: cargo clippy --all-features
|
run: |
|
||||||
|
cargo clippy --tests --all-features
|
||||||
|
# See PR#75: https://github.com/asynchronics/nexosim/pull/75
|
||||||
|
cargo clippy --examples --all-features -- -A clippy::new_without_default -A clippy::manual_async_fn
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
name: Docs
|
name: Docs
|
||||||
|
@ -48,18 +48,14 @@ pub enum ModeId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Processor state.
|
/// Processor state.
|
||||||
|
#[derive(Default)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
|
#[default]
|
||||||
Off,
|
Off,
|
||||||
Idle,
|
Idle,
|
||||||
Processing(AutoActionKey),
|
Processing(AutoActionKey),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
State::Off
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Observable<ModeId> for State {
|
impl Observable<ModeId> for State {
|
||||||
fn observe(&self) -> ModeId {
|
fn observe(&self) -> ModeId {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -482,7 +482,7 @@ mod tests {
|
|||||||
|
|
||||||
assert!(matches!(c.pop(), Err(PopError::Empty)));
|
assert!(matches!(c.pop(), Err(PopError::Empty)));
|
||||||
|
|
||||||
assert!(matches!(p.push(|b| RecycleBox::recycle(b, 42)), Ok(_)));
|
assert!(p.push(|b| RecycleBox::recycle(b, 42)).is_ok());
|
||||||
p.close();
|
p.close();
|
||||||
|
|
||||||
assert_eq!(*c.pop().unwrap(), 42);
|
assert_eq!(*c.pop().unwrap(), 42);
|
||||||
@ -493,12 +493,12 @@ mod tests {
|
|||||||
fn queue_closed_by_consumer() {
|
fn queue_closed_by_consumer() {
|
||||||
let (p, mut c) = queue(3);
|
let (p, mut c) = queue(3);
|
||||||
|
|
||||||
assert_eq!(p.is_closed(), false);
|
assert!(!p.is_closed());
|
||||||
assert!(matches!(p.push(|b| RecycleBox::recycle(b, 42)), Ok(_)));
|
assert!(p.push(|b| RecycleBox::recycle(b, 42)).is_ok());
|
||||||
|
|
||||||
c.close();
|
c.close();
|
||||||
|
|
||||||
assert_eq!(p.is_closed(), true);
|
assert!(p.is_closed());
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
p.push(|b| RecycleBox::recycle(b, 13)),
|
p.push(|b| RecycleBox::recycle(b, 13)),
|
||||||
Err(PushError::Closed)
|
Err(PushError::Closed)
|
||||||
|
@ -173,7 +173,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
impl<F: FnOnce()> Drop for RunOnDrop<F> {
|
impl<F: FnOnce()> Drop for RunOnDrop<F> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.drop_fn.take().map(|f| f());
|
if let Some(f) = self.drop_fn.take() {
|
||||||
|
f()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,13 +164,13 @@ fn task_schedule() {
|
|||||||
|
|
||||||
let (future, future_is_alive, output_is_alive) = MonitoredFuture::new(async move { 42 });
|
let (future, future_is_alive, output_is_alive) = MonitoredFuture::new(async move { 42 });
|
||||||
let (promise, runnable, _cancel_token) = spawn(future, schedule_runnable, ());
|
let (promise, runnable, _cancel_token) = spawn(future, schedule_runnable, ());
|
||||||
assert_eq!(future_is_alive.get(), true);
|
assert!(future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
|
|
||||||
// The task should complete immediately when ran.
|
// The task should complete immediately when ran.
|
||||||
runnable.run();
|
runnable.run();
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(42));
|
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(42));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,13 +200,13 @@ fn task_schedule_and_forget() {
|
|||||||
|
|
||||||
let (future, future_is_alive, output_is_alive) = MonitoredFuture::new(async {});
|
let (future, future_is_alive, output_is_alive) = MonitoredFuture::new(async {});
|
||||||
let (runnable, _cancel_token) = spawn_and_forget(future, schedule_runnable, ());
|
let (runnable, _cancel_token) = spawn_and_forget(future, schedule_runnable, ());
|
||||||
assert_eq!(future_is_alive.get(), true);
|
assert!(future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
|
|
||||||
// The task should complete immediately when ran.
|
// The task should complete immediately when ran.
|
||||||
runnable.run();
|
runnable.run();
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -215,25 +215,23 @@ fn task_wake() {
|
|||||||
|
|
||||||
let (sender, receiver) = oneshot::channel();
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
|
||||||
let (future, future_is_alive, output_is_alive) = MonitoredFuture::new(async move {
|
let (future, future_is_alive, output_is_alive) =
|
||||||
let result = receiver.await.unwrap();
|
MonitoredFuture::new(async move { receiver.await.unwrap() });
|
||||||
result
|
|
||||||
});
|
|
||||||
|
|
||||||
let (promise, runnable, _cancel_token) = spawn(future, schedule_runnable, ());
|
let (promise, runnable, _cancel_token) = spawn(future, schedule_runnable, ());
|
||||||
runnable.run();
|
runnable.run();
|
||||||
|
|
||||||
// The future should have been polled but should not have completed.
|
// The future should have been polled but should not have completed.
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
assert!(promise.poll().is_pending());
|
assert!(promise.poll().is_pending());
|
||||||
|
|
||||||
// Wake the task.
|
// Wake the task.
|
||||||
sender.send(42).unwrap();
|
sender.send(42).unwrap();
|
||||||
|
|
||||||
// The task should have been scheduled by the channel sender.
|
// The task should have been scheduled by the channel sender.
|
||||||
assert_eq!(run_scheduled_runnable(), true);
|
assert!(run_scheduled_runnable());
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(42));
|
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(42));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,10 +242,7 @@ fn task_wake_mt() {
|
|||||||
let (sender, receiver) = oneshot::channel();
|
let (sender, receiver) = oneshot::channel();
|
||||||
|
|
||||||
let (promise, runnable, _cancel_token) = spawn(
|
let (promise, runnable, _cancel_token) = spawn(
|
||||||
async move {
|
async move { receiver.await.unwrap() },
|
||||||
let result = receiver.await.unwrap();
|
|
||||||
result
|
|
||||||
},
|
|
||||||
schedule_runnable,
|
schedule_runnable,
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
@ -284,15 +279,15 @@ fn task_wake_and_forget() {
|
|||||||
runnable.run();
|
runnable.run();
|
||||||
|
|
||||||
// The future should have been polled but should not have completed.
|
// The future should have been polled but should not have completed.
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
|
|
||||||
// Wake the task.
|
// Wake the task.
|
||||||
sender.send(42).unwrap();
|
sender.send(42).unwrap();
|
||||||
|
|
||||||
// The task should have been scheduled by the channel sender.
|
// The task should have been scheduled by the channel sender.
|
||||||
assert_eq!(run_scheduled_runnable(), true);
|
assert!(run_scheduled_runnable());
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -321,7 +316,7 @@ fn task_multiple_wake() {
|
|||||||
sender.try_send(3).unwrap();
|
sender.try_send(3).unwrap();
|
||||||
|
|
||||||
// The task should have been scheduled by the channel sender.
|
// The task should have been scheduled by the channel sender.
|
||||||
assert_eq!(run_scheduled_runnable(), true);
|
assert!(run_scheduled_runnable());
|
||||||
assert!(promise.poll().is_pending());
|
assert!(promise.poll().is_pending());
|
||||||
|
|
||||||
// The channel should be empty. Wake the task 2 more times.
|
// The channel should be empty. Wake the task 2 more times.
|
||||||
@ -329,11 +324,11 @@ fn task_multiple_wake() {
|
|||||||
sender.try_send(5).unwrap();
|
sender.try_send(5).unwrap();
|
||||||
|
|
||||||
// The task should have been scheduled by the channel sender.
|
// The task should have been scheduled by the channel sender.
|
||||||
assert_eq!(run_scheduled_runnable(), true);
|
assert!(run_scheduled_runnable());
|
||||||
|
|
||||||
// The task should have completed.
|
// The task should have completed.
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(15));
|
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,13 +396,13 @@ fn task_cancel_scheduled() {
|
|||||||
|
|
||||||
// The future should not be dropped while the `Runnable` exists, even if the
|
// The future should not be dropped while the `Runnable` exists, even if the
|
||||||
// task is cancelled, but the task should be seen as cancelled.
|
// task is cancelled, but the task should be seen as cancelled.
|
||||||
assert_eq!(future_is_alive.get(), true);
|
assert!(future_is_alive.get());
|
||||||
assert!(promise.poll().is_cancelled());
|
assert!(promise.poll().is_cancelled());
|
||||||
|
|
||||||
// An attempt to run the task should now drop the future without polling it.
|
// An attempt to run the task should now drop the future without polling it.
|
||||||
runnable.run();
|
runnable.run();
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -422,8 +417,8 @@ fn task_cancel_unscheduled() {
|
|||||||
|
|
||||||
let (promise, runnable, cancel_token) = spawn(future, schedule_runnable, ());
|
let (promise, runnable, cancel_token) = spawn(future, schedule_runnable, ());
|
||||||
runnable.run();
|
runnable.run();
|
||||||
assert_eq!(future_is_alive.get(), true);
|
assert!(future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
|
|
||||||
// Cancel the task while no `Runnable` exists (the task is not scheduled as
|
// Cancel the task while no `Runnable` exists (the task is not scheduled as
|
||||||
// it needs to be woken by the channel sender first).
|
// it needs to be woken by the channel sender first).
|
||||||
@ -433,8 +428,8 @@ fn task_cancel_unscheduled() {
|
|||||||
|
|
||||||
// The future should be dropped immediately upon cancellation without
|
// The future should be dropped immediately upon cancellation without
|
||||||
// completing.
|
// completing.
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -445,12 +440,12 @@ fn task_cancel_completed() {
|
|||||||
|
|
||||||
let (promise, runnable, cancel_token) = spawn(future, schedule_runnable, ());
|
let (promise, runnable, cancel_token) = spawn(future, schedule_runnable, ());
|
||||||
runnable.run();
|
runnable.run();
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
|
|
||||||
// Cancel the already completed task.
|
// Cancel the already completed task.
|
||||||
cancel_token.cancel();
|
cancel_token.cancel();
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(42));
|
assert_eq!(promise.poll().map(|v| *v), Stage::Ready(42));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,8 +474,8 @@ fn task_drop_promise_scheduled() {
|
|||||||
|
|
||||||
// The task should complete immediately when ran.
|
// The task should complete immediately when ran.
|
||||||
runnable.run();
|
runnable.run();
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -504,9 +499,9 @@ fn task_drop_promise_unscheduled() {
|
|||||||
assert!(sender.send(()).is_ok());
|
assert!(sender.send(()).is_ok());
|
||||||
|
|
||||||
// The task should have been scheduled by the channel sender.
|
// The task should have been scheduled by the channel sender.
|
||||||
assert_eq!(run_scheduled_runnable(), true);
|
assert!(run_scheduled_runnable());
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), true);
|
assert!(output_is_alive.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -538,9 +533,9 @@ fn task_drop_runnable() {
|
|||||||
assert!(sender.send(()).is_ok());
|
assert!(sender.send(()).is_ok());
|
||||||
|
|
||||||
// Drop the task scheduled by the channel sender.
|
// Drop the task scheduled by the channel sender.
|
||||||
assert_eq!(drop_runnable(), true);
|
assert!(drop_runnable());
|
||||||
assert_eq!(future_is_alive.get(), false);
|
assert!(!future_is_alive.get());
|
||||||
assert_eq!(output_is_alive.get(), false);
|
assert!(!output_is_alive.get());
|
||||||
assert!(promise.poll().is_cancelled());
|
assert!(promise.poll().is_cancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -672,9 +672,8 @@ mod tests {
|
|||||||
|
|
||||||
let th_broadcast = thread::spawn(move || {
|
let th_broadcast = thread::spawn(move || {
|
||||||
let iter = block_on(broadcaster.broadcast(MESSAGE)).unwrap();
|
let iter = block_on(broadcaster.broadcast(MESSAGE)).unwrap();
|
||||||
let sum = iter.fold(0, |acc, val| acc + val);
|
|
||||||
|
|
||||||
sum
|
iter.sum::<usize>()
|
||||||
});
|
});
|
||||||
|
|
||||||
let th_recv: Vec<_> = mailboxes
|
let th_recv: Vec<_> = mailboxes
|
||||||
@ -727,11 +726,7 @@ mod tests {
|
|||||||
|
|
||||||
// Send messages reaching only one receiver each.
|
// Send messages reaching only one receiver each.
|
||||||
for id in 0..N_RECV {
|
for id in 0..N_RECV {
|
||||||
sum += broadcaster
|
sum += broadcaster.broadcast(id).await.unwrap().sum::<usize>();
|
||||||
.broadcast(id)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.fold(0, |acc, val| acc + val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast the special value to all receivers.
|
// Broadcast the special value to all receivers.
|
||||||
@ -739,15 +734,11 @@ mod tests {
|
|||||||
.broadcast(BROADCAST_ALL)
|
.broadcast(BROADCAST_ALL)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.fold(0, |acc, val| acc + val);
|
.sum::<usize>();
|
||||||
|
|
||||||
// Send again messages reaching only one receiver each.
|
// Send again messages reaching only one receiver each.
|
||||||
for id in 0..N_RECV {
|
for id in 0..N_RECV {
|
||||||
sum += broadcaster
|
sum += broadcaster.broadcast(id).await.unwrap().sum::<usize>();
|
||||||
.broadcast(id)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.fold(0, |acc, val| acc + val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sum
|
sum
|
||||||
|
@ -567,9 +567,8 @@ mod tests {
|
|||||||
|
|
||||||
let th_broadcast = thread::spawn(move || {
|
let th_broadcast = thread::spawn(move || {
|
||||||
let iter = block_on(broadcaster.broadcast(MESSAGE)).unwrap();
|
let iter = block_on(broadcaster.broadcast(MESSAGE)).unwrap();
|
||||||
let sum = iter.fold(0, |acc, val| acc + val);
|
|
||||||
|
|
||||||
sum
|
iter.sum::<usize>()
|
||||||
});
|
});
|
||||||
|
|
||||||
let th_recv: Vec<_> = mailboxes
|
let th_recv: Vec<_> = mailboxes
|
||||||
@ -622,11 +621,7 @@ mod tests {
|
|||||||
|
|
||||||
// Send messages reaching only one receiver each.
|
// Send messages reaching only one receiver each.
|
||||||
for id in 0..N_RECV {
|
for id in 0..N_RECV {
|
||||||
sum += broadcaster
|
sum += broadcaster.broadcast(id).await.unwrap().sum::<usize>();
|
||||||
.broadcast(id)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.fold(0, |acc, val| acc + val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast the special value to all receivers.
|
// Broadcast the special value to all receivers.
|
||||||
@ -634,15 +629,11 @@ mod tests {
|
|||||||
.broadcast(BROADCAST_ALL)
|
.broadcast(BROADCAST_ALL)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.fold(0, |acc, val| acc + val);
|
.sum::<usize>();
|
||||||
|
|
||||||
// Send again messages reaching only one receiver each.
|
// Send again messages reaching only one receiver each.
|
||||||
for id in 0..N_RECV {
|
for id in 0..N_RECV {
|
||||||
sum += broadcaster
|
sum += broadcaster.broadcast(id).await.unwrap().sum::<usize>();
|
||||||
.broadcast(id)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.fold(0, |acc, val| acc + val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sum
|
sum
|
||||||
|
@ -649,14 +649,12 @@ mod tests {
|
|||||||
let delete_marked_fn =
|
let delete_marked_fn =
|
||||||
|queue: &mut IndexedPriorityQueue<u64, u64>,
|
|queue: &mut IndexedPriorityQueue<u64, u64>,
|
||||||
shadow_queue: &mut BTreeMap<(u64, usize), u64>| {
|
shadow_queue: &mut BTreeMap<(u64, usize), u64>| {
|
||||||
let success = match marked.take() {
|
let success = marked
|
||||||
Some(delete_key) => Some(queue.extract(delete_key).is_some()),
|
.take()
|
||||||
None => None,
|
.map(|delete_key| queue.extract(delete_key).is_some());
|
||||||
};
|
let shadow_success = shadow_marked
|
||||||
let shadow_success = match shadow_marked.take() {
|
.take()
|
||||||
Some(delete_key) => Some(shadow_queue.remove(&delete_key).is_some()),
|
.map(|delete_key| shadow_queue.remove(&delete_key).is_some());
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
assert_eq!(success, shadow_success);
|
assert_eq!(success, shadow_success);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user