]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issues/issue-25549-multiple-drop.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / run-pass / issues / issue-25549-multiple-drop.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // run-pass
12 #![allow(unused_variables)]
13 struct Foo<'r>(&'r mut i32);
14
15 impl<'r> Drop for Foo<'r> {
16 fn drop(&mut self) {
17 *self.0 += 1;
18 }
19 }
20
21 trait Trait {}
22 impl<'r> Trait for Foo<'r> {}
23
24 struct Holder<T: ?Sized>(T);
25
26 fn main() {
27 let mut drops = 0;
28
29 {
30 let y = &Holder([Foo(&mut drops)]) as &Holder<[Foo]>;
31 // this used to cause an extra drop of the Foo instance
32 let x = &y.0;
33 }
34 assert_eq!(1, drops);
35
36 drops = 0;
37 {
38 let y = &Holder(Foo(&mut drops)) as &Holder<Trait>;
39 // this used to cause an extra drop of the Foo instance
40 let x = &y.0;
41 }
42 assert_eq!(1, drops);
43 }