|
| 1 | +// check-pass |
| 2 | +// edition:2018 |
| 3 | + |
| 4 | +#![allow(non_fmt_panics, unreachable_code)] |
| 5 | + |
| 6 | +use std::fmt::{self, Display}; |
| 7 | +use std::marker::PhantomData; |
| 8 | + |
| 9 | +struct NotSend { |
| 10 | + marker: PhantomData<*const u8>, |
| 11 | +} |
| 12 | + |
| 13 | +const NOT_SEND: NotSend = NotSend { marker: PhantomData }; |
| 14 | + |
| 15 | +impl Display for NotSend { |
| 16 | + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 17 | + formatter.write_str("this value does not implement Send") |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +async fn f(_: u8) {} |
| 22 | + |
| 23 | +// Exercises this matcher in panic_2015: |
| 24 | +// ($fmt:expr, $($arg:tt)+) => $crate::panicking::panic_fmt(...) |
| 25 | +async fn panic_fmt() { |
| 26 | + // Panic returns `!`, so the await is never reached, and in particular the |
| 27 | + // temporaries inside the formatting machinery are not still alive at the |
| 28 | + // await point. |
| 29 | + let todo = "..."; |
| 30 | + f(panic!("not yet implemented: {}", todo)).await; |
| 31 | +} |
| 32 | + |
| 33 | +// Exercises ("{}", $arg:expr) => $crate::panicking::panic_display(&$arg) |
| 34 | +async fn panic_display() { |
| 35 | + f(panic!("{}", NOT_SEND)).await; |
| 36 | +} |
| 37 | + |
| 38 | +// Exercises ($msg:expr) => $crate::panicking::panic_str($msg) |
| 39 | +async fn panic_str() { |
| 40 | + f(panic!((NOT_SEND, "...").1)).await; |
| 41 | +} |
| 42 | + |
| 43 | +// Exercises ($msg:expr) => $crate::panicking::unreachable_display(&$msg) |
| 44 | +async fn unreachable_display() { |
| 45 | + f(unreachable!(NOT_SEND)).await; |
| 46 | +} |
| 47 | + |
| 48 | +fn require_send(_: impl Send) {} |
| 49 | + |
| 50 | +fn main() { |
| 51 | + require_send(panic_fmt()); |
| 52 | + require_send(panic_display()); |
| 53 | + require_send(panic_str()); |
| 54 | + require_send(unreachable_display()); |
| 55 | +} |
0 commit comments