]> git.lizzy.rs Git - rust.git/blob - tests/ui/inconsistent_struct_constructor.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / inconsistent_struct_constructor.rs
1 // run-rustfix
2 #![warn(clippy::inconsistent_struct_constructor)]
3 #![allow(clippy::redundant_field_names)]
4 #![allow(clippy::unnecessary_operation)]
5 #![allow(clippy::no_effect)]
6 #![allow(dead_code)]
7
8 #[derive(Default)]
9 struct Foo {
10     x: i32,
11     y: i32,
12     z: i32,
13 }
14
15 macro_rules! new_foo {
16     () => {
17         let x = 1;
18         let y = 1;
19         let z = 1;
20         Foo { y, x, z }
21     };
22 }
23
24 mod without_base {
25     use super::Foo;
26
27     fn test() {
28         let x = 1;
29         let y = 1;
30         let z = 1;
31
32         // Should lint.
33         Foo { y, x, z };
34
35         // Should NOT lint.
36         // issue #7069.
37         new_foo!();
38
39         // Should NOT lint because the order is the same as in the definition.
40         Foo { x, y, z };
41
42         // Should NOT lint because z is not a shorthand init.
43         Foo { y, x, z: z };
44     }
45 }
46
47 mod with_base {
48     use super::Foo;
49
50     fn test() {
51         let x = 1;
52         let z = 1;
53
54         // Should lint.
55         Foo {
56             z,
57             x,
58             ..Default::default()
59         };
60
61         // Should NOT lint because the order is consistent with the definition.
62         Foo {
63             x,
64             z,
65             ..Default::default()
66         };
67
68         // Should NOT lint because z is not a shorthand init.
69         Foo {
70             z: z,
71             x,
72             ..Default::default()
73         };
74     }
75 }
76
77 fn main() {}