]> git.lizzy.rs Git - rust.git/blob - tests/ui/box/thin_zst.rs
Rollup merge of #106944 - Nilstrieb:there-once-was-a-diagnostic, r=WaffleLapkin
[rust.git] / tests / ui / box / thin_zst.rs
1 #![feature(thin_box)]
2 // run-pass
3 use std::boxed::ThinBox;
4 use std::error::Error;
5 use std::{fmt, mem};
6 use std::ops::DerefMut;
7
8 const EXPECTED: &str = "boooo!";
9
10 fn main() {
11     let thin_error: ThinBox<dyn Error> = ThinBox::new_unsize(Foo);
12     assert_eq!(mem::size_of::<*const i32>(), mem::size_of_val(&thin_error));
13     let msg = thin_error.to_string();
14     assert_eq!(EXPECTED, msg);
15
16     let mut thin_concrete_error: ThinBox<Foo> = ThinBox::new(Foo);
17     assert_eq!(mem::size_of::<*const i32>(), mem::size_of_val(&thin_concrete_error));
18     let msg = thin_concrete_error.to_string();
19     assert_eq!(EXPECTED, msg);
20     let inner = thin_concrete_error.deref_mut();
21     let msg = inner.to_string();
22     assert_eq!(EXPECTED, msg);
23 }
24
25 #[derive(Debug)]
26 struct Foo;
27
28 impl fmt::Display for Foo {
29     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30         write!(f, "{}", EXPECTED)
31     }
32 }
33
34 impl Error for Foo {}