Skip to content

Commit 5d7a92c

Browse files
committed
Rust: Add example from discussion.
1 parent 40096eb commit 5d7a92c

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
| unreachable.rs:20:3:20:17 | ExprStmt | This code is never reached. |
1111
| unreachable.rs:32:3:32:17 | ExprStmt | This code is never reached. |
1212
| unreachable.rs:39:3:39:17 | ExprStmt | This code is never reached. |
13-
| unreachable.rs:48:2:48:16 | ExprStmt | This code is never reached. |
14-
| unreachable.rs:89:3:89:17 | ExprStmt | This code is never reached. |
15-
| unreachable.rs:97:3:97:17 | ExprStmt | This code is never reached. |
16-
| unreachable.rs:105:3:107:3 | MatchArm | This code is never reached. |
17-
| unreachable.rs:108:3:110:3 | MatchArm | This code is never reached. |
18-
| unreachable.rs:112:2:112:16 | ExprStmt | This code is never reached. |
19-
| unreachable.rs:115:3:117:3 | MatchArm | This code is never reached. |
20-
| unreachable.rs:118:3:120:3 | MatchArm | This code is never reached. |
21-
| unreachable.rs:122:2:122:16 | ExprStmt | This code is never reached. |
22-
| unreachable.rs:129:3:129:17 | ExprStmt | This code is never reached. |
23-
| unreachable.rs:138:4:138:18 | ExprStmt | This code is never reached. |
24-
| unreachable.rs:144:3:144:17 | ExprStmt | This code is never reached. |
13+
| unreachable.rs:46:6:46:8 | ParenExpr | This code is never reached. |
14+
| unreachable.rs:48:7:48:10 | ParenExpr | This code is never reached. |
15+
| unreachable.rs:60:2:60:16 | ExprStmt | This code is never reached. |
16+
| unreachable.rs:101:3:101:17 | ExprStmt | This code is never reached. |
17+
| unreachable.rs:109:3:109:17 | ExprStmt | This code is never reached. |
18+
| unreachable.rs:117:3:119:3 | MatchArm | This code is never reached. |
19+
| unreachable.rs:120:3:122:3 | MatchArm | This code is never reached. |
20+
| unreachable.rs:124:2:124:16 | ExprStmt | This code is never reached. |
21+
| unreachable.rs:127:3:129:3 | MatchArm | This code is never reached. |
22+
| unreachable.rs:130:3:132:3 | MatchArm | This code is never reached. |
23+
| unreachable.rs:134:2:134:16 | ExprStmt | This code is never reached. |
24+
| unreachable.rs:141:3:141:17 | ExprStmt | This code is never reached. |
2525
| unreachable.rs:150:4:150:18 | ExprStmt | This code is never reached. |
26-
| unreachable.rs:153:2:153:16 | ExprStmt | This code is never reached. |
26+
| unreachable.rs:156:3:156:17 | ExprStmt | This code is never reached. |
27+
| unreachable.rs:162:4:162:18 | ExprStmt | This code is never reached. |
28+
| unreachable.rs:165:2:165:16 | ExprStmt | This code is never reached. |

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ fn unreachable_if() {
4040
}
4141
do_something();
4242

43+
if cond() {
44+
bool x = cond();
45+
46+
if (x) { // SPURIOUS: unreachable
47+
do_something();
48+
if (!x) { // SPURIOUS: unreachable
49+
do_something(); // BAD: unreachable code [NOT DETECTED]
50+
}
51+
do_something();
52+
}
53+
}
54+
4355
if cond() {
4456
return;
4557
} else {

0 commit comments

Comments
 (0)