@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
2
2
use clippy_utils:: is_def_id_trait_method;
3
3
use rustc_hir:: def:: DefKind ;
4
4
use rustc_hir:: intravisit:: { FnKind , Visitor , walk_expr, walk_fn} ;
5
- use rustc_hir:: { Body , Expr , ExprKind , FnDecl , Node , YieldSource } ;
5
+ use rustc_hir:: { Body , Expr , ExprKind , FnDecl , HirId , Node , YieldSource } ;
6
6
use rustc_lint:: { LateContext , LateLintPass } ;
7
7
use rustc_middle:: hir:: nested_filter;
8
8
use rustc_session:: impl_lint_pass;
@@ -137,17 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
137
137
}
138
138
}
139
139
140
- fn check_path ( & mut self , cx : & LateContext < ' tcx > , path : & rustc_hir:: Path < ' tcx > , hir_id : rustc_hir:: HirId ) {
141
- fn is_node_func_call ( node : Node < ' _ > , expected_receiver : Span ) -> bool {
142
- matches ! (
143
- node,
144
- Node :: Expr ( Expr {
145
- kind: ExprKind :: Call ( Expr { span, .. } , _) | ExprKind :: MethodCall ( _, Expr { span, .. } , ..) ,
146
- ..
147
- } ) if * span == expected_receiver
148
- )
149
- }
150
-
140
+ fn check_path ( & mut self , cx : & LateContext < ' tcx > , path : & rustc_hir:: Path < ' tcx > , hir_id : HirId ) {
151
141
// Find paths to local async functions that aren't immediately called.
152
142
// E.g. `async fn f() {}; let x = f;`
153
143
// Depending on how `x` is used, f's asyncness might be required despite not having any `await`
@@ -156,7 +146,14 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
156
146
&& let Some ( local_def_id) = def_id. as_local ( )
157
147
&& cx. tcx . def_kind ( def_id) == DefKind :: Fn
158
148
&& cx. tcx . asyncness ( def_id) . is_async ( )
159
- && !is_node_func_call ( cx. tcx . parent_hir_node ( hir_id) , path. span )
149
+ && let parent = cx. tcx . parent_hir_node ( hir_id)
150
+ && !matches ! (
151
+ parent,
152
+ Node :: Expr ( Expr {
153
+ kind: ExprKind :: Call ( Expr { span, .. } , _) ,
154
+ ..
155
+ } ) if * span == path. span
156
+ )
160
157
{
161
158
self . async_fns_as_value . insert ( local_def_id) ;
162
159
}
0 commit comments