8000 Rust: Add another unused-value test · github/codeql@d0f9a0b · GitHub
[go: up one dir, main page]

Skip to content

Commit d0f9a0b

Browse files
committed
Rust: Add another unused-value test
1 parent 55a6ed7 commit d0f9a0b

File tree

6 files changed

+96
-70
lines changed

6 files changed

+96
-70
lines changed
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
| unreachable.rs:11:9:11:23 | ExprStmt | This code is never reached. |
21
| unreachable.rs:19:9:19:23 | ExprStmt | This code is never reached. |
3-
| unreachable.rs:31:9:31:23 | ExprStmt | This code is never reached. |
4-
| unreachable.rs:38:9:38:23 | ExprStmt | This code is never reached. |
5-
| unreachable.rs:59:5:59:19 | ExprStmt | This code is never reached. |
6-
| unreachable.rs:106:13:106:20 | MacroExpr | This code is never reached. |
7-
| unreachable.rs:115:13:115:20 | MacroExpr | This code is never reached. |
8-
| unreachable.rs:141:5:141:19 | ExprStmt | This code is never reached. |
9-
| unreachable.rs:148:9:148:23 | ExprStmt | This code is never reached. |
10-
| unreachable.rs:157:13:157:27 | ExprStmt | This code is never reached. |
11-
| unreachable.rs:163:9:163:23 | ExprStmt | This code is never reached. |
12-
| unreachable.rs:169:13:169:27 | ExprStmt | This code is never reached. |
2+
| unreachable.rs:27:9:27:23 | ExprStmt | This code is never reached. |
3+
| unreachable.rs:39:9:39:23 | ExprStmt | This code is never reached. |
4+
| unreachable.rs:46:9:46:23 | ExprStmt | This code is never reached. |
5+
| unreachable.rs:67:5:67:19 | ExprStmt | This code is never reached. |
6+
| unreachable.rs:114:13:114:20 | MacroExpr | This code is never reached. |
7+
| unreachable.rs:123:13:123:20 | MacroExpr | This code is never reached. |
8+
| unreachable.rs:149:5:149:19 | ExprStmt | This code is never reached. |
9+
| unreachable.rs:156:9:156:23 | ExprStmt | This code is never reached. |
10+
| unreachable.rs:165:13:165:27 | ExprStmt | This code is never reached. |
11+
| unreachable.rs:171:9:171:23 | ExprStmt | This code is never reached. |
1312
| unreachable.rs:177:13:177:27 | ExprStmt | This code is never reached. |
14-
| unreachable.rs:180:5:180:19 | ExprStmt | This code is never reached. |
15-
| unreachable.rs:204:9:204:23 | ExprStmt | This code is never reached. |
16-
| unreachable.rs:220:9:220:23 | ExprStmt | This code is never reached. |
13+
| unreachable.rs:185:13:185:27 | ExprStmt | This code is never reached. |
14+
| unreachable.rs:188:5:188:19 | ExprStmt | This code is never reached. |
15+
| unreachable.rs:212:9:212:23 | ExprStmt | This code is never reached. |
16+
| unreachable.rs:228:9:228:23 | ExprStmt | This code is never reached. |

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
| main.rs:6:9:6:9 | a | Variable $@ is assigned a value that is never used. | main.rs:6:9:6:9 | a | a |
2-
| main.rs:9:9:9:9 | d | Variable $@ is assigned a value that is never used. | main.rs:9:9:9:9 | d | d |
3-
| main.rs:35:5:35:5 | b | Variable $@ is assigned a value that is never used. | main.rs:26:9:26:9 | b | b |
4-
| main.rs:37:5:37:5 | c | Variable $@ is assigned a value that is never used. | main.rs:27:13:27:13 | c | c |
5-
| main.rs:40:5:40:5 | c | Variable $@ is assigned a value that is never used. | main.rs:27:13:27:13 | c | c |
6-
| main.rs:44:9:44:9 | d | Variable $@ is assigned a value that is never used. | main.rs:28:13:28:13 | d | d |
7-
| main.rs:50:5:50:5 | e | Variable $@ is assigned a value that is never used. | main.rs:29:13:29:13 | e | e |
8-
| main.rs:61:5:61:5 | f | Variable $@ is assigned a value that is never used. | main.rs:30:13:30:13 | f | f |
9-
| main.rs:63:5:63:5 | f | Variable $@ is assigned a value that is never used. | main.rs:30:13:30:13 | f | f |
10-
| main.rs:65:5:65:5 | g | Variable $@ is assigned a value that is never used. | main.rs:31:9:31:9 | g | g |
11-
| main.rs:87:9:87:9 | a | Variable $@ is assigned a value that is never used. | main.rs:87:9:87:9 | a | a |
12-
| main.rs:108:9:108:10 | is | Variable $@ is assigned a value that is never used. | main.rs:108:9:108:10 | is | is |
13-
| main.rs:131:13:131:17 | total | Variable $@ is assigned a value that is never used. | main.rs:131:13:131:17 | total | total |
14-
| main.rs:266:13:266:17 | total | Variable $@ is assigned a value that is never used. | main.rs:234:13:234:17 | total | total |
15-
| main.rs:359:9:359:9 | x | Variable $@ is assigned a value that is never used. | main.rs:359:9:359:9 | x | x |
16-
| main.rs:367:17:367:17 | x | Variable $@ is assigned a value that is never used. | main.rs:367:17:367:17 | x | x |
1+
| main.rs:8:9:8:9 | a | Variable $@ is assigned a value that is never used. | main.rs:8:9:8:9 | a | a |
2+
| main.rs:11:9:11:9 | d | Variable $@ is assigned a value that is never used. | main.rs:11:9:11:9 | d | d |
3+
| main.rs:37:5:37:5 | b | Variable $@ is assigned a value that is never used. | main.rs:28:9:28:9 | b | b |
4+
| main.rs:39:5:39:5 | c | Variable $@ is assigned a value that is never used. | main.rs:29:13:29:13 | c | c |
5+
| main.rs:42:5:42:5 | c | Variable $@ is assigned a value that is never used. | main.rs:29:13:29:13 | c | c |
6+
| main.rs:46:9:46:9 | d | Variable $@ is assigned a value that is never used. | main.rs:30:13:30:13 | d | d |
7+
| main.rs:52:5:52:5 | e | Variable $@ is assigned a value that is never used. | main.rs:31:13:31:13 | e | e |
8+
| main.rs:63:5:63:5 | f | Variable $@ is assigned a value that is never used. | main.rs:32:13:32:13 | f | f |
9+
| main.rs:65:5:65:5 | f | Variable $@ is assigned a value that is never used. | main.rs:32:13:32:13 | f | f |
10+
| main.rs:67:5:67:5 | g | Variable $@ is assigned a value that is never used. | main.rs:33:9:33:9 | g | g |
11+
| main.rs:89:9:89:9 | a | Variable $@ is assigned a value that is never used. | main.rs:89:9:89:9 | a | a |
12+
| main.rs:110:9:110:10 | is | Variable $@ is assigned a value that is never used. | main.rs:110:9:110:10 | is | is |
13+
| main.rs:133:13:133:17 | total | Variable $@ is assigned a value that is never used. | main.rs:133:13:133:17 | total | total |
14+
| main.rs:270:13:270:17 | total | Variable $@ is assigned a value that is never used. | main.rs:238:13:238:17 | total | total |
15+
| main.rs:363:9:363:9 | x | Variable $@ is assigned a value that is never used. | main.rs:363:9:363:9 | x | x |
16+
| main.rs:371:17:371:17 | x | Variable $@ is assigned a value that is never used. | main.rs:371:17:371:17 | x | x |
1717
| more.rs:24:9:24:11 | val | Variable $@ is assigned a value that is never used. | more.rs:24:9:24:11 | val | val |
1818
| more.rs:44:9:44:14 | a_ptr4 | Variable $@ is assigned a value that is never used. | more.rs:44:9:44:14 | a_ptr4 | a_ptr4 |
1919
| more.rs:59:9:59:13 | d_ptr | Variable $@ is assigned a value that is never used. | more.rs:59:9:59:13 | d_ptr | d_ptr |
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
| main.rs:25:9:25:9 | a | Variable 'a' is not used. |
2-
| main.rs:90:13:90:13 | d | Variable 'd' is not used. |
3-
| main.rs:139:5:139:5 | y | Variable 'y' is not used. |
4-
| main.rs:166:9:166:9 | x | Variable 'x' is not used. |
5-
| main.rs:236:17:236:17 | a | Variable 'a' is not used. |
6-
| main.rs:244:20:244:22 | val | Variable 'val' is not used. |
7-
| main.rs:258:14:258:16 | val | Variable 'val' is not used. |
8-
| main.rs:273:22:273:24 | val | Variable 'val' is not used. |
9-
| main.rs:280:24:280:26 | val | Variable 'val' is not used. |
10-
| main.rs:288:13:288:15 | num | Variable 'num' is not used. |
11-
| main.rs:303:12:303:12 | j | Variable 'j' is not used. |
12-
| main.rs:323:25:323:25 | y | Variable 'y' is not used. |
13-
| main.rs:326:28:326:28 | a | Variable 'a' is not used. |
14-
| main.rs:329:9:329:9 | p | Variable 'p' is not used. |
15-
| main.rs:347:9:347:13 | right | Variable 'right' is not used. |
16-
| main.rs:353:9:353:14 | right2 | Variable 'right2' is not used. |
17-
| main.rs:360:13:360:13 | y | Variable 'y' is not used. |
18-
| main.rs:368:21:368:21 | y | Variable 'y' is not used. |
19-
| main.rs:413:26:413:28 | val | Variable 'val' is not used. |
20-
| main.rs:416:21:416:23 | acc | Variable 'acc' is not used. |
21-
| main.rs:437:9:437:14 | unused | Variable 'unused' is not used. |
1+
| main.rs:27:9:27:9 | a | Variable 'a' is not used. |
2+
| main.rs:92:13:92:13 | d | Variable 'd' is not used. |
3+
| main.rs:141:5:141:5 | y | Variable 'y' is not used. |
4+
| main.rs:168:9:168:9 | x | Variable 'x' is not used. |
5+
| main.rs:240:17:240:17 | a | Variable 'a' is not used. |
6+
| main.rs:248:20:248:22 | val | Variable 'val' is not used. |
7+
| main.rs:262:14:262:16 | val | Variable 'val' is not used F438 . |
8+
| main.rs:277:22:277:24 | val | Variable 'val' is not used. |
9+
| main.rs:284:24:284:26 | val | Variable 'val' is not used. |
10+
| main.rs:292:13:292:15 | num | Variable 'num' is not used. |
11+
| main.rs:307:12:307:12 | j | Variable 'j' is not used. |
12+
| main.rs:327:25:327:25 | y | Variable 'y' is not used. |
13+
| main.rs:330:28:330:28 | a | Variable 'a' is not used. |
14+
| main.rs:333:9:333:9 | p | Variable 'p' is not used. |
15+
| main.rs:351:9:351:13 | right | Variable 'right' is not used. |
16+
| main.rs:357:9:357:14 | right2 | Variable 'right2' is not used. |
17+
| main.rs:364:13:364:13 | y | Variable 'y' is not used. |
18+
| main.rs:372:21:372:21 | y | Variable 'y' is not used. |
19+
| main.rs:417:26:417:28 | val | Variable 'val' is not used. |
20+
| main.rs:420:21:420:23 | acc | Variable 'acc' is not used. |
21+
| main.rs:441:9:441:14 | unused | Variable 'unused' is not used. |

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//fn cond() -> bool;
1+
mod unreachable;
2+
3+
use unreachable::*;
24

