Skip to content

Commit 90afb20

Browse files
committed
Remove identity_future indirection
This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm. Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]` annotation.
1 parent 0966f59 commit 90afb20

File tree

3 files changed

+3
-23
lines changed

3 files changed

+3
-23
lines changed

clippy_lints/src/manual_async_fn.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::match_function_call_with_def_id;
32
use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt};
43
use if_chain::if_chain;
54
use rustc_errors::Applicability;
@@ -175,16 +174,10 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName])
175174
fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> {
176175
if_chain! {
177176
if let Some(block_expr) = block.expr;
178-
if let Some(args) = cx
179-
.tcx
180-
.lang_items()
181-
.identity_future_fn()
182-
.and_then(|def_id| match_function_call_with_def_id(cx, block_expr, def_id));
183-
if args.len() == 1;
184177
if let Expr {
185178
kind: ExprKind::Closure(&Closure { body, .. }),
186179
..
187-
} = args[0];
180+
} = block_expr;
188181
let closure_body = cx.tcx.hir().body(body);
189182
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
190183
then {

clippy_utils/src/lib.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -1904,16 +1904,7 @@ pub fn is_async_fn(kind: FnKind<'_>) -> bool {
19041904

19051905
/// Peels away all the compiler generated code surrounding the body of an async function,
19061906
pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'tcx Expr<'tcx>> {
1907-
if let ExprKind::Call(
1908-
_,
1909-
&[
1910-
Expr {
1911-
kind: ExprKind::Closure(&Closure { body, .. }),
1912-
..
1913-
},
1914-
],
1915-
) = body.value.kind
1916-
{
1907+
if let ExprKind::Closure(&Closure { body, .. }) = body.value.kind {
19171908
if let ExprKind::Block(
19181909
Block {
19191910
stmts: [],

tests/ui/author/blocks.stdout

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ if let ExprKind::Block(block, None) = expr.kind
4343
if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind
4444
&& let FnRetTy::DefaultReturn(_) = fn_decl.output
4545
&& expr1 = &cx.tcx.hir().body(body_id).value
46-
&& let ExprKind::Call(func, args) = expr1.kind
47-
&& let ExprKind::Path(ref qpath) = func.kind
48-
&& matches!(qpath, QPath::LangItem(LangItem::IdentityFuture, _))
49-
&& args.len() == 1
50-
&& let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind
46+
&& let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = expr1.kind
5147
&& let FnRetTy::DefaultReturn(_) = fn_decl1.output
5248
&& expr2 = &cx.tcx.hir().body(body_id1).value
5349
&& let ExprKind::Block(block, None) = expr2.kind

0 commit comments

Comments
 (0)