]> git.lizzy.rs Git - rust.git/blob - tests/ui/box/thin_drop.rs
Auto merge of #105716 - chriswailes:ndk-update-redux, r=pietroalbini
[rust.git] / tests / ui / box / thin_drop.rs
1 #![feature(thin_box)]
2 // run-pass
3 use std::boxed::ThinBox;
4 use std::error::Error;
5 use std::ops::Deref;
6 use std::fmt;
7
8 fn main() {
9     let expected = "Foo error!";
10     let mut dropped = false;
11     {
12         let foo = Foo(expected, &mut dropped);
13         let a: ThinBox<dyn Error> = ThinBox::new_unsize(foo);
14         let a = a.deref();
15         let msg = a.to_string();
16         assert_eq!(expected, msg);
17     }
18     assert!(dropped);
19 }
20
21 #[derive(Debug)]
22 #[repr(align(1024))]
23 struct Foo<'a>(&'static str, &'a mut bool);
24
25 impl Drop for Foo<'_> {
26     fn drop(&mut self) {
27         *self.1 = true;
28     }
29 }
30
31 impl fmt::Display for Foo<'_> {
32     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33         write!(f, "{}", self.0)
34     }
35 }
36
37 impl Error for Foo<'_> {}