2024-02-16 14:02:50 -06:00
|
|
|
//@ check-pass
|
|
|
|
//@ edition:2021
|
2022-11-07 15:16:25 -06:00
|
|
|
|
|
|
|
#![allow(unreachable_code)]
|
|
|
|
|
2023-05-15 04:56:31 -05:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-07 15:16:25 -06:00
|
|
|
async fn f(_: u8) {}
|
|
|
|
|
2023-05-15 04:56:31 -05:00
|
|
|
// 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
|
2022-11-07 15:16:25 -06:00
|
|
|
// temporaries inside the formatting machinery are not still alive at the
|
|
|
|
// await point.
|
2023-05-15 04:56:31 -05:00
|
|
|
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;
|
2022-11-07 15:16:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn require_send(_: impl Send) {}
|
|
|
|
|
|
|
|
fn main() {
|
2023-05-15 04:56:31 -05:00
|
|
|
require_send(panic_fmt());
|
|
|
|
require_send(panic_display());
|
2022-11-07 15:16:25 -06:00
|
|
|
}
|