]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/superdefault-generics.rs
Auto merge of #87284 - Aaron1011:remove-paren-special, r=petrochenkov
[rust.git] / src / test / ui / traits / superdefault-generics.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(non_snake_case)]
4
5 // There is some other borrowck bug, so we make the stuff not mut.
6
7
8 use std::ops::Add;
9
10 trait Positioned<S> {
11   fn SetX(&mut self, _: S);
12   fn X(&self) -> S;
13 }
14
15 trait Movable<S: Add<Output=S>>: Positioned<S> {
16   fn translate(&mut self, dx: S) {
17     let x = self.X() + dx;
18     self.SetX(x);
19   }
20 }
21
22 struct Point<S> { x: S, y: S }
23
24 impl<S: Clone> Positioned<S> for Point<S> {
25     fn SetX(&mut self, x: S) {
26         self.x = x;
27     }
28     fn X(&self) -> S {
29         self.x.clone()
30     }
31 }
32
33 impl<S: Clone + Add<Output=S>> Movable<S> for Point<S> {}
34
35 pub fn main() {
36     let mut p = Point{ x: 1, y: 2};
37     p.translate(3);
38     assert_eq!(p.X(), 4);
39 }