about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/borrowck/cloning-in-async-block-121547.rs11
-rw-r--r--tests/ui/borrowck/cloning-in-async-block-121547.stderr22
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/borrowck/cloning-in-async-block-121547.rs b/tests/ui/borrowck/cloning-in-async-block-121547.rs
new file mode 100644
index 00000000000..b2d8dbae977
--- /dev/null
+++ b/tests/ui/borrowck/cloning-in-async-block-121547.rs
@@ -0,0 +1,11 @@
+//@ edition:2021
+
+async fn clone_async_block(value: String) {
+    for _ in 0..10 {
+        async { //~ ERROR: use of moved value: `value` [E0382]
+            drop(value);
+            //~^ HELP: consider cloning the value if the performance cost is acceptable
+        }.await
+    }
+}
+fn main() {}
diff --git a/tests/ui/borrowck/cloning-in-async-block-121547.stderr b/tests/ui/borrowck/cloning-in-async-block-121547.stderr
new file mode 100644
index 00000000000..ae57e0018f8
--- /dev/null
+++ b/tests/ui/borrowck/cloning-in-async-block-121547.stderr
@@ -0,0 +1,22 @@
+error[E0382]: use of moved value: `value`
+  --> $DIR/cloning-in-async-block-121547.rs:5:9
+   |
+LL |   async fn clone_async_block(value: String) {
+   |                              ----- move occurs because `value` has type `String`, which does not implement the `Copy` trait
+LL |       for _ in 0..10 {
+   |       -------------- inside of this loop
+LL | /         async {
+LL | |             drop(value);
+   | |                  ----- use occurs due to use in coroutine
+LL | |
+LL | |         }.await
+   | |_________^ value moved here, in previous iteration of loop
+   |
+help: consider cloning the value if the performance cost is acceptable
+   |
+LL |             drop(value.clone());
+   |                       ++++++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0382`.