1
1
use clippy_utils:: diagnostics:: span_lint_and_then;
2
+ use clippy_utils:: is_def_id_trait_method;
2
3
use rustc_hir:: intravisit:: { walk_body, walk_expr, walk_fn, FnKind , Visitor } ;
3
- use rustc_hir:: { Body , Expr , ExprKind , FnDecl , ItemKind , Node , YieldSource } ;
4
+ use rustc_hir:: { Body , Expr , ExprKind , FnDecl , YieldSource } ;
4
5
use rustc_lint:: { LateContext , LateLintPass } ;
5
6
use rustc_middle:: hir:: nested_filter;
6
7
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -81,20 +82,6 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> {
81
82
}
82
83
}
83
84
84
- /// Checks if the `def_id` belongs to a function and that function is part of a trait impl,
85
- /// in which case we shouldn't lint because `async` is part of the trait definition and therefore
86
- /// can't be removed.
87
- fn is_in_trait_impl ( cx : & LateContext < ' _ > , def_id : LocalDefId ) -> bool {
88
- if let Some ( hir_id) = cx. tcx . opt_local_def_id_to_hir_id ( def_id)
89
- && let Node :: Item ( item) = cx. tcx . hir ( ) . get_parent ( hir_id)
90
- && let ItemKind :: Impl ( imp) = item. kind
91
- {
92
- imp. of_trait . is_some ( )
93
- } else {
94
- false
95
- }
96
- }
97
-
98
85
impl < ' tcx > LateLintPass < ' tcx > for UnusedAsync {
99
86
fn check_fn (
100
87
& mut self ,
@@ -105,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
105
92
span : Span ,
106
93
def_id : LocalDefId ,
107
94
) {
108
- if !span. from_expansion ( ) && fn_kind. asyncness ( ) . is_async ( ) && !is_in_trait_impl ( cx, def_id) {
95
+ if !span. from_expansion ( ) && fn_kind. asyncness ( ) . is_async ( ) && !is_def_id_trait_method ( cx, def_id) {
109
96
let mut visitor = AsyncFnVisitor {
110
97
cx,
111
98
found_await : false ,
0 commit comments