Skip to content

Commit

Permalink
Add doc for field_reassign_with_default
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Lunnikivi committed Nov 1, 2019
1 parent 3de7e14 commit 94ce83e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions clippy_lints/src/field_reassign_with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ use syntax::print::pprust::{expr_to_string, ty_to_string};
use syntax::symbol::Symbol;

declare_clippy_lint! {
/// **What it does:** Checks for immediate reassignment of fields initialized
/// with Default::default().
///
/// **Why is this bad?** Fields should be set using
/// T { field: value, ..Default::default() } syntax instead of using a mutable binding.
///
/// **Known problems:** The lint does not detect calls to Default::default()
/// if they are made via another struct implementing the Default trait. This
/// may be corrected with a LateLintPass. If type inference stops requiring
/// an explicit type for assignment using Default::default() this lint will
/// not trigger for cases where the type is elided. This may also be corrected
/// with a LateLintPass.
///
/// **Example:**
/// ```ignore
/// // Bad
/// let mut a: A = Default::default();
/// a.i = 42;
///
/// // Good
/// let a = A {
/// i: 42,
/// .. Default::default()
/// };
/// ```
pub FIELD_REASSIGN_WITH_DEFAULT,
pedantic,
"binding initialized with Default should have its fields set in the initializer"
Expand Down

0 comments on commit 94ce83e

Please sign in to comment.