Skip to content

Commit ebf6667

Browse files
committed
Apply suggestions
1 parent f879096 commit ebf6667

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

clippy_lints/src/methods/waker_clone_wake.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
3-
use clippy_utils::{match_def_path, paths};
3+
use clippy_utils::{is_trait_method, match_def_path, paths};
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::LateContext;
@@ -13,21 +13,19 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'
1313

1414
if let Some(did) = ty.ty_adt_def()
1515
&& match_def_path(cx, did.did(), &paths::WAKER)
16-
&& let ExprKind::MethodCall(func, waker_ref, &[], _) = recv.kind
17-
&& func.ident.name == sym::clone
16+
&& let ExprKind::MethodCall(_, waker_ref, &[], _) = recv.kind
17+
&& is_trait_method(cx, recv, sym::Clone)
1818
{
1919
let mut applicability = Applicability::MachineApplicable;
20+
let snippet = snippet_with_applicability(cx, waker_ref.span.source_callsite(), "..", &mut applicability);
2021

2122
span_lint_and_sugg(
2223
cx,
2324
WAKER_CLONE_WAKE,
2425
expr.span,
2526
"cloning a `Waker` only to wake it",
2627
"replace with",
27-
format!(
28-
"{}.wake_by_ref()",
29-
snippet_with_applicability(cx, waker_ref.span, "..", &mut applicability)
30-
),
28+
format!("{snippet}.wake_by_ref()"),
3129
applicability,
3230
);
3331
}

tests/ui/waker_clone_wake.fixed

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ impl Custom {
55
pub fn wake(self) {}
66
}
77

8+
macro_rules! mac {
9+
($cx:ident) => {
10+
$cx.waker()
11+
};
12+
}
13+
814
pub fn wake(cx: &mut std::task::Context) {
915
cx.waker().wake_by_ref();
1016

11-
// We don't do that for now
17+
mac!(cx).wake_by_ref();
18+
}
19+
20+
pub fn no_lint(cx: &mut std::task::Context, c: &Custom) {
21+
c.clone().wake();
22+
1223
let w = cx.waker().clone();
1324
w.wake();
1425

1526
cx.waker().clone().wake_by_ref();
1627
}
1728

18-
pub fn no_lint(c: &Custom) {
19-
c.clone().wake()
20-
}
21-
2229
fn main() {}

tests/ui/waker_clone_wake.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ impl Custom {
55
pub fn wake(self) {}
66
}
77

8+
macro_rules! mac {
9+
($cx:ident) => {
10+
$cx.waker()
11+
};
12+
}
13+
814
pub fn wake(cx: &mut std::task::Context) {
915
cx.waker().clone().wake();
1016

11-
// We don't do that for now
17+
mac!(cx).clone().wake();
18+
}
19+
20+
pub fn no_lint(cx: &mut std::task::Context, c: &Custom) {
21+
c.clone().wake();
22+
1223
let w = cx.waker().clone();
1324
w.wake();
1425

1526
cx.waker().clone().wake_by_ref();
1627
}
1728

18-
pub fn no_lint(c: &Custom) {
19-
c.clone().wake()
20-
}
21-
2229
fn main() {}

tests/ui/waker_clone_wake.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
error: cloning a `Waker` only to wake it
2-
--> $DIR/waker_clone_wake.rs:9:5
2+
--> $DIR/waker_clone_wake.rs:15:5
33
|
44
LL | cx.waker().clone().wake();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `cx.waker().wake_by_ref()`
66
|
77
= note: `-D clippy::waker-clone-wake` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::waker_clone_wake)]`
99

10-
error: aborting due to previous error
10+
error: cloning a `Waker` only to wake it
11+
--> $DIR/waker_clone_wake.rs:17:5
12+
|
13+
LL | mac!(cx).clone().wake();
14+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `mac!(cx).wake_by_ref()`
15+
16+
error: aborting due to 2 previous errors
1117

0 commit comments

Comments
 (0)