|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_help;
|
2 | 2 | use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor};
|
3 |
| -use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnHeader, HirId, IsAsync, YieldSource}; |
| 3 | +use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, IsAsync, YieldSource}; |
4 | 4 | use rustc_lint::{LateContext, LateLintPass};
|
5 | 5 | use rustc_middle::hir::nested_filter;
|
6 | 6 | use rustc_session::{declare_lint_pass, declare_tool_lint};
|
@@ -68,20 +68,18 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
|
68 | 68 | span: Span,
|
69 | 69 | hir_id: HirId,
|
70 | 70 | ) {
|
71 |
| - if let FnKind::ItemFn(_, _, FnHeader { asyncness, .. }) = &fn_kind { |
72 |
| - if matches!(asyncness, IsAsync::Async) { |
73 |
| - let mut visitor = AsyncFnVisitor { cx, found_await: false }; |
74 |
| - walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), span, hir_id); |
75 |
| - if !visitor.found_await { |
76 |
| - span_lint_and_help( |
77 |
| - cx, |
78 |
| - UNUSED_ASYNC, |
79 |
| - span, |
80 |
| - "unused `async` for function with no await statements", |
81 |
| - None, |
82 |
| - "consider removing the `async` from this function", |
83 |
| - ); |
84 |
| - } |
| 71 | + if !span.from_expansion() && fn_kind.asyncness() == IsAsync::Async { |
| 72 | + let mut visitor = AsyncFnVisitor { cx, found_await: false }; |
| 73 | + walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), span, hir_id); |
| 74 | + if !visitor.found_await { |
| 75 | + span_lint_and_help( |
| 76 | + cx, |
| 77 | + UNUSED_ASYNC, |
| 78 | + span, |
| 79 | + "unused `async` for function with no await statements", |
| 80 | + None, |
| 81 | + "consider removing the `async` from this function", |
| 82 | + ); |
85 | 83 | }
|
86 | 84 | }
|
87 | 85 | }
|
|
0 commit comments