2025-07-01 02:46:47 +05:00
|
|
|
//! Check that panics in `Display::fmt` during printing are properly handled.
|
|
|
|
|
|
2020-03-12 13:03:48 -07:00
|
|
|
//@ run-pass
|
2022-03-19 16:13:18 +01:00
|
|
|
//@ needs-unwind
|
2020-03-12 13:03:48 -07:00
|
|
|
|
2020-11-04 00:11:14 +01:00
|
|
|
#![feature(internal_output_capture)]
|
2020-03-12 13:03:48 -07:00
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
use std::fmt::{Display, Formatter};
|
2020-11-04 00:11:14 +01:00
|
|
|
use std::io::set_output_capture;
|
2020-11-03 20:49:02 +01:00
|
|
|
use std::sync::{Arc, Mutex};
|
2020-03-12 13:03:48 -07:00
|
|
|
|
|
|
|
|
pub struct A;
|
|
|
|
|
|
|
|
|
|
impl Display for A {
|
|
|
|
|
fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
|
|
|
|
|
panic!();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
2020-11-04 00:11:14 +01:00
|
|
|
set_output_capture(Some(Arc::new(Mutex::new(Vec::new()))));
|
2025-07-01 02:46:47 +05:00
|
|
|
assert!(
|
|
|
|
|
std::panic::catch_unwind(|| {
|
|
|
|
|
eprintln!("{}", A);
|
|
|
|
|
})
|
|
|
|
|
.is_err()
|
|
|
|
|
);
|
2020-03-12 13:03:48 -07:00
|
|
|
}
|