]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
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 | ||
cdc7bbd5 XL |
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 | ||
f20569fa XL |
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 { x, y, z }; | |
35 | ||
cdc7bbd5 XL |
36 | // Should NOT lint. |
37 | // issue #7069. | |
38 | new_foo!(); | |
39 | ||
f20569fa XL |
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 { x, z, ..Default::default() }; | |
57 | ||
58 | // Should NOT lint because the order is consistent with the definition. | |
59 | Foo { | |
60 | x, | |
61 | z, | |
62 | ..Default::default() | |
63 | }; | |
64 | ||
65 | // Should NOT lint because z is not a shorthand init. | |
66 | Foo { | |
67 | z: z, | |
68 | x, | |
69 | ..Default::default() | |
70 | }; | |
71 | } | |
72 | } | |
73 | ||
74 | fn main() {} |