]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/derive-totalsum-attr.rs
Auto merge of #56534 - xfix:copied, r=@SimonSapin
[rust.git] / src / test / run-pass-fulldeps / derive-totalsum-attr.rs
1 // aux-build:custom_derive_plugin_attr.rs
2 // ignore-stage1
3
4 #![feature(plugin, rustc_attrs)]
5 #![plugin(custom_derive_plugin_attr)]
6
7 trait TotalSum {
8     fn total_sum(&self) -> isize;
9 }
10
11 impl TotalSum for isize {
12     fn total_sum(&self) -> isize {
13         *self
14     }
15 }
16
17 struct Seven;
18
19 impl TotalSum for Seven {
20     fn total_sum(&self) -> isize {
21         7
22     }
23 }
24
25 #[rustc_derive_TotalSum]
26 struct Foo {
27     seven: Seven,
28     bar: Bar,
29     baz: isize,
30     #[ignore]
31     nan: NaN,
32 }
33
34 #[rustc_derive_TotalSum]
35 struct Bar {
36     quux: isize,
37     bleh: isize,
38     #[ignore]
39     nan: NaN2
40 }
41
42 struct NaN;
43
44 impl TotalSum for NaN {
45     fn total_sum(&self) -> isize {
46         panic!();
47     }
48 }
49
50 struct NaN2;
51
52 pub fn main() {
53     let v = Foo {
54         seven: Seven,
55         bar: Bar {
56             quux: 9,
57             bleh: 3,
58             nan: NaN2
59         },
60         baz: 80,
61         nan: NaN
62     };
63     assert_eq!(v.total_sum(), 99);
64 }