Skip to content

Commit 0ebb5cb

Browse files
committed
Add test coverage of more varieties of panic temporaries
1 parent 0bcfd2d commit 0ebb5cb

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}

tests/ui/macros/panic-temporaries.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,41 @@
33

44
#![allow(unreachable_code)]
55

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+
621
async fn f(_: u8) {}
722

8-
async fn g() {
9-
// Todo returns `!`, so the await is never reached, and in particular the
23+
// Exercises this matcher in panic_2021:
24+
// ($($t:tt)+) => $crate::panicking::panic_fmt(...)
25+
async fn panic_fmt() {
26+
// Panic returns `!`, so the await is never reached, and in particular the
1027
// temporaries inside the formatting machinery are not still alive at the
1128
// await point.
12-
f(todo!("...")).await;
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;
1336
}
1437

1538
fn require_send(_: impl Send) {}
1639

1740
fn main() {
18-
require_send(g());
41+
require_send(panic_fmt());
42+
require_send(panic_display());
1943
}

0 commit comments

Comments
 (0)