Skip to content

Commit b92fac4

Browse files
author
Henri Lunnikivi
committed
Resolve minor issues based on review
1 parent 66ab580 commit b92fac4

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

clippy_lints/src/field_reassign_with_default.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,27 @@ declare_clippy_lint! {
1111
/// **What it does:** Checks for immediate reassignment of fields initialized
1212
/// with Default::default().
1313
///
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).
1615
///
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.
2117
///
2218
/// **Example:**
2319
/// Bad:
24-
/// ```ignore
20+
/// ```
21+
/// # struct A { i: i32 }
2522
/// let mut a: A = Default::default();
2623
/// a.i = 42;
2724
/// ```
2825
/// Use instead:
29-
/// ```ignore
26+
/// ```
27+
/// # struct A { i: i32 }
3028
/// let a = A {
3129
/// i: 42,
3230
/// .. Default::default()
3331
/// };
3432
/// ```
3533
pub FIELD_REASSIGN_WITH_DEFAULT,
36-
pedantic,
34+
style,
3735
"binding initialized with Default should have its fields set in the initializer"
3836
}
3937

@@ -56,7 +54,7 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
5654
// only when assigning `... = Default::default()`
5755
if let Some(ref expr) = local.init;
5856
if let ExprKind::Call(ref fn_expr, _) = &expr.kind;
59-
if let ExprKind::Path( qpath ) = &fn_expr.kind;
57+
if let ExprKind::Path(qpath) = &fn_expr.kind;
6058
if let Res::Def(_, def_id) = qpath_res(cx, qpath, fn_expr.hir_id);
6159
// right hand side of assignment is `Default::default`
6260
if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD);

0 commit comments

Comments
 (0)