about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-01-24 17:18:08 +0000
committerMichael Goulet <michael@errs.io>2024-02-06 02:22:57 +0000
commitb2bb51734cd97682cf2124e70ebbb73a3304b6b0 (patch)
tree3a9430d5a071667e88e8787ffc678a039b2e70a4 /compiler/rustc_ast_lowering
parentf067fd6084d750f3797f54b71771c5dbc149726f (diff)
downloadrust-b2bb51734cd97682cf2124e70ebbb73a3304b6b0.tar.gz
rust-b2bb51734cd97682cf2124e70ebbb73a3304b6b0.zip
Make sure that async closures (and fns) only capture their parent callable's parameters by move, and nothing else
Diffstat (limited to 'compiler/rustc_ast_lowering')
-rw-r--r--compiler/rustc_ast_lowering/src/item.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index 6b772c1295f..a122b4c5113 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -1278,10 +1278,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
         };
         let closure_id = coroutine_kind.closure_id();
         let coroutine_expr = self.make_desugared_coroutine_expr(
-            // FIXME(async_closures): This should only move locals,
-            // and not upvars. Capturing closure upvars by ref doesn't
-            // work right now anyways, so whatever.
-            CaptureBy::Value { move_kw: rustc_span::DUMMY_SP },
+            // The default capture mode here is by-ref. Later on during upvar analysis,
+            // we will force the captured arguments to by-move, but for async closures,
+            // we want to make sure that we avoid unnecessarily moving captures, or else
+            // all async closures would default to `FnOnce` as their calling mode.
+            CaptureBy::Ref,
             closure_id,
             return_type_hint,
             body_span,