Skip to content

Lint on no-op implementations of core::task::Wake #16639

@JarredAllen

Description

@JarredAllen

What it does

Lint on no-op implementations of std::task::Wake which can likely be replaced by Waker::noop() in their use.

Advantage

(assuming the Wake implementer is used for the From<Arc<W>> for Waker implementation) Using Waker::noop instead is less code and more performant since it doesn't need to check the reference count on an Arc.

Drawbacks

People might do other things with the Wake trait other than using it to construct a Waker, and if they do then this would be a false positive. I haven't seen any code doing anything like that, but it might exist somewhere.

Example

struct NoopWaker;
impl Wake for NoopWaker {
    fn wake(self: Arc<Self>) {}
    fn wake_by_ref(self: &Arc<Self>) {}
}
let waker = Waker::from(Arc::new(NoopWaker));
let context = Context::from_waker(&waker);

Could be written as:

let context = Context::from_waker(Waker::noop());

Comparison with existing lints

I don't believe there are any similar lints

Additional Context

No response

Metadata

Metadata

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions