|
1 | | -use clippy_utils::diagnostics::span_lint_and_then; |
| 1 | +use clippy_utils::diagnostics::span_lint_hir_and_then; |
2 | 2 | use clippy_utils::is_def_id_trait_method; |
3 | | -use rustc_data_structures::fx::FxHashMap; |
4 | 3 | use rustc_hir::def::DefKind; |
5 | 4 | use rustc_hir::intravisit::{walk_body, walk_expr, walk_fn, FnKind, Visitor}; |
6 | 5 | use rustc_hir::{Body, Expr, ExprKind, FnDecl, Node, YieldSource}; |
@@ -47,11 +46,12 @@ pub struct UnusedAsync { |
47 | 46 | async_fns_as_value: LocalDefIdSet, |
48 | 47 | /// Functions with unused `async`, linted post-crate after we've found all uses of local async |
49 | 48 | /// functions |
50 | | - unused_async_fns: FxHashMap<LocalDefId, UnusedAsyncFn>, |
| 49 | + unused_async_fns: Vec<UnusedAsyncFn>, |
51 | 50 | } |
52 | 51 |
|
53 | 52 | #[derive(Copy, Clone)] |
54 | 53 | struct UnusedAsyncFn { |
| 54 | + def_id: LocalDefId, |
55 | 55 | fn_span: Span, |
56 | 56 | await_in_async_block: Option<Span>, |
57 | 57 | } |
@@ -122,13 +122,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { |
122 | 122 | // Don't lint just yet, but store the necessary information for later. |
123 | 123 | // The actual linting happens in `check_crate_post`, once we've found all |
124 | 124 | // uses of local async functions that do require asyncness to pass typeck |
125 | | - self.unused_async_fns.insert( |
| 125 | + self.unused_async_fns.push(UnusedAsyncFn { |
| 126 | + await_in_async_block: visitor.await_in_async_block, |
| 127 | + fn_span: span, |
126 | 128 | def_id, |
127 | | - UnusedAsyncFn { |
128 | | - await_in_async_block: visitor.await_in_async_block, |
129 | | - fn_span: span, |
130 | | - }, |
131 | | - ); |
| 129 | + }); |
132 | 130 | } |
133 | 131 | } |
134 | 132 | } |
@@ -164,12 +162,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { |
164 | 162 | let iter = self |
165 | 163 | .unused_async_fns |
166 | 164 | .iter() |
167 | | - .filter_map(|(did, item)| (!self.async_fns_as_value.contains(did)).then_some(item)); |
| 165 | + .filter(|UnusedAsyncFn { def_id, .. }| (!self.async_fns_as_value.contains(def_id))); |
168 | 166 |
|
169 | 167 | for fun in iter { |
170 | | - span_lint_and_then( |
| 168 | + span_lint_hir_and_then( |
171 | 169 | cx, |
172 | 170 | UNUSED_ASYNC, |
| 171 | + cx.tcx.local_def_id_to_hir_id(fun.def_id), |
173 | 172 | fun.fn_span, |
174 | 173 | "unused `async` for function with no await statements", |
175 | 174 | |diag| { |
|
0 commit comments