Skip to content

Commit 679f755

Browse files
Henri Lunnikivihegza
Henri Lunnikivi
authored andcommitted
Add note about removing assignments in suggestion
1 parent ef11e11 commit 679f755

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

clippy_lints/src/field_reassign_with_default.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
140140
first_assign.unwrap().span,
141141
"field assignment outside of initializer for an instance created with Default::default()",
142142
Some(preceding_local.span),
143-
&format!("consider initializing the variable with `{}`", sugg),
143+
&format!(
144+
"consider initializing the variable with `{}` and removing relevant reassignments",
145+
sugg
146+
),
144147
);
145148
}
146149
}

tests/ui/field_reassign_with_default.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | a.i = 42;
55
| ^^^^^^^^^
66
|
77
= note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
8-
note: consider initializing the variable with `A { i: 42, ..Default::default() }`
8+
note: consider initializing the variable with `A { i: 42, ..Default::default() }` and removing relevant reassignments
99
--> $DIR/field_reassign_with_default.rs:16:5
1010
|
1111
LL | let mut a: A = Default::default();
@@ -17,7 +17,7 @@ error: field assignment outside of initializer for an instance created with Defa
1717
LL | a.j = 43;
1818
| ^^^^^^^^^
1919
|
20-
note: consider initializing the variable with `A { j: 43, i: 42 }`
20+
note: consider initializing the variable with `A { j: 43, i: 42 }` and removing relevant reassignments
2121
--> $DIR/field_reassign_with_default.rs:56:5
2222
|
2323
LL | let mut a: A = Default::default();
@@ -29,7 +29,7 @@ error: field assignment outside of initializer for an instance created with Defa
2929
LL | a.i = 42;
3030
| ^^^^^^^^^
3131
|
32-
note: consider initializing the variable with `A { i: 42, j: 44 }`
32+
note: consider initializing the variable with `A { i: 42, j: 44 }` and removing relevant reassignments
3333
--> $DIR/field_reassign_with_default.rs:61:5
3434
|
3535
LL | let mut a: A = Default::default();
@@ -41,7 +41,7 @@ error: field assignment outside of initializer for an instance created with Defa
4141
LL | a.i = 42;
4242
| ^^^^^^^^^
4343
|
44-
note: consider initializing the variable with `A { i: 42, ..Default::default() }`
44+
note: consider initializing the variable with `A { i: 42, ..Default::default() }` and removing relevant reassignments
4545
--> $DIR/field_reassign_with_default.rs:67:5
4646
|
4747
LL | let mut a = A::default();
@@ -53,7 +53,7 @@ error: field assignment outside of initializer for an instance created with Defa
5353
LL | a.i = Default::default();
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5555
|
56-
note: consider initializing the variable with `A::default()`
56+
note: consider initializing the variable with `A::default()` and removing relevant reassignments
5757
--> $DIR/field_reassign_with_default.rs:77:5
5858
|
5959
LL | let mut a: A = Default::default();
@@ -65,7 +65,7 @@ error: field assignment outside of initializer for an instance created with Defa
6565
LL | a.i = Default::default();
6666
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6767
|
68-
note: consider initializing the variable with `A { j: 45, ..Default::default() }`
68+
note: consider initializing the variable with `A { j: 45, ..Default::default() }` and removing relevant reassignments
6969
--> $DIR/field_reassign_with_default.rs:81:5
7070
|
7171
LL | let mut a: A = Default::default();

0 commit comments

Comments
 (0)