|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then; |
| 2 | +use clippy_utils::desugared_async_block; |
2 | 3 | use clippy_utils::source::{SpanRangeExt, position_before_rarrow, snippet_block}; |
3 | 4 | use rustc_errors::Applicability; |
4 | 5 | use rustc_hir::intravisit::FnKind; |
5 | | -use rustc_hir::{ |
6 | | - Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl, |
7 | | - FnRetTy, GenericBound, Node, OpaqueTy, TraitRef, Ty, TyKind, |
8 | | -}; |
| 6 | +use rustc_hir::{Body, ExprKind, FnDecl, FnRetTy, GenericBound, Node, OpaqueTy, TraitRef, Ty, TyKind}; |
9 | 7 | use rustc_lint::{LateContext, LateLintPass}; |
10 | 8 | use rustc_middle::middle::resolve_bound_vars::ResolvedArg; |
11 | 9 | use rustc_middle::ty; |
@@ -59,7 +57,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { |
59 | 57 | // Check that the body of the function consists of one async block |
60 | 58 | && let ExprKind::Block(block, _) = body.value.kind |
61 | 59 | && block.stmts.is_empty() |
62 | | - && let Some(closure_body) = desugared_async_block(cx, block) |
| 60 | + && let Some(body_expr) = block.expr |
| 61 | + && let Some((_, closure_body)) = desugared_async_block(cx, body_expr) |
63 | 62 | && let Some(vis_span_opt) = match cx.tcx.hir_node_by_def_id(fn_def_id) { |
64 | 63 | Node::Item(item) => Some(Some(item.vis_span)), |
65 | 64 | Node::ImplItem(impl_item) => Some(impl_item.vis_span()), |
@@ -165,20 +164,6 @@ fn captures_all_lifetimes(cx: &LateContext<'_>, fn_def_id: LocalDefId, opaque_de |
165 | 164 | num_captured_lifetimes == num_early_lifetimes + num_late_lifetimes |
166 | 165 | } |
167 | 166 |
|
168 | | -fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> { |
169 | | - if let Some(&Expr { |
170 | | - kind: ExprKind::Closure(&Closure { kind, body, .. }), |
171 | | - .. |
172 | | - }) = block.expr |
173 | | - && let ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block)) = |
174 | | - kind |
175 | | - { |
176 | | - return Some(cx.tcx.hir_body(body)); |
177 | | - } |
178 | | - |
179 | | - None |
180 | | -} |
181 | | - |
182 | 167 | fn suggested_ret(cx: &LateContext<'_>, output: &Ty<'_>) -> Option<(&'static str, String)> { |
183 | 168 | if let TyKind::Tup([]) = output.kind { |
184 | 169 | let sugg = "remove the return type"; |
|
0 commit comments