You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clippy_lints/src/field_reassign_with_default.rs
+8-10
Original file line number
Diff line number
Diff line change
@@ -11,29 +11,27 @@ declare_clippy_lint! {
11
11
/// **What it does:** Checks for immediate reassignment of fields initialized
12
12
/// with Default::default().
13
13
///
14
-
/// **Why is this bad?** Fields should be set using
15
-
/// T { field: value, ..Default::default() } syntax instead of using a mutable binding.
14
+
/// **Why is this bad?**It's more idiomatic to use [functional update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax).
16
15
///
17
-
/// **Known problems:** The lint does not detect calls to Default::default()
18
-
/// if they are made via another struct implementing the Default trait. If type inference stops
19
-
/// requiring an explicit type for assignment using Default::default() this lint will not
20
-
/// trigger for cases where the type is elided.
16
+
/// **Known problems:** None.
21
17
///
22
18
/// **Example:**
23
19
/// Bad:
24
-
/// ```ignore
20
+
/// ```
21
+
/// # struct A { i: i32 }
25
22
/// let mut a: A = Default::default();
26
23
/// a.i = 42;
27
24
/// ```
28
25
/// Use instead:
29
-
/// ```ignore
26
+
/// ```
27
+
/// # struct A { i: i32 }
30
28
/// let a = A {
31
29
/// i: 42,
32
30
/// .. Default::default()
33
31
/// };
34
32
/// ```
35
33
pubFIELD_REASSIGN_WITH_DEFAULT,
36
-
pedantic,
34
+
style,
37
35
"binding initialized with Default should have its fields set in the initializer"
38
36
}
39
37
@@ -56,7 +54,7 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
0 commit comments