impl manual_noop_waker lint#16687
Conversation
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
9ff1a2c to
a64fe9c
Compare
|
Reminder, once the PR becomes ready for a review, use |
It's not vibe coded. I followed example and on that I'll do implementation. It's my first pr in this repo. |
31dfdc6 to
9e5f983
Compare
|
@rustbot ready |
There was a problem hiding this comment.
You haven't addressed the false positives (see #16687 (review))
Did you see? |
|
@rustbot ready |
It doesn't test the same thing. Did you even try to run Clippy on the exact code I gave? trait Wake {
fn wake(self);
}
impl Wake for () {
fn wake(self) {}
}warning: manual implementation of a no-op waker
--> /tmp/t.rs:5:1
|
5 | / impl Wake for () {
6 | | fn wake(self) {}
7 | | }
| |_^
|
= help: use `std::task::Waker::noop()` insteadThis is wrong. @rustbot author |
9e5f983 to
6808bfe
Compare
|
The proper way to check that this is the right trait is to use a diagnostic item when available (it is not the case here), or a type path. All this is described in the Clippy book in the trait checking chapter. |
Fixes #16639
Description
This PR introduces a new lint manual_noop_waker that detects manual, empty implementations of the std::task::Wake trait. These can be replaced with std::task::Waker::noop(), which is more performant (avoids Arc allocation) and cleaner.
Example
Can be replaced with:
I've followed the contribution guidelines
I've added UI tests for the new lint
I've run
cargo dev update_lintschangelog:
[manual_noop_waker]: Added a lint to detect manual no-op Wake implementations.