]> git.proxmox.com Git - rustc.git/blame - tests/ui/box/thin_new.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / box / thin_new.rs
CommitLineData
04454e1e
FG
1#![feature(thin_box)]
2// run-pass
3use std::boxed::ThinBox;
4use std::error::Error;
5use std::{fmt, mem};
6
7fn 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)]
22struct Foo;
23
24impl fmt::Display for Foo {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "boooo!")
27 }
28}
29
30impl Error for Foo {}