Skip to content

Commit 689e62b

Browse files
authored
fix: unused_async FP on default impl (#14720)
Closes #14704 changelog: [`unused_async`] fix FP on default impl
2 parents ea13461 + 782c606 commit 689e62b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

clippy_lints/src/unused_async.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::is_def_id_trait_method;
33
use rustc_hir::def::DefKind;
44
use rustc_hir::intravisit::{FnKind, Visitor, walk_expr, walk_fn};
5-
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Node, YieldSource};
5+
use rustc_hir::{Body, Defaultness, Expr, ExprKind, FnDecl, HirId, Node, TraitItem, YieldSource};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::hir::nested_filter;
88
use rustc_session::impl_lint_pass;
@@ -116,7 +116,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
116116
span: Span,
117117
def_id: LocalDefId,
118118
) {
119-
if !span.from_expansion() && fn_kind.asyncness().is_async() && !is_def_id_trait_method(cx, def_id) {
119+
if !span.from_expansion()
120+
&& fn_kind.asyncness().is_async()
121+
&& !is_def_id_trait_method(cx, def_id)
122+
&& !is_default_trait_impl(cx, def_id)
123+
{
120124
let mut visitor = AsyncFnVisitor {
121125
cx,
122126
found_await: false,
@@ -189,3 +193,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
189193
}
190194
}
191195
}
196+
197+
fn is_default_trait_impl(cx: &LateContext<'_>, def_id: LocalDefId) -> bool {
198+
matches!(
199+
cx.tcx.hir_node_by_def_id(def_id),
200+
Node::TraitItem(TraitItem {
201+
defaultness: Defaultness::Default { .. },
202+
..
203+
})
204+
)
205+
}

tests/ui/unused_async.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,11 @@ fn main() {
119119
foo();
120120
bar();
121121
}
122+
123+
mod issue14704 {
124+
use std::sync::Arc;
125+
126+
trait Action {
127+
async fn cancel(self: Arc<Self>) {}
128+
}
129+
}

0 commit comments

Comments
 (0)