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