]> git.lizzy.rs Git - rust.git/blob - tests/ui/test-attrs/test-panic-while-printing.rs
Rollup merge of #106714 - Ezrashaw:remove-e0490, r=davidtwco
[rust.git] / tests / ui / test-attrs / test-panic-while-printing.rs
1 // compile-flags:--test
2 // run-pass
3 // needs-unwind
4
5 use std::fmt;
6 use std::fmt::{Display, Formatter};
7
8 pub struct A(Vec<u32>);
9
10 impl Display for A {
11     fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
12         self.0[0];
13         Ok(())
14     }
15 }
16
17 #[test]
18 fn main() {
19     let result = std::panic::catch_unwind(|| {
20         let a = A(vec![]);
21         eprintln!("{}", a);
22     });
23     assert!(result.is_err());
24 }