From 31c73fb24c2abe72fe24d523964210dbd37dbadc Mon Sep 17 00:00:00 2001 From: Henri Lunnikivi Date: Sun, 23 Aug 2020 19:47:57 +0300 Subject: [PATCH] Resolve minor issues based on review --- .../src/field_reassign_with_default.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/field_reassign_with_default.rs b/clippy_lints/src/field_reassign_with_default.rs index 547276451a36..e75c1bef252b 100644 --- a/clippy_lints/src/field_reassign_with_default.rs +++ b/clippy_lints/src/field_reassign_with_default.rs @@ -11,29 +11,27 @@ 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. + /// **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). /// - /// **Known problems:** The lint does not detect calls to Default::default() - /// if they are made via another struct implementing the Default trait. 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. + /// **Known problems:** None. /// /// **Example:** /// Bad: - /// ```ignore + /// ``` + /// # struct A { i: i32 } /// let mut a: A = Default::default(); /// a.i = 42; /// ``` /// Use instead: - /// ```ignore + /// ``` + /// # struct A { i: i32 } /// let a = A { /// i: 42, /// .. Default::default() /// }; /// ``` pub FIELD_REASSIGN_WITH_DEFAULT, - pedantic, + style, "binding initialized with Default should have its fields set in the initializer" } @@ -56,7 +54,7 @@ impl LateLintPass<'_> for FieldReassignWithDefault { // only when assigning `... = Default::default()` if let Some(ref expr) = local.init; if let ExprKind::Call(ref fn_expr, _) = &expr.kind; - if let ExprKind::Path( qpath ) = &fn_expr.kind; + if let ExprKind::Path(qpath) = &fn_expr.kind; if let Res::Def(_, def_id) = qpath_res(cx, qpath, fn_expr.hir_id); // right hand side of assignment is `Default::default` if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD);