11use clippy_utils:: diagnostics:: span_lint_and_then;
2+ use clippy_utils:: is_def_id_trait_method;
23use 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 } ;
45use rustc_lint:: { LateContext , LateLintPass } ;
56use rustc_middle:: hir:: nested_filter;
67use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -81,20 +82,6 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> {
8182 }
8283}
8384
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-
9885impl < ' tcx > LateLintPass < ' tcx > for UnusedAsync {
9986 fn check_fn (
10087 & mut self ,
@@ -105,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
10592 span : Span ,
10693 def_id : LocalDefId ,
10794 ) {
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) {
10996 let mut visitor = AsyncFnVisitor {
11097 cx,
11198 found_await : false ,
0 commit comments