Skip to content

Commit

Permalink
Add note about removing assignments in suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Lunnikivi authored and hegza committed Oct 18, 2020
1 parent 4651030 commit 5bfb948
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion clippy_lints/src/field_reassign_with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
first_assign.unwrap().span,
"field assignment outside of initializer for an instance created with Default::default()",
Some(preceding_local.span),
&format!("consider initializing the variable with `{}`", sugg),
&format!(
"consider initializing the variable with `{}` and removing relevant reassignments",
sugg
),
);
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/field_reassign_with_default.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | a.i = 42;
| ^^^^^^^^^
|
= note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
note: consider initializing the variable with `A { i: 42, ..Default::default() }`
note: consider initializing the variable with `A { i: 42, ..Default::default() }` and removing relevant reassignments
--> $DIR/field_reassign_with_default.rs:16:5
|
LL | let mut a: A = Default::default();
Expand All @@ -17,7 +17,7 @@ error: field assignment outside of initializer for an instance created with Defa
LL | a.j = 43;
| ^^^^^^^^^
|
note: consider initializing the variable with `A { j: 43, i: 42 }`
note: consider initializing the variable with `A { j: 43, i: 42 }` and removing relevant reassignments
--> $DIR/field_reassign_with_default.rs:56:5
|
LL | let mut a: A = Default::default();
Expand All @@ -29,7 +29,7 @@ error: field assignment outside of initializer for an instance created with Defa
LL | a.i = 42;
| ^^^^^^^^^
|
note: consider initializing the variable with `A { i: 42, j: 44 }`
note: consider initializing the variable with `A { i: 42, j: 44 }` and removing relevant reassignments
--> $DIR/field_reassign_with_default.rs:61:5
|
LL | let mut a: A = Default::default();
Expand All @@ -41,7 +41,7 @@ error: field assignment outside of initializer for an instance created with Defa
LL | a.i = 42;
| ^^^^^^^^^
|
note: consider initializing the variable with `A { i: 42, ..Default::default() }`
note: consider initializing the variable with `A { i: 42, ..Default::default() }` and removing relevant reassignments
--> $DIR/field_reassign_with_default.rs:67:5
|
LL | let mut a = A::default();
Expand All @@ -53,7 +53,7 @@ error: field assignment outside of initializer for an instance created with Defa
LL | a.i = Default::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: consider initializing the variable with `A::default()`
note: consider initializing the variable with `A::default()` and removing relevant reassignments
--> $DIR/field_reassign_with_default.rs:77:5
|
LL | let mut a: A = Default::default();
Expand All @@ -65,7 +65,7 @@ error: field assignment outside of initializer for an instance created with Defa
LL | a.i = Default::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: consider initializing the variable with `A { j: 45, ..Default::default() }`
note: consider initializing the variable with `A { j: 45, ..Default::default() }` and removing relevant reassignments
--> $DIR/field_reassign_with_default.rs:81:5
|
LL | let mut a: A = Default::default();
Expand Down

0 comments on commit 5bfb948

Please sign in to comment.