diff options
| author | bors <bors@rust-lang.org> | 2022-06-20 13:10:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-20 13:10:52 +0000 |
| commit | 97d451397de3f97fa586297a7bc2d16908d3d842 (patch) | |
| tree | 7b9c1b532ffda0dddea766c764e6d0a90bfd1468 /clippy_lints/src | |
| parent | 195f2cba458f0dcdce16b2d22212ec148a6126f5 (diff) | |
| parent | a0b107bbb624ab4bf889f916707d2f025964d3be (diff) | |
| download | rust-97d451397de3f97fa586297a7bc2d16908d3d842.tar.gz rust-97d451397de3f97fa586297a7bc2d16908d3d842.zip | |
Auto merge of #9025 - Alexendoo:unused-async-method, r=dswij
unused_async: lint async methods
Now lints:
```rust
impl Foo {
async fn method(&self) -> &'static str {
"no await here"
}
}
```
changelog: [`unused_async`]: lint async methods
Fixes #9024
Diffstat (limited to 'clippy_lints/src')
| -rw-r--r-- | clippy_lints/src/unused_async.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index c8ec4442ab1..a832dfcccaf 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor}; -use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnHeader, HirId, IsAsync, YieldSource}; +use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, IsAsync, YieldSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -68,20 +68,18 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { span: Span, hir_id: HirId, ) { - if let FnKind::ItemFn(_, _, FnHeader { asyncness, .. }) = &fn_kind { - if matches!(asyncness, IsAsync::Async) { - let mut visitor = AsyncFnVisitor { cx, found_await: false }; - walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), span, hir_id); - if !visitor.found_await { - span_lint_and_help( - cx, - UNUSED_ASYNC, - span, - "unused `async` for function with no await statements", - None, - "consider removing the `async` from this function", - ); - } + if !span.from_expansion() && fn_kind.asyncness() == IsAsync::Async { + let mut visitor = AsyncFnVisitor { cx, found_await: false }; + walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), span, hir_id); + if !visitor.found_await { + span_lint_and_help( + cx, + UNUSED_ASYNC, + span, + "unused `async` for function with no await statements", + None, + "consider removing the `async` from this function", + ); } } } |
