summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/inconsistent_struct_constructor.txt
blob: eb682109a54ee74cec3f50cf35b13600f8c534a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
### What it does
Checks for struct constructors where all fields are shorthand and
the order of the field init shorthand in the constructor is inconsistent
with the order in the struct definition.

### Why is this bad?
Since the order of fields in a constructor doesn't affect the
resulted instance as the below example indicates,

```
#[derive(Debug, PartialEq, Eq)]
struct Foo {
    x: i32,
    y: i32,
}
let x = 1;
let y = 2;

// This assertion never fails:
assert_eq!(Foo { x, y }, Foo { y, x });
```

inconsistent order can be confusing and decreases readability and consistency.

### Example
```
struct Foo {
    x: i32,
    y: i32,
}
let x = 1;
let y = 2;

Foo { y, x };
```

Use instead:
```
Foo { x, y };
```