about summary refs log tree commit diff
path: root/tests/ui/macros/panic-temporaries.rs
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2023-05-15 02:56:31 -0700
committerDavid Tolnay <dtolnay@gmail.com>2023-05-15 03:47:37 -0700
commit0ebb5cbab62e42b2e71ff8bfe6e30a8a51b59d4b (patch)
tree61deacbfe7282fb1b8d83d159c158cceb55347f1 /tests/ui/macros/panic-temporaries.rs
parent0bcfd2d96efe7a2cb5205c3af1b9eea17423fe65 (diff)
downloadrust-0ebb5cbab62e42b2e71ff8bfe6e30a8a51b59d4b.tar.gz
rust-0ebb5cbab62e42b2e71ff8bfe6e30a8a51b59d4b.zip
Add test coverage of more varieties of panic temporaries
Diffstat (limited to 'tests/ui/macros/panic-temporaries.rs')
-rw-r--r--tests/ui/macros/panic-temporaries.rs32
1 files changed, 28 insertions, 4 deletions
diff --git a/tests/ui/macros/panic-temporaries.rs b/tests/ui/macros/panic-temporaries.rs
index 5b5b8b7c2d9..db65601fb73 100644
--- a/tests/ui/macros/panic-temporaries.rs
+++ b/tests/ui/macros/panic-temporaries.rs
@@ -3,17 +3,41 @@
 
 #![allow(unreachable_code)]
 
+use std::fmt::{self, Display};
+use std::marker::PhantomData;
+
+struct NotSend {
+    marker: PhantomData<*const u8>,
+}
+
+const NOT_SEND: NotSend = NotSend { marker: PhantomData };
+
+impl Display for NotSend {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter.write_str("this value does not implement Send")
+    }
+}
+
 async fn f(_: u8) {}
 
-async fn g() {
-    // Todo returns `!`, so the await is never reached, and in particular the
+// Exercises this matcher in panic_2021:
+// ($($t:tt)+) => $crate::panicking::panic_fmt(...)
+async fn panic_fmt() {
+    // Panic 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;
+    let todo = "...";
+    f(panic!("not yet implemented: {}", todo)).await;
+}
+
+// Exercises ("{}", $arg:expr) => $crate::panicking::panic_display(&$arg)
+async fn panic_display() {
+    f(panic!("{}", NOT_SEND)).await;
 }
 
 fn require_send(_: impl Send) {}
 
 fn main() {
-    require_send(g());
+    require_send(panic_fmt());
+    require_send(panic_display());
 }