Skip to content

Commit d6f8504

Browse files
committed
improve the run-pass test
1 parent 1b38864 commit d6f8504

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/test/run-pass/panic-uninitialized-zeroed.rs

+34-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,40 @@ struct Foo {
2222

2323
fn main() {
2424
unsafe {
25-
panic::catch_unwind(|| mem::uninitialized::<!>()).is_err();
26-
panic::catch_unwind(|| mem::zeroed::<!>()).is_err();
25+
assert_eq!(
26+
panic::catch_unwind(|| {
27+
mem::uninitialized::<!>()
28+
}).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
29+
s == "Attempted to instantiate uninhabited type ! using mem::uninitialized"
30+
})),
31+
Some(true)
32+
);
2733

28-
panic::catch_unwind(|| mem::uninitialized::<Foo>()).is_err();
29-
panic::catch_unwind(|| mem::zeroed::<Foo>()).is_err();
34+
assert_eq!(
35+
panic::catch_unwind(|| {
36+
mem::zeroed::<!>()
37+
}).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
38+
s == "Attempted to instantiate uninhabited type ! using mem::zeroed"
39+
})),
40+
Some(true)
41+
);
42+
43+
assert_eq!(
44+
panic::catch_unwind(|| {
45+
mem::uninitialized::<Foo>()
46+
}).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
47+
s == "Attempted to instantiate uninhabited type Foo using mem::uninitialized"
48+
})),
49+
Some(true)
50+
);
51+
52+
assert_eq!(
53+
panic::catch_unwind(|| {
54+
mem::zeroed::<Foo>()
55+
}).err().and_then(|a| a.downcast_ref::<String>().map(|s| {
56+
s == "Attempted to instantiate uninhabited type Foo using mem::zeroed"
57+
})),
58+
Some(true)
59+
);
3060
}
3161
}

0 commit comments

Comments
 (0)