]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-25549-multiple-drop.rs
Auto merge of #79113 - andjo403:raw_vec_ptr, r=m-ou-se
[rust.git] / src / test / ui / issues / issue-25549-multiple-drop.rs
1 // run-pass
2 #![allow(unused_variables)]
3 struct Foo<'r>(&'r mut i32);
4
5 impl<'r> Drop for Foo<'r> {
6     fn drop(&mut self) {
7         *self.0 += 1;
8     }
9 }
10
11 trait Trait {}
12 impl<'r> Trait for Foo<'r> {}
13
14 struct Holder<T: ?Sized>(T);
15
16 fn main() {
17     let mut drops = 0;
18
19     {
20         let y = &Holder([Foo(&mut drops)]) as &Holder<[Foo]>;
21         // this used to cause an extra drop of the Foo instance
22         let x = &y.0;
23     }
24     assert_eq!(1, drops);
25
26     drops = 0;
27     {
28         let y = &Holder(Foo(&mut drops)) as &Holder<dyn Trait>;
29         // this used to cause an extra drop of the Foo instance
30         let x = &y.0;
31     }
32     assert_eq!(1, drops);
33 }