]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/inconsistent_struct_constructor.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / inconsistent_struct_constructor.txt
1 ### What it does
2 Checks for struct constructors where all fields are shorthand and
3 the order of the field init shorthand in the constructor is inconsistent
4 with the order in the struct definition.
5
6 ### Why is this bad?
7 Since the order of fields in a constructor doesn't affect the
8 resulted instance as the below example indicates,
9
10 ```
11 #[derive(Debug, PartialEq, Eq)]
12 struct Foo {
13     x: i32,
14     y: i32,
15 }
16 let x = 1;
17 let y = 2;
18
19 // This assertion never fails:
20 assert_eq!(Foo { x, y }, Foo { y, x });
21 ```
22
23 inconsistent order can be confusing and decreases readability and consistency.
24
25 ### Example
26 ```
27 struct Foo {
28     x: i32,
29     y: i32,
30 }
31 let x = 1;
32 let y = 2;
33
34 Foo { y, x };
35 ```
36
37 Use instead:
38 ```
39 Foo { x, y };
40 ```