]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-3979.rs
auto merge of #19514 : jbranchaud/rust/add-btree-set-bitor, r=Gankro
[rust.git] / src / test / run-pass / issue-3979.rs
1
2 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
3 // file at the top-level directory of this distribution and at
4 // http://rust-lang.org/COPYRIGHT.
5 //
6 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 // option. This file may not be copied, modified, or distributed
10 // except according to those terms.
11
12 trait Positioned {
13   fn SetX(&mut self, int);
14   fn X(&self) -> int;
15 }
16
17 trait Movable: Positioned {
18   fn translate(&mut self, dx: int) {
19     let x = self.X();
20     self.SetX(x + dx);
21   }
22 }
23
24 struct Point { x: int, y: int }
25
26 impl Positioned for Point {
27     fn SetX(&mut self, x: int) {
28         self.x = x;
29     }
30     fn X(&self) -> int {
31         self.x
32     }
33 }
34
35 impl Movable for Point {}
36
37 pub fn main() {
38     let mut p = Point{ x: 1, y: 2};
39     p.translate(3);
40     assert_eq!(p.X(), 4);
41 }