diff options
| author | Alejandra González <blyxyas@gmail.com> | 2025-05-05 00:43:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-05 00:43:30 +0000 |
| commit | 689e62b3b20f383d7009db7fcff580f0b0eb5f08 (patch) | |
| tree | 1acb661550bbf46429ef4c2ad57df096bc8412c8 | |
| parent | ea13461967fb97098c5a9f1566e8826dd32f5495 (diff) | |
| parent | 782c6065c40369db84a8e05ad3c8299b30a06b0a (diff) | |
| download | rust-689e62b3b20f383d7009db7fcff580f0b0eb5f08.tar.gz rust-689e62b3b20f383d7009db7fcff580f0b0eb5f08.zip | |
fix: `unused_async` FP on default impl (#14720)
Closes rust-lang/rust-clippy#14704 changelog: [`unused_async`] fix FP on default impl
| -rw-r--r-- | clippy_lints/src/unused_async.rs | 18 | ||||
| -rw-r--r-- | tests/ui/unused_async.rs | 8 |
2 files changed, 24 insertions, 2 deletions
diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 1c1c841e964..8ceaa3dc58e 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::is_def_id_trait_method; use rustc_hir::def::DefKind; use rustc_hir::intravisit::{FnKind, Visitor, walk_expr, walk_fn}; -use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Node, YieldSource}; +use rustc_hir::{Body, Defaultness, Expr, ExprKind, FnDecl, HirId, Node, TraitItem, YieldSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_session::impl_lint_pass; @@ -116,7 +116,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { span: Span, def_id: LocalDefId, ) { - if !span.from_expansion() && fn_kind.asyncness().is_async() && !is_def_id_trait_method(cx, def_id) { + if !span.from_expansion() + && fn_kind.asyncness().is_async() + && !is_def_id_trait_method(cx, def_id) + && !is_default_trait_impl(cx, def_id) + { let mut visitor = AsyncFnVisitor { cx, found_await: false, @@ -189,3 +193,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { } } } + +fn is_default_trait_impl(cx: &LateContext<'_>, def_id: LocalDefId) -> bool { + matches!( + cx.tcx.hir_node_by_def_id(def_id), + Node::TraitItem(TraitItem { + defaultness: Defaultness::Default { .. }, + .. + }) + ) +} diff --git a/tests/ui/unused_async.rs b/tests/ui/unused_async.rs index 5aaf7b9f5b5..433459253dd 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -119,3 +119,11 @@ fn main() { foo(); bar(); } + +mod issue14704 { + use std::sync::Arc; + + trait Action { + async fn cancel(self: Arc<Self>) {} + } +} |
