]> git.lizzy.rs Git - rust.git/blob - tests/ui/inconsistent_struct_constructor.fixed
Auto merge of #8374 - Alexendoo:bless-revisions, r=camsteffen
[rust.git] / tests / ui / inconsistent_struct_constructor.fixed
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 { x, y, z };
34
35         // Should NOT lint.
36         // issue #7069.
37         new_foo!();
38
39         // Shoule 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 { x, z, ..Default::default() };
56
57         // Should NOT lint because the order is consistent with the definition.
58         Foo {
59             x,
60             z,
61             ..Default::default()
62         };
63
64         // Should NOT lint because z is not a shorthand init.
65         Foo {
66             z: z,
67             x,
68             ..Default::default()
69         };
70     }
71 }
72
73 fn main() {}