]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/struct-path-self.rs
Auto merge of #87284 - Aaron1011:remove-paren-special, r=petrochenkov
[rust.git] / src / test / ui / structs-enums / struct-path-self.rs
1 // run-pass
2 use std::ops::Add;
3
4 struct S<T, U = u16> {
5     a: T,
6     b: U,
7 }
8
9 trait Tr {
10     fn f(&self) -> Self;
11 }
12
13 impl<T: Default + Add<u8, Output = T>, U: Default> Tr for S<T, U> {
14     fn f(&self) -> Self {
15         let s = Self { a: Default::default(), b: Default::default() };
16         match s {
17             Self { a, b } => Self { a: a + 1, b: b }
18         }
19     }
20 }
21
22 impl<T: Default, U: Default + Add<u16, Output = U>> S<T, U> {
23     fn g(&self) -> Self {
24         let s = Self { a: Default::default(), b: Default::default() };
25         match s {
26             Self { a, b } => Self { a: a, b: b + 1 }
27         }
28     }
29 }
30
31 impl S<u8> {
32     fn new() -> Self {
33         Self { a: 0, b: 1 }
34     }
35 }
36
37 fn main() {
38     let s0 = S::new();
39     let s1 = s0.f();
40     assert_eq!(s1.a, 1);
41     assert_eq!(s1.b, 0);
42     let s2 = s0.g();
43     assert_eq!(s2.a, 0);
44     assert_eq!(s2.b, 1);
45 }