Add a lint to check needless Waker clones
This commit is contained in:
parent
56c8235c99
commit
f8790963d9
8 changed files with 119 additions and 0 deletions
22
tests/ui/waker_clone_wake.fixed
Normal file
22
tests/ui/waker_clone_wake.fixed
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#[derive(Clone)]
|
||||
pub struct Custom;
|
||||
|
||||
impl Custom {
|
||||
pub fn wake(self) {}
|
||||
}
|
||||
|
||||
pub fn wake(cx: &mut std::task::Context) {
|
||||
cx.waker().wake_by_ref();
|
||||
|
||||
// We don't do that for now
|
||||
let w = cx.waker().clone();
|
||||
w.wake();
|
||||
|
||||
cx.waker().clone().wake_by_ref();
|
||||
}
|
||||
|
||||
pub fn no_lint(c: &Custom) {
|
||||
c.clone().wake()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
22
tests/ui/waker_clone_wake.rs
Normal file
22
tests/ui/waker_clone_wake.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#[derive(Clone)]
|
||||
pub struct Custom;
|
||||
|
||||
impl Custom {
|
||||
pub fn wake(self) {}
|
||||
}
|
||||
|
||||
pub fn wake(cx: &mut std::task::Context) {
|
||||
cx.waker().clone().wake();
|
||||
|
||||
// We don't do that for now
|
||||
let w = cx.waker().clone();
|
||||
w.wake();
|
||||
|
||||
cx.waker().clone().wake_by_ref();
|
||||
}
|
||||
|
||||
pub fn no_lint(c: &Custom) {
|
||||
c.clone().wake()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
11
tests/ui/waker_clone_wake.stderr
Normal file
11
tests/ui/waker_clone_wake.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: cloning a `Waker` only to wake it
|
||||
--> $DIR/waker_clone_wake.rs:9:5
|
||||
|
|
||||
LL | cx.waker().clone().wake();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `cx.waker().wake_by_ref()`
|
||||
|
|
||||
= note: `-D clippy::waker-clone-wake` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::waker_clone_wake)]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue