about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authoryifei <lyfmagic99@gmail.com>2023-03-08 20:12:46 +0800
committeryifei <lyfmagic99@gmail.com>2023-03-08 20:12:46 +0800
commit204ba3224ef06f99622fd733cdc14afbc5d83c7e (patch)
tree9b0201348b9226c5c962bbd536e08b376850caf2 /tests
parent38b96553112dce3de630890701f17d86e265f6ba (diff)
downloadrust-204ba3224ef06f99622fd733cdc14afbc5d83c7e.tar.gz
rust-204ba3224ef06f99622fd733cdc14afbc5d83c7e.zip
fix: evaluate with wrong obligation stack
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/traits/unsend-future.rs21
-rw-r--r--tests/ui/traits/unsend-future.stderr24
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/ui/traits/unsend-future.rs b/tests/ui/traits/unsend-future.rs
new file mode 100644
index 00000000000..fbbc07b11e7
--- /dev/null
+++ b/tests/ui/traits/unsend-future.rs
@@ -0,0 +1,21 @@
+// edition:2021
+
+// issue 108897
+trait Handler {}
+impl<F, Fut> Handler for F
+where
+    Fut: Send,
+    F: FnOnce() -> Fut,
+{}
+
+fn require_handler<H: Handler>(h: H) {}
+
+async fn handler() {
+    let a = &1 as *const i32;
+    async {}.await;
+}
+
+fn main() {
+    require_handler(handler)
+     //~^ ERROR future cannot be sent between threads safely
+}
diff --git a/tests/ui/traits/unsend-future.stderr b/tests/ui/traits/unsend-future.stderr
new file mode 100644
index 00000000000..4aaa7c4a924
--- /dev/null
+++ b/tests/ui/traits/unsend-future.stderr
@@ -0,0 +1,24 @@
+error: future cannot be sent between threads safely
+  --> $DIR/unsend-future.rs:19:21
+   |
+LL |     require_handler(handler)
+   |                     ^^^^^^^ future returned by `handler` is not `Send`
+   |
+   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const i32`
+note: future is not `Send` as this value is used across an await
+  --> $DIR/unsend-future.rs:15:13
+   |
+LL |     let a = &1 as *const i32;
+   |         - has type `*const i32` which is not `Send`
+LL |     async {}.await;
+   |             ^^^^^^ await occurs here, with `a` maybe used later
+LL | }
+   | - `a` is later dropped here
+note: required by a bound in `require_handler`
+  --> $DIR/unsend-future.rs:11:23
+   |
+LL | fn require_handler<H: Handler>(h: H) {}
+   |                       ^^^^^^^ required by this bound in `require_handler`
+
+error: aborting due to previous error
+