]> git.lizzy.rs Git - rust.git/blob - tests/ui/inconsistent_struct_constructor.fixed
Auto merge of #7047 - camsteffen:lang-ctor, r=flip1995
[rust.git] / tests / ui / inconsistent_struct_constructor.fixed
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 mod without_base {
17     use super::Foo;
18
19     fn test() {
20         let x = 1;
21         let y = 1;
22         let z = 1;
23
24         // Should lint.
25         Foo { x, y, z };
26
27         // Shoule NOT lint because the order is the same as in the definition.
28         Foo { x, y, z };
29
30         // Should NOT lint because z is not a shorthand init.
31         Foo { y, x, z: z };
32     }
33 }
34
35 mod with_base {
36     use super::Foo;
37
38     fn test() {
39         let x = 1;
40         let z = 1;
41
42         // Should lint.
43         Foo { x, z, ..Default::default() };
44
45         // Should NOT lint because the order is consistent with the definition.
46         Foo {
47             x,
48             z,
49             ..Default::default()
50         };
51
52         // Should NOT lint because z is not a shorthand init.
53         Foo {
54             z: z,
55             x,
56             ..Default::default()
57         };
58     }
59 }
60
61 fn main() {}