]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/supertrait-default-generics.rs
librustc: Remove the fallback to `int` from typechecking.
[rust.git] / src / test / run-pass / supertrait-default-generics.rs
1 // Copyright 2012 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 // There is some other borrowck bug, so we make the stuff not mut.
12
13 trait Positioned<S> {
14   fn SetX(&mut self, S);
15   fn X(&self) -> S;
16 }
17
18 trait Movable<S: Add<S, S>>: Positioned<S> {
19   fn translate(&mut self, dx: S) {
20     let x = self.X() + dx;
21     self.SetX(x);
22   }
23 }
24
25 struct Point<S> { x: S, y: S }
26
27 impl<S: Clone> Positioned<S> for Point<S> {
28     fn SetX(&mut self, x: S) {
29         self.x = x;
30     }
31     fn X(&self) -> S {
32         self.x.clone()
33     }
34 }
35
36 impl<S: Clone + Add<S, S>> Movable<S> for Point<S> {}
37
38 pub fn main() {
39     let mut p = Point{ x: 1i, y: 2i};
40     p.translate(3);
41     assert_eq!(p.X(), 4);
42 }