Skip to content

Commit 579004f

Browse files
committed
in which the liveness lint tests find a new home
In this commit, liveness-dead and liveness-unused are made into UI tests (cf. #44844) rather than compile-fail tests, because then if some future commit were to, say, change some of the spans in these lints, that commit's diff would clearly show exactly what changed. If. Hypothetically.
1 parent 6bfa7d0 commit 579004f

File tree

4 files changed

+162
-22
lines changed

4 files changed

+162
-22
lines changed

src/test/compile-fail/liveness-dead.rs renamed to src/test/ui/lint/liveness-dead.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,35 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// must-compile-successfully
12+
1113
#![allow(dead_code)]
12-
#![deny(unused_assignments)]
14+
#![warn(unused_assignments)]
1315

1416
fn f1(x: &mut isize) {
1517
*x = 1; // no error
1618
}
1719

1820
fn f2() {
19-
let mut x: isize = 3; //~ ERROR: value assigned to `x` is never read
21+
let mut x: isize = 3; //~ WARN: value assigned to `x` is never read
2022
x = 4;
2123
x.clone();
2224
}
2325

2426
fn f3() {
2527
let mut x: isize = 3;
2628
x.clone();
27-
x = 4; //~ ERROR: value assigned to `x` is never read
29+
x = 4; //~ WARN: value assigned to `x` is never read
2830
}
2931

30-
fn f4(mut x: i32) { //~ ERROR: value passed to `x` is never read
32+
fn f4(mut x: i32) { //~ WARN: value passed to `x` is never read
3133
x = 4;
3234
x.clone();
3335
}
3436

3537
fn f5(mut x: i32) {
3638
x.clone();
37-
x = 4; //~ ERROR: value assigned to `x` is never read
39+
x = 4; //~ WARN: value assigned to `x` is never read
3840
}
3941

4042
fn main() {}

src/test/ui/lint/liveness-dead.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
warning: value assigned to `x` is never read
2+
--> $DIR/liveness-dead.rs:21:9
3+
|
4+
LL | let mut x: isize = 3; //~ WARN: value assigned to `x` is never read
5+
| ^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/liveness-dead.rs:14:9
9+
|
10+
LL | #![warn(unused_assignments)]
11+
| ^^^^^^^^^^^^^^^^^^
12+
13+
warning: value assigned to `x` is never read
14+
--> $DIR/liveness-dead.rs:29:5
15+
|
16+
LL | x = 4; //~ WARN: value assigned to `x` is never read
17+
| ^
18+
19+
warning: value passed to `x` is never read
20+
--> $DIR/liveness-dead.rs:32:7
21+
|
22+
LL | fn f4(mut x: i32) { //~ WARN: value passed to `x` is never read
23+
| ^^^^^
24+
25+
warning: value assigned to `x` is never read
26+
--> $DIR/liveness-dead.rs:39:5
27+
|
28+
LL | x = 4; //~ WARN: value assigned to `x` is never read
29+
| ^
30+

src/test/compile-fail/liveness-unused.rs renamed to src/test/ui/lint/liveness-unused.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,44 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![warn(unused)]
12-
#![deny(unused_variables)]
13-
#![deny(unused_assignments)]
11+
// must-compile-successfully
12+
13+
#![warn(unused_variables, unused_assignments, unreachable_code)]
1414
#![allow(dead_code, non_camel_case_types, trivial_numeric_casts)]
1515

1616
use std::ops::AddAssign;
1717

1818
fn f1(x: isize) {
19-
//~^ ERROR unused variable: `x`
19+
//~^ WARN unused variable: `x`
2020
}
2121

2222
fn f1b(x: &mut isize) {
23-
//~^ ERROR unused variable: `x`
23+
//~^ WARN unused variable: `x`
2424
}
2525

2626
#[allow(unused_variables)]
2727
fn f1c(x: isize) {}
2828

2929
fn f1d() {
3030
let x: isize;
31-
//~^ ERROR unused variable: `x`
31+
//~^ WARN unused variable: `x`
3232
}
3333

3434
fn f2() {
3535
let x = 3;
36-
//~^ ERROR unused variable: `x`
36+
//~^ WARN unused variable: `x`
3737
}
3838

3939
fn f3() {
4040
let mut x = 3;
41-
//~^ ERROR variable `x` is assigned to, but never used
41+
//~^ WARN variable `x` is assigned to, but never used
4242
x += 4;
43-
//~^ ERROR value assigned to `x` is never read
43+
//~^ WARN value assigned to `x` is never read
4444
}
4545

4646
fn f3b() {
4747
let mut z = 3;
48-
//~^ ERROR variable `z` is assigned to, but never used
48+
//~^ WARN variable `z` is assigned to, but never used
4949
loop {
5050
z += 4;
5151
}
@@ -67,7 +67,7 @@ fn f3d() {
6767
fn f4() {
6868
match Some(3) {
6969
Some(i) => {
70-
//~^ ERROR unused variable: `i`
70+
//~^ WARN unused variable: `i`
7171
}
7272
None => {}
7373
}
@@ -87,19 +87,19 @@ fn f4b() -> isize {
8787

8888
fn f5a() {
8989
for x in 1..10 { }
90-
//~^ ERROR unused variable: `x`
90+
//~^ WARN unused variable: `x`
9191
}
9292

9393
fn f5b() {
9494
for (x, _) in [1, 2, 3].iter().enumerate() { }
95-
//~^ ERROR unused variable: `x`
95+
//~^ WARN unused variable: `x`
9696
}
9797

9898
fn f5c() {
9999
for (_, x) in [1, 2, 3].iter().enumerate() {
100-
//~^ ERROR unused variable: `x`
100+
//~^ WARN unused variable: `x`
101101
continue;
102-
drop(*x as i32); //~ WARNING unreachable statement
102+
drop(*x as i32); //~ WARN unreachable statement
103103
}
104104
}
105105

@@ -120,10 +120,10 @@ fn f6() {
120120
// ensure an error shows up for x even if lhs of an overloaded add assign
121121

122122
let x;
123-
//~^ ERROR variable `x` is assigned to, but never used
123+
//~^ WARN variable `x` is assigned to, but never used
124124

125125
*({
126-
x = 0; //~ ERROR value assigned to `x` is never read
126+
x = 0; //~ WARN value assigned to `x` is never read
127127
&mut v
128128
}) += 1;
129129
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
warning: unreachable statement
2+
--> $DIR/liveness-unused.rs:102:9
3+
|
4+
LL | drop(*x as i32); //~ WARN unreachable statement
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/liveness-unused.rs:13:47
9+
|
10+
LL | #![warn(unused_variables, unused_assignments, unreachable_code)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
warning: unused variable: `x`
14+
--> $DIR/liveness-unused.rs:18:7
15+
|
16+
LL | fn f1(x: isize) {
17+
| ^ help: consider using `_x` instead
18+
|
19+
note: lint level defined here
20+
--> $DIR/liveness-unused.rs:13:9
21+
|
22+
LL | #![warn(unused_variables, unused_assignments, unreachable_code)]
23+
| ^^^^^^^^^^^^^^^^
24+
25+
warning: unused variable: `x`
26+
--> $DIR/liveness-unused.rs:22:8
27+
|
28+
LL | fn f1b(x: &mut isize) {
29+
| ^ help: consider using `_x` instead
30+
31+
warning: unused variable: `x`
32+
--> $DIR/liveness-unused.rs:30:9
33+
|
34+
LL | let x: isize;
35+
| ^ help: consider using `_x` instead
36+
37+
warning: unused variable: `x`
38+
--> $DIR/liveness-unused.rs:35:9
39+
|
40+
LL | let x = 3;
41+
| ^ help: consider using `_x` instead
42+
43+
warning: variable `x` is assigned to, but never used
44+
--> $DIR/liveness-unused.rs:40:9
45+
|
46+
LL | let mut x = 3;
47+
| ^^^^^
48+
|
49+
= note: consider using `_x` instead
50+
51+
warning: value assigned to `x` is never read
52+
--> $DIR/liveness-unused.rs:42:5
53+
|
54+
LL | x += 4;
55+
| ^
56+
|
57+
note: lint level defined here
58+
--> $DIR/liveness-unused.rs:13:27
59+
|
60+
LL | #![warn(unused_variables, unused_assignments, unreachable_code)]
61+
| ^^^^^^^^^^^^^^^^^^
62+
63+
warning: variable `z` is assigned to, but never used
64+
--> $DIR/liveness-unused.rs:47:9
65+
|
66+
LL | let mut z = 3;
67+
| ^^^^^
68+
|
69+
= note: consider using `_z` instead
70+
71+
warning: unused variable: `i`
72+
--> $DIR/liveness-unused.rs:69:12
73+
|
74+
LL | Some(i) => {
75+
| ^ help: consider using `_i` instead
76+
77+
warning: unused variable: `x`
78+
--> $DIR/liveness-unused.rs:89:9
79+
|
80+
LL | for x in 1..10 { }
81+
| ^ help: consider using `_x` instead
82+
83+
warning: unused variable: `x`
84+
--> $DIR/liveness-unused.rs:94:10
85+
|
86+
LL | for (x, _) in [1, 2, 3].iter().enumerate() { }
87+
| ^ help: consider using `_x` instead
88+
89+
warning: unused variable: `x`
90+
--> $DIR/liveness-unused.rs:99:13
91+
|
92+
LL | for (_, x) in [1, 2, 3].iter().enumerate() {
93+
| ^ help: consider using `_x` instead
94+
95+
warning: variable `x` is assigned to, but never used
96+
--> $DIR/liveness-unused.rs:122:9
97+
|
98+
LL | let x;
99+
| ^
100+
|
101+
= note: consider using `_x` instead
102+
103+
warning: value assigned to `x` is never read
104+
--> $DIR/liveness-unused.rs:126:9
105+
|
106+
LL | x = 0; //~ WARN value assigned to `x` is never read
107+
| ^
108+

0 commit comments

Comments
 (0)