@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
22use clippy_utils:: is_def_id_trait_method;
33use rustc_hir:: def:: DefKind ;
44use 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 } ;
66use rustc_lint:: { LateContext , LateLintPass } ;
77use rustc_middle:: hir:: nested_filter;
88use rustc_session:: impl_lint_pass;
@@ -137,17 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
137137 }
138138 }
139139
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 ) {
151141 // Find paths to local async functions that aren't immediately called.
152142 // E.g. `async fn f() {}; let x = f;`
153143 // 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 {
156146 && let Some ( local_def_id) = def_id. as_local ( )
157147 && cx. tcx . def_kind ( def_id) == DefKind :: Fn
158148 && 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+ )
160157 {
161158 self . async_fns_as_value . insert ( local_def_id) ;
162159 }
0 commit comments