]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-13264.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / issue-13264.rs
1 // Copyright 2014 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 // pretty-expanded FIXME #23616
12
13 use std::ops::Deref;
14
15 struct Root {
16     jsref: JSRef
17 }
18
19 impl Deref for Root {
20     type Target = JSRef;
21
22     fn deref<'a>(&'a self) -> &'a JSRef {
23         &self.jsref
24     }
25 }
26
27 #[derive(Copy, Clone)]
28 struct JSRef {
29     node: *const Node
30 }
31
32 impl Deref for JSRef {
33     type Target = Node;
34
35     fn deref<'a>(&'a self) -> &'a Node {
36         self.get()
37     }
38 }
39
40 trait INode {
41     fn RemoveChild(&self);
42 }
43
44 impl INode for JSRef {
45     fn RemoveChild(&self) {
46         self.get().RemoveChild(0)
47     }
48 }
49
50 impl JSRef {
51     fn AddChild(&self) {
52         self.get().AddChild(0);
53     }
54
55     fn get<'a>(&'a self) -> &'a Node {
56         unsafe {
57             &*self.node
58         }
59     }
60 }
61
62 struct Node;
63
64 impl Node {
65     fn RemoveChild(&self, _a: usize) {
66     }
67
68     fn AddChild(&self, _a: usize) {
69     }
70 }
71
72 fn main() {
73     let n = Node;
74     let jsref = JSRef { node: &n };
75     let root = Root { jsref: jsref };
76
77     root.AddChild();
78     jsref.AddChild();
79
80     root.RemoveChild();
81     jsref.RemoveChild();
82 }