]>
Commit | Line | Data |
---|---|---|
c30ab7b3 SL |
1 | // Copyright 2016 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 | ||
b7449926 | 11 | // run-pass |
c30ab7b3 SL |
12 | use std::ops::Add; |
13 | ||
14 | struct S<T, U = u16> { | |
15 | a: T, | |
16 | b: U, | |
17 | } | |
18 | ||
19 | trait Tr { | |
20 | fn f(&self) -> Self; | |
21 | } | |
22 | ||
23 | impl<T: Default + Add<u8, Output = T>, U: Default> Tr for S<T, U> { | |
24 | fn f(&self) -> Self { | |
25 | let s = Self { a: Default::default(), b: Default::default() }; | |
26 | match s { | |
27 | Self { a, b } => Self { a: a + 1, b: b } | |
28 | } | |
29 | } | |
30 | } | |
31 | ||
32 | impl<T: Default, U: Default + Add<u16, Output = U>> S<T, U> { | |
33 | fn g(&self) -> Self { | |
34 | let s = Self { a: Default::default(), b: Default::default() }; | |
35 | match s { | |
36 | Self { a, b } => Self { a: a, b: b + 1 } | |
37 | } | |
38 | } | |
39 | } | |
40 | ||
41 | impl S<u8> { | |
42 | fn new() -> Self { | |
43 | Self { a: 0, b: 1 } | |
44 | } | |
45 | } | |
46 | ||
47 | fn main() { | |
48 | let s0 = S::new(); | |
49 | let s1 = s0.f(); | |
50 | assert_eq!(s1.a, 1); | |
51 | assert_eq!(s1.b, 0); | |
52 | let s2 = s0.g(); | |
53 | assert_eq!(s2.a, 0); | |
54 | assert_eq!(s2.b, 1); | |
55 | } |