Skip to content

Commit a5ce3c1

Browse files
committed
Rust: Move trait tests for unused entities into main.rs
1 parent 45e9c2f commit a5ce3c1

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

rust/ql/test/query-tests/unusedentities/UnusedValue.expected

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
| main.rs:370:9:370:9 | x | Variable is assigned a value that is never used. |
2020
| main.rs:378:17:378:17 | x | Variable is assigned a value that is never used. |
2121
| main.rs:432:9:432:10 | i6 | Variable is assigned a value that is never used. |
22-
| more.rs:8:9:8:13 | times | Variable is assigned a value that is never used. |
23-
| more.rs:9:9:9:14 | unused | Variable is assigned a value that is never used. |
24-
| more.rs:21:9:21:14 | unused | Variable is assigned a value that is never used. |
25-
| more.rs:38:23:38:25 | val | Variable is assigned a value that is never used. |
26-
| more.rs:42:19:42:21 | val | Variable is assigned a value that is never used. |
27-
| more.rs:58:9:58:11 | val | Variable is assigned a value that is never used. |
28-
| more.rs:80:9:80:14 | a_ptr4 | Variable is assigned a value that is never used. |
29-
| more.rs:95:9:95:13 | d_ptr | Variable is assigned a value that is never used. |
30-
| more.rs:101:9:101:17 | f_ptr | Variable is assigned a value that is never used. |
22+
| more.rs:4:23:4:25 | val | Variable is assigned a value that is never used. |
23+
| more.rs:8:19:8:21 | val | Variable is assigned a value that is never used. |
24+
| more.rs:24:9:24:11 | val | Variable is assigned a value that is never used. |
25+
| more.rs:46:9:46:14 | a_ptr4 | Variable is assigned a value that is never used. |
26+
| more.rs:61:9:61:13 | d_ptr | Variable is assigned a value that is never used. |
27+
| more.rs:67:9:67:17 | f_ptr | Variable is assigned a value that is never used. |
3128
| unreachable.rs:166:6:166:6 | x | Variable is assigned a value that is never used. |
3229
| unreachable.rs:190:14:190:14 | a | Variable is assigned a value that is never used. |
3330
| unreachable.rs:199:9:199:9 | a | Variable is assigned a value that is never used. |

rust/ql/test/query-tests/unusedentities/UnusedVariable.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
| main.rs:379:21:379:21 | y | Variable is not used. |
1919
| main.rs:427:27:427:29 | val | Variable is not used. |
2020
| main.rs:430:22:430:24 | acc | Variable is not used. |
21+
| main.rs:442:9:442:13 | times | Variable is not used. |
22+
| main.rs:443:9:443:14 | unused | Variable is not used. |
23+
| main.rs:455:9:455:14 | unused | Variable is not used. |

rust/ql/test/query-tests/unusedentities/main.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,38 @@ fn folds_and_closures() {
434434
_ = a6.fold(0, | acc, val | acc + val + i6);
435435
}
436436

437+
// --- traits ---
438+
439+
trait Incrementable {
440+
fn increment(
441+
&mut self,
442+
times: i32, // SPURIOUS: unused variable
443+
unused: i32 // SPURIOUS: unused variable
444+
);
445+
}
446+
447+
struct MyValue {
448+
value: i32,
449+
}
450+
451+
impl Incrementable for MyValue {
452+
fn increment(
453+
&mut self,
454+
times: i32,
455+
unused: i32 // BAD: unused variable
456+
) {
457+
self.value += times;
458+
}
459+
}
460+
461+
fn traits() {
462+
let mut i = MyValue { value: 0 };
463+
let a = 1;
464+
let b = 2;
465+
466+
i.increment(a, b);
467+
}
468+
437469
// --- main ---
438470

439471
fn main() {

rust/ql/test/query-tests/unusedentities/more.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
1-
2-
3-
// --- traits ---
4-
5-
trait Incrementable {
6-
fn increment(
7-
&mut self,
8-
times: i32, // SPURIOUS: unused value
9-
unused: i32 // SPURIOUS: unused value
10-
);
11-
}
12-
13-
struct MyValue {
14-
value: i32,
15-
}
16-
17-
impl Incrementable for MyValue {
18-
fn increment(
19-
&mut self,
20-
times: i32,
21-
unused: i32 // BAD: unused variable [NOT DETECTED] SPURIOUS: unused value
22-
) {
23-
self.value += times;
24-
}
25-
}
26-
27-
fn traits() {
28-
let mut i = MyValue { value: 0 };
29-
let a = 1;
30-
let b = 2;
31-
32-
i.increment(a, b);
33-
}
34-
351
// --- generics ---
362

373
trait MySettable<T> {

0 commit comments

Comments
 (0)