Skip to content

Commit 0729e9f

Browse files
Add UI tests
1 parent 7d840de commit 0729e9f

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![deny(unused_assignments)]
2+
3+
struct Foo {
4+
x: i16
5+
}
6+
7+
const FOO: Foo = Foo { x: 1 };
8+
const BAR: (i16, bool) = (2, false);
9+
10+
fn main() {
11+
Foo { x: 2 }.x = 3;
12+
//~^ ERROR unused assignement to temporary
13+
Foo { x: 2 }.x += 1;
14+
//~^ ERROR unused assignement to temporary
15+
16+
(2, 12).0 += 10;
17+
//~^ ERROR unused assignement to temporary
18+
(10, false).1 = true;
19+
//~^ ERROR unused assignement to temporary
20+
21+
FOO.x = 2;
22+
//~^ ERROR unused assignement to temporary
23+
//~| HELP consider introducing a local variable
24+
FOO.x -= 6;
25+
//~^ ERROR unused assignement to temporary
26+
//~| HELP consider introducing a local variable
27+
28+
BAR.1 = true;
29+
//~^ ERROR unused assignement to temporary
30+
//~| HELP consider introducing a local variable
31+
BAR.0 *= 2;
32+
//~^ ERROR unused assignement to temporary
33+
//~| HELP consider introducing a local variable
34+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
error: unused assignement to temporary
2+
--> $DIR/unused-field-assign.rs:11:20
3+
|
4+
LL | Foo { x: 2 }.x = 3;
5+
| ------------ ^
6+
| |
7+
| this is not bound to any variable
8+
|
9+
note: the lint level is defined here
10+
--> $DIR/unused-field-assign.rs:1:9
11+
|
12+
LL | #![deny(unused_assignments)]
13+
| ^^^^^^^^^^^^^^^^^^
14+
15+
error: unused assignement to temporary
16+
--> $DIR/unused-field-assign.rs:13:20
17+
|
18+
LL | Foo { x: 2 }.x += 1;
19+
| ------------ ^^
20+
| |
21+
| this is not bound to any variable
22+
23+
error: unused assignement to temporary
24+
--> $DIR/unused-field-assign.rs:16:15
25+
|
26+
LL | (2, 12).0 += 10;
27+
| ------- ^^
28+
| |
29+
| this is not bound to any variable
30+
31+
error: unused assignement to temporary
32+
--> $DIR/unused-field-assign.rs:18:19
33+
|
34+
LL | (10, false).1 = true;
35+
| ----------- ^
36+
| |
37+
| this is not bound to any variable
38+
39+
error: unused assignement to temporary
40+
--> $DIR/unused-field-assign.rs:21:11
41+
|
42+
LL | FOO.x = 2;
43+
| --- ^
44+
| |
45+
| this is not bound to any variable
46+
| help: consider introducing a local variable: `let mut foo = FOO;`
47+
|
48+
= note: in Rust, constants are not associated with a specific memory location, and are inlined wherever they are used
49+
50+
error: unused assignement to temporary
51+
--> $DIR/unused-field-assign.rs:24:11
52+
|
53+
LL | FOO.x -= 6;
54+
| --- ^^
55+
| |
56+
| this is not bound to any variable
57+
| help: consider introducing a local variable: `let mut foo = FOO;`
58+
|
59+
= note: in Rust, constants are not associated with a specific memory location, and are inlined wherever they are used
60+
61+
error: unused assignement to temporary
62+
--> $DIR/unused-field-assign.rs:28:11
63+
|
64+
LL | BAR.1 = true;
65+
| --- ^
66+
| |
67+
| this is not bound to any variable
68+
| help: consider introducing a local variable: `let mut bar = BAR;`
69+
|
70+
= note: in Rust, constants are not associated with a specific memory location, and are inlined wherever they are used
71+
72+
error: unused assignement to temporary
73+
--> $DIR/unused-field-assign.rs:31:11
74+
|
75+
LL | BAR.0 *= 2;
76+
| --- ^^
77+
| |
78+
| this is not bound to any variable
79+
| help: consider introducing a local variable: `let mut bar = BAR;`
80+
|
81+
= note: in Rust, constants are not associated with a specific memory location, and are inlined wherever they are used
82+
83+
error: aborting due to 8 previous errors
84+

0 commit comments

Comments
 (0)