Skip to content

Commit ee289cc

Browse files
author
Henri Lunnikivi
committed
Add UI test for field_reassign_with_default
1 parent 4192dbe commit ee289cc

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![warn(clippy::field_reassign_with_default)]
2+
3+
#[derive(Default)]
4+
struct A {
5+
i: i32,
6+
j: i64,
7+
}
8+
9+
struct B {
10+
i: i32,
11+
j: i64,
12+
}
13+
14+
#[derive(Default)]
15+
struct C {
16+
i: i32,
17+
}
18+
19+
fn main() {
20+
// wrong
21+
let mut a: A = Default::default();
22+
a.i = 42;
23+
24+
// right
25+
let mut a: A = Default::default();
26+
27+
// right
28+
let a = A {
29+
i: 42,
30+
..Default::default()
31+
};
32+
33+
// right
34+
let b = B { i: 42, j: 24 };
35+
36+
// right
37+
let c: C = Default::default();
38+
}

0 commit comments

Comments
 (0)