@@ -13,7 +13,23 @@ declare_clippy_lint! {
13
13
/// **What it does:** Checks for struct constructors where the order of the field init
14
14
/// shorthand in the constructor is inconsistent with the order in the struct definition.
15
15
///
16
- /// **Why is this bad?** It decreases readability and consistency.
16
+ /// **Why is this bad?** Since the order of fields in a constructor doesn't affect the
17
+ /// resulted instance as the below example indicates,
18
+ ///
19
+ /// ```rust
20
+ /// #[derive(Debug, PartialEq, Eq)]
21
+ /// struct Foo {
22
+ /// x: i32,
23
+ /// y: i32,
24
+ /// }
25
+ /// let x = 1;
26
+ /// let y = 2;
27
+ ///
28
+ /// // This assertion never fails.
29
+ /// assert_eq!(Foo { x, y }, Foo { y, x });
30
+ /// ```
31
+ ///
32
+ /// inconsistent order means nothing and just decreases readability and consistency.
17
33
///
18
34
/// **Known problems:** None.
19
35
///
@@ -74,12 +90,12 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
74
90
for ident in idents {
75
91
fields_snippet. push_str( & format!( "{}, " , ident) ) ;
76
92
}
77
- fields_snippet. push_str( & format! ( "{}" , last_ident) ) ;
93
+ fields_snippet. push_str( & last_ident. to_string ( ) ) ;
78
94
79
95
let base_snippet = if let Some ( base) = base {
80
96
format!( ", ..{}" , snippet( cx, base. span, ".." ) )
81
97
} else {
82
- "" . to_string ( )
98
+ String :: new ( )
83
99
} ;
84
100
85
101
let sugg = format!( "{} {{ {}{} }}" ,
0 commit comments