about summary refs log tree commit diff
path: root/tests/ui/async-await/async-closures/not-lending.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/async-await/async-closures/not-lending.rs')
-rw-r--r--tests/ui/async-await/async-closures/not-lending.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/ui/async-await/async-closures/not-lending.rs b/tests/ui/async-await/async-closures/not-lending.rs
new file mode 100644
index 00000000000..90832e1a074
--- /dev/null
+++ b/tests/ui/async-await/async-closures/not-lending.rs
@@ -0,0 +1,21 @@
+// aux-build:block-on.rs
+// edition:2021
+
+#![feature(async_closure)]
+
+extern crate block_on;
+
+// Make sure that we can't make an async closure that evaluates to a self-borrow.
+// i.e. that the generator may reference captures, but the future's return type can't.
+
+fn main() {
+    block_on::block_on(async {
+        let s = String::new();
+        let x = async move || -> &String { &s };
+        //~^ ERROR lifetime may not live long enough
+
+        let s = String::new();
+        let x = async move || { &s };
+        //~^ ERROR lifetime may not live long enough
+    });
+}