Skip to content

Commit 265cd86

Browse files
author
Henri Lunnikivi
committed
Add doc for field_reassign_with_default
1 parent 447d672 commit 265cd86

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

clippy_lints/src/field_reassign_with_default.rs

+25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ use syntax::print::pprust::{expr_to_string, ty_to_string};
77
use syntax::symbol::Symbol;
88

99
declare_clippy_lint! {
10+
/// **What it does:** Checks for immediate reassignment of fields initialized
11+
/// with Default::default().
12+
///
13+
/// **Why is this bad?** Fields should be set using
14+
/// T { field: value, ..Default::default() } syntax instead of using a mutable binding.
15+
///
16+
/// **Known problems:** The lint does not detect calls to Default::default()
17+
/// if they are made via another struct implementing the Default trait. This
18+
/// may be corrected with a LateLintPass. If type inference stops requiring
19+
/// an explicit type for assignment using Default::default() this lint will
20+
/// not trigger for cases where the type is elided. This may also be corrected
21+
/// with a LateLintPass.
22+
///
23+
/// **Example:**
24+
/// ```ignore
25+
/// // Bad
26+
/// let mut a: A = Default::default();
27+
/// a.i = 42;
28+
///
29+
/// // Good
30+
/// let a = A {
31+
/// i: 42,
32+
/// .. Default::default()
33+
/// };
34+
/// ```
1035
pub FIELD_REASSIGN_WITH_DEFAULT,
1136
pedantic,
1237
"binding initialized with Default should have its fields set in the initializer"

0 commit comments

Comments
 (0)