]> git.lizzy.rs Git - rust.git/blob - tests/ui/box/thin_new.rs
Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-se
[rust.git] / tests / ui / box / thin_new.rs
1 #![feature(thin_box)]
2 // run-pass
3 use std::boxed::ThinBox;
4 use std::error::Error;
5 use std::{fmt, mem};
6
7 fn main() {
8     let thin_error: ThinBox<dyn Error> = ThinBox::new_unsize(Foo);
9     assert_eq!(mem::size_of::<*const i32>(), mem::size_of_val(&thin_error));
10     println!("{:?}", thin_error);
11
12     let thin = ThinBox::new(42i32);
13     assert_eq!(mem::size_of::<*const i32>(), mem::size_of_val(&thin));
14     println!("{:?}", thin);
15
16     let thin_slice = ThinBox::<[i32]>::new_unsize([1, 2, 3, 4]);
17     assert_eq!(mem::size_of::<*const i32>(), mem::size_of_val(&thin_slice));
18     println!("{:?}", thin_slice);
19 }
20
21 #[derive(Debug)]
22 struct Foo;
23
24 impl fmt::Display for Foo {
25     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26         write!(f, "boooo!")
27     }
28 }
29
30 impl Error for Foo {}