]> git.lizzy.rs Git - rust.git/blob - tests/ui/inconsistent_struct_constructor.rs
Auto merge of #7059 - camsteffen:filter-map, r=flip1995
[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 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 { y, x, 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 {
44             z,
45             x,
46             ..Default::default()
47         };
48
49         // Should NOT lint because the order is consistent with the definition.
50         Foo {
51             x,
52             z,
53             ..Default::default()
54         };
55
56         // Should NOT lint because z is not a shorthand init.
57         Foo {
58             z: z,
59             x,
60             ..Default::default()
61         };
62     }
63 }
64
65 fn main() {}