about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArpad Borsos <swatinem@swatinem.de>2022-11-18 22:56:22 +0100
committerArpad Borsos <swatinem@swatinem.de>2022-11-24 10:04:27 +0100
commit1ebdcca8b97feca67ce077a2bad87e7655bc774a (patch)
tree2b5a0f7d734821c4748c4da6f516a5435bda250f
parent91d2ce302020391df83620b622acea484c505b72 (diff)
downloadrust-1ebdcca8b97feca67ce077a2bad87e7655bc774a.tar.gz
rust-1ebdcca8b97feca67ce077a2bad87e7655bc774a.zip
Avoid `GenFuture` shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
-rw-r--r--clippy_lints/src/doc.rs4
-rw-r--r--clippy_lints/src/manual_async_fn.rs2
-rw-r--r--tests/ui/author/blocks.stdout2
3 files changed, 3 insertions, 5 deletions
diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs
index 4557e432885..ae5f9424b23 100644
--- a/clippy_lints/src/doc.rs
+++ b/clippy_lints/src/doc.rs
@@ -427,9 +427,7 @@ fn lint_for_missing_headers(
                 let body = cx.tcx.hir().body(body_id);
                 let ret_ty = typeck.expr_ty(body.value);
                 if implements_trait(cx, ret_ty, future, &[]);
-                if let ty::Opaque(_, subs) = ret_ty.kind();
-                if let Some(gen) = subs.types().next();
-                if let ty::Generator(_, subs, _) = gen.kind();
+                if let ty::Generator(_, subs, _) = ret_ty.kind();
                 if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result);
                 then {
                     span_lint(
diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs
index 5c6a342b3d0..6a98df49912 100644
--- a/clippy_lints/src/manual_async_fn.rs
+++ b/clippy_lints/src/manual_async_fn.rs
@@ -177,7 +177,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
         if let Some(args) = cx
             .tcx
             .lang_items()
-            .from_generator_fn()
+            .identity_future_fn()
             .and_then(|def_id| match_function_call_with_def_id(cx, block_expr, def_id));
         if args.len() == 1;
         if let Expr {
diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout
index 9de0550d81d..c6acf24c21e 100644
--- a/tests/ui/author/blocks.stdout
+++ b/tests/ui/author/blocks.stdout
@@ -45,7 +45,7 @@ if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kin
     && expr1 = &cx.tcx.hir().body(body_id).value
     && let ExprKind::Call(func, args) = expr1.kind
     && let ExprKind::Path(ref qpath) = func.kind
-    && matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _))
+    && matches!(qpath, QPath::LangItem(LangItem::IdentityFuture, _))
     && args.len() == 1
     && let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind
     && let FnRetTy::DefaultReturn(_) = fn_decl1.output