@@ -112,6 +112,7 @@ mod useless_asref;
112
112
mod utils;
113
113
mod vec_resize_to_zero;
114
114
mod verbose_file_reads;
115
+ mod waker_clone_wake;
115
116
mod wrong_self_convention;
116
117
mod zst_offset;
117
118
@@ -3632,6 +3633,28 @@ declare_clippy_lint! {
3632
3633
"`as_str` used to call a method on `str` that is also available on `String`"
3633
3634
}
3634
3635
3636
+ declare_clippy_lint ! {
3637
+ /// ### What it does
3638
+ /// Checks for usage of `waker.clone().wake()`
3639
+ ///
3640
+ /// ### Why is this bad?
3641
+ /// Cloning the waker is not necessary, `wake_by_ref()` enables the same operation
3642
+ /// without extra cloning/dropping.
3643
+ ///
3644
+ /// ### Example
3645
+ /// ```rust,ignore
3646
+ /// waker.clone().wake();
3647
+ /// ```
3648
+ /// Should be written
3649
+ /// ```rust,ignore
3650
+ /// waker.wake_by_ref();
3651
+ /// ```
3652
+ #[ clippy:: version = "1.75.0" ]
3653
+ pub WAKER_CLONE_WAKE ,
3654
+ perf,
3655
+ "cloning a `Waker` only to wake it"
3656
+ }
3657
+
3635
3658
pub struct Methods {
3636
3659
avoid_breaking_exported_api : bool ,
3637
3660
msrv : Msrv ,
@@ -3777,6 +3800,7 @@ impl_lint_pass!(Methods => [
3777
3800
ITER_OUT_OF_BOUNDS ,
3778
3801
PATH_ENDS_WITH_EXT ,
3779
3802
REDUNDANT_AS_STR ,
3803
+ WAKER_CLONE_WAKE ,
3780
3804
] ) ;
3781
3805
3782
3806
/// Extracts a method call name, args, and `Span` of the method name.
@@ -4365,6 +4389,9 @@ impl Methods {
4365
4389
}
4366
4390
unnecessary_literal_unwrap:: check ( cx, expr, recv, name, args) ;
4367
4391
} ,
4392
+ ( "wake" , [ ] ) => {
4393
+ waker_clone_wake:: check ( cx, expr, recv) ;
4394
+ }
4368
4395
( "write" , [ ] ) => {
4369
4396
readonly_write_lock:: check ( cx, expr, recv) ;
4370
4397
}
0 commit comments