35
// --- locals ---
46

@@ -204,10 +206,12 @@ fn loops() {
204206

205207
for x in 1..10 {
206208
assert_eq!(x, 1);
209+
break;
207210
}
208211

209212
for x in 1..10 {
210213
assert_eq!(id(x), id(1));
214+
break;
211215
}
212216
}
213217

@@ -434,7 +438,7 @@ impl Incrementable for MyValue {
434438
fn increment(
435439
&mut self,
436440
times: i32,
437-
unused: i32, // $ Alert[rust/unused-variable]
441+
unused: &mut i32, // $ Alert[rust/unused-variable]
438442
) {
439443
self.value += times;
440444
}
@@ -443,9 +447,22 @@ impl Incrementable for MyValue {
443447
fn traits() {
444448
let mut i = MyValue { value: 0 };
445449
let a = 1;
446-
let b = 2;
450+
let mut b = 2;
451+
452+
i.increment(a, &mut b);
453+
}
447454

448-
i.increment(a, b);
455+
// --- macros ---
456+
457+
fn macros() {
458+
let x;
459+
println!(
460+
"The value of x is {}",
461+
({
462+
x = 10; // $ MISSING: Alert[rust/unused-value]
463+
10
464+
})
465+
)
449466
}
450467

451468
// --- main ---
@@ -464,12 +481,14 @@ fn main() {
464481
folds_and_closures();
465482

466483
unreachable_if_1();
467-
unreachable_panic();
484+
// unreachable_panic();
468485
unreachable_match();
469-
unreachable_loop();
486+
// unreachable_loop();
470487
unreachable_paren();
471488
unreachable_let_1();
472489
unreachable_let_2();
473490
unreachable_if_2();
474491
unreachable_if_3();
492+
493+
macros();
475494
}

rust/ql/test/query-tests/unusedentities/options

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
//fn cond() -> bool;
2-
//fn get_a_number() -> i32;
3-
//fn maybe_get_a_number() -> Option<i32>;
1+
pub fn cond() -> bool {
2+
true
3+
}
4+
5+
fn get_a_number() -> i32 {
6+
42
7+
}
8+
9+
fn maybe_get_a_number() -> Option<i32> {
10+
None
11+
}
412

513
// --- unreachable code --
614

715
fn do_something() {}
816

9-
fn unreachable_if_1() {
17+
pub fn unreachable_if_1() {
1018
if false {
1119
do_something(); // $ Alert[rust/dead-code]
1220
} else {
@@ -59,7 +67,7 @@ fn unreachable_if_1() {
5967
do_something(); // $ Alert[rust/dead-code]
6068
}
6169

62-
fn unreachable_panic() {
70+
pub fn unreachable_panic() {
6371
if cond() {
6472
do_something();
6573
panic!("Oh no!!!");
@@ -119,7 +127,7 @@ fn unreachable_panic() {
119127
}
120128
}
121129

122-
fn unreachable_match() {
130+
pub fn unreachable_match() {
123131
match get_a_number() {
124132
1 => {
125133
return;
@@ -141,7 +149,7 @@ fn unreachable_match() {
141149
do_something(); // $ Alert[rust/dead-code]
142150
}
143151

144-
fn unreachable_loop() {
152+
pub fn unreachable_loop() {
145153
loop {
146154
do_something();
147155
break;
@@ -182,11 +190,11 @@ fn unreachable_loop() {
182190
do_something();
183191
}
184192

185-
fn unreachable_paren() {
193+
pub fn unreachable_paren() {
186194
let _ = (((1)));
187195
}
188196

189-
fn unreachable_let_1() {
197+
pub fn unreachable_let_1() {
190198
if let Some(_) = maybe_get_a_number() {
191199
do_something();
192200
return;
@@ -207,7 +215,7 @@ fn unreachable_let_1() {
207215
do_something();
208216
}
209217

210-
fn unreachable_let_2() {
218+
pub fn unreachable_let_2() {
211219
let Some(_) = maybe_get_a_number() else {
212220
do_something();
213221
return;
@@ -224,7 +232,7 @@ fn unreachable_let_2() {
224232
do_something();
225233
}
226234

227-
fn unreachable_if_2() {
235+
pub fn unreachable_if_2() {
228236
if cond() {
229237
do_something();
230238
return;
@@ -235,7 +243,7 @@ fn unreachable_if_2() {
235243
do_something();
236244
}
237245

238-
fn unreachable_if_3() {
246+
pub fn unreachable_if_3() {
239247
if !cond() {
240248
do_something();
241249
return;

0 commit comments

Comments
 (0)
0