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