about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2022-11-07 13:16:25 -0800
committerDavid Tolnay <dtolnay@gmail.com>2023-05-14 07:27:20 -0700
commitcbee2a1ec44dcc49a0a10b713d6b5dac66cd7ba6 (patch)
tree16381e32e2eda3df440624ad51ad3d207b3f967b
parent3603a84a3d74d0b70dbbdaa47ed8f8a306f3fe7f (diff)
downloadrust-cbee2a1ec44dcc49a0a10b713d6b5dac66cd7ba6.tar.gz
rust-cbee2a1ec44dcc49a0a10b713d6b5dac66cd7ba6.zip
Add ui test to reproduce non-Send panic temporary
-rw-r--r--tests/ui/macros/panic-temporaries.rs19
-rw-r--r--tests/ui/macros/panic-temporaries.stderr27
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/ui/macros/panic-temporaries.rs b/tests/ui/macros/panic-temporaries.rs
new file mode 100644
index 00000000000..5ca139daf4e
--- /dev/null
+++ b/tests/ui/macros/panic-temporaries.rs
@@ -0,0 +1,19 @@
+// check-fail
+// edition:2021
+
+#![allow(unreachable_code)]
+
+async fn f(_: u8) {}
+
+async fn g() {
+    // Todo returns `!`, so the await is never reached, and in particular the
+    // temporaries inside the formatting machinery are not still alive at the
+    // await point.
+    f(todo!("...")).await;
+}
+
+fn require_send(_: impl Send) {}
+
+fn main() {
+    require_send(g()); //~ future cannot be sent between threads safely
+}
diff --git a/tests/ui/macros/panic-temporaries.stderr b/tests/ui/macros/panic-temporaries.stderr
new file mode 100644
index 00000000000..425409dda69
--- /dev/null
+++ b/tests/ui/macros/panic-temporaries.stderr
@@ -0,0 +1,27 @@
+error: future cannot be sent between threads safely
+  --> $DIR/panic-temporaries.rs:18:18
+   |
+LL |     require_send(g());
+   |                  ^^^ future returned by `g` is not `Send`
+   |
+   = help: the trait `Sync` is not implemented for `core::fmt::Opaque`
+note: future is not `Send` as this value is used across an await
+  --> $DIR/panic-temporaries.rs:12:20
+   |
+LL |     f(todo!("...")).await;
+   |       ------------ ^^^^^^ await occurs here, with `$crate::format_args!($($arg)+)` maybe used later
+   |       |
+   |       has type `ArgumentV1<'_>` which is not `Send`
+note: `$crate::format_args!($($arg)+)` is later dropped here
+  --> $DIR/panic-temporaries.rs:12:26
+   |
+LL |     f(todo!("...")).await;
+   |                          ^
+note: required by a bound in `require_send`
+  --> $DIR/panic-temporaries.rs:15:25
+   |
+LL | fn require_send(_: impl Send) {}
+   |                         ^^^^ required by this bound in `require_send`
+
+error: aborting due to previous error
+