Skip to content

Commit 8462d98

Browse files
committed
dbg2
1 parent 6159d34 commit 8462d98

File tree

6 files changed

+56
-91
lines changed

6 files changed

+56
-91
lines changed

rust/ql/lib/codeql/rust/elements/internal/MacroCallImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module Impl {
2020
or
2121
n = root.(Adt).getDeriveMacroExpansion(_)
2222
or
23-
n = root.(Item).getAttributeMacroExpansion()
24-
or
23+
// or
24+
// n = root.(Item).getAttributeMacroExpansion()
2525
isInMacroExpansion(root, n.getParentNode())
2626
}
2727

rust/ql/lib/codeql/rust/internal/Definitions.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ private import codeql.rust.internal.PathResolution
1717

1818
/** An element with an associated definition. */
1919
abstract class Use extends Locatable {
20+
Use() { not this.(AstNode).isFromMacroExpansion() }
21+
2022
/** Gets the definition associated with this element. */
2123
abstract Definition getDefinition();
2224

rust/ql/test/library-tests/definitions/Definitions.expected

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,29 @@
1010
| main.rs:20:13:20:14 | S2 | main.rs:16:5:16:24 | struct S2 | path |
1111
| main.rs:20:16:20:16 | x | main.rs:19:20:19:20 | x | local variable |
1212
| main.rs:29:5:29:11 | println | {EXTERNAL LOCATION} | MacroRules | path |
13-
| main.rs:29:5:29:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
14-
| main.rs:29:5:29:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
15-
| main.rs:29:5:29:12 | _print | {EXTERNAL LOCATION} | fn _print | path |
16-
| main.rs:29:5:29:12 | format_args_nl | {EXTERNAL LOCATION} | MacroRules | path |
17-
| main.rs:29:5:29:12 | io | {EXTERNAL LOCATION} | mod io | path |
1813
| main.rs:29:22:29:26 | value | main.rs:29:50:29:54 | value | format argument |
1914
| main.rs:29:29:29:33 | width | main.rs:26:9:26:13 | width | local variable |
2015
| main.rs:29:36:29:44 | precision | main.rs:27:9:27:17 | precision | local variable |
2116
| main.rs:30:5:30:11 | println | {EXTERNAL LOCATION} | MacroRules | path |
22-
| main.rs:30:5:30:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
23-
| main.rs:30:5:30:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
24-
| main.rs:30:5:30:12 | _print | {EXTERNAL LOCATION} | fn _print | path |
25-
| main.rs:30:5:30:12 | format_args_nl | {EXTERNAL LOCATION} | MacroRules | path |
26-
| main.rs:30:5:30:12 | io | {EXTERNAL LOCATION} | mod io | path |
2717
| main.rs:30:22:30:22 | 0 | main.rs:30:34:30:38 | value | format argument |
2818
| main.rs:30:25:30:25 | 1 | main.rs:30:41:30:45 | width | format argument |
2919
| main.rs:30:28:30:28 | 2 | main.rs:30:48:30:56 | precision | format argument |
3020
| main.rs:30:34:30:38 | value | main.rs:28:9:28:13 | value | local variable |
3121
| main.rs:30:41:30:45 | width | main.rs:26:9:26:13 | width | local variable |
3222
| main.rs:30:48:30:56 | precision | main.rs:27:9:27:17 | precision | local variable |
3323
| main.rs:31:5:31:11 | println | {EXTERNAL LOCATION} | MacroRules | path |
34-
| main.rs:31:5:31:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
35-
| main.rs:31:5:31:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
36-
| main.rs:31:5:31:12 | _print | {EXTERNAL LOCATION} | fn _print | path |
37-
| main.rs:31:5:31:12 | format_args_nl | {EXTERNAL LOCATION} | MacroRules | path |
38-
| main.rs:31:5:31:12 | io | {EXTERNAL LOCATION} | mod io | path |
3924
| main.rs:31:21:31:22 | {} | main.rs:31:29:31:33 | value | format argument |
4025
| main.rs:31:24:31:25 | {} | main.rs:31:36:31:40 | width | format argument |
4126
| main.rs:31:29:31:33 | value | main.rs:28:9:28:13 | value | local variable |
4227
| main.rs:31:36:31:40 | width | main.rs:26:9:26:13 | width | local variable |
4328
| main.rs:33:5:33:11 | println | {EXTERNAL LOCATION} | MacroRules | path |
44-
| main.rs:33:5:33:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
45-
| main.rs:33:5:33:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
46-
| main.rs:33:5:33:12 | _print | {EXTERNAL LOCATION} | fn _print | path |
47-
| main.rs:33:5:33:12 | format_args_nl | {EXTERNAL LOCATION} | MacroRules | path |
48-
| main.rs:33:5:33:12 | io | {EXTERNAL LOCATION} | mod io | path |
4929
| main.rs:33:22:33:27 | people | main.rs:32:9:32:14 | people | local variable |
5030
| main.rs:34:5:34:11 | println | {EXTERNAL LOCATION} | MacroRules | path |
51-
| main.rs:34:5:34:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
52-
| main.rs:34:5:34:12 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
53-
| main.rs:34:5:34:12 | _print | {EXTERNAL LOCATION} | fn _print | path |
54-
| main.rs:34:5:34:12 | format_args_nl | {EXTERNAL LOCATION} | MacroRules | path |
55-
| main.rs:34:5:34:12 | io | {EXTERNAL LOCATION} | mod io | path |
5631
| main.rs:34:16:34:16 | 1 | main.rs:34:34:34:34 | 2 | format argument |
5732
| main.rs:34:19:34:20 | {} | main.rs:34:31:34:31 | 1 | format argument |
5833
| main.rs:34:23:34:23 | 0 | main.rs:34:31:34:31 | 1 | format argument |
5934
| main.rs:34:26:34:27 | {} | main.rs:34:34:34:34 | 2 | format argument |
6035
| main.rs:35:5:35:13 | assert_eq | {EXTERNAL LOCATION} | MacroRules | path |
61-
| main.rs:35:5:35:14 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
62-
| main.rs:35:5:35:14 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
63-
| main.rs:35:5:35:14 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
64-
| main.rs:35:5:35:14 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
65-
| main.rs:35:5:35:14 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
66-
| main.rs:35:5:35:14 | $crate | {EXTERNAL LOCATION} | Crate([email protected]) | path |
67-
| main.rs:35:5:35:14 | AssertKind | {EXTERNAL LOCATION} | enum AssertKind | path |
68-
| main.rs:35:5:35:14 | Eq | {EXTERNAL LOCATION} | Eq | path |
69-
| main.rs:35:5:35:14 | None | {EXTERNAL LOCATION} | None | path |
70-
| main.rs:35:5:35:14 | Option | {EXTERNAL LOCATION} | enum Option | path |
71-
| main.rs:35:5:35:14 | __export | {EXTERNAL LOCATION} | mod __export | path |
72-
| main.rs:35:5:35:14 | __export | {EXTERNAL LOCATION} | mod __export | path |
73-
| main.rs:35:5:35:14 | assert_failed | {EXTERNAL LOCATION} | fn assert_failed | path |
74-
| main.rs:35:5:35:14 | fmt | {EXTERNAL LOCATION} | mod fmt | path |
75-
| main.rs:35:5:35:14 | format | {EXTERNAL LOCATION} | fn format | path |
76-
| main.rs:35:5:35:14 | format_args | {EXTERNAL LOCATION} | MacroRules | path |
77-
| main.rs:35:5:35:14 | kind | main.rs:35:5:35:14 | kind | local variable |
78-
| main.rs:35:5:35:14 | left_val | main.rs:35:5:35:14 | left_val | local variable |
79-
| main.rs:35:5:35:14 | left_val | main.rs:35:5:35:14 | left_val | local variable |
80-
| main.rs:35:5:35:14 | must_use | {EXTERNAL LOCATION} | fn must_use | path |
81-
| main.rs:35:5:35:14 | option | {EXTERNAL LOCATION} | mod option | path |
82-
| main.rs:35:5:35:14 | panicking | {EXTERNAL LOCATION} | mod panicking | path |
83-
| main.rs:35:5:35:14 | panicking | {EXTERNAL LOCATION} | mod panicking | path |
84-
| main.rs:35:5:35:14 | right_val | main.rs:35:5:35:14 | right_val | local variable |
85-
| main.rs:35:5:35:14 | right_val | main.rs:35:5:35:14 | right_val | local variable |
8636
| main.rs:35:16:35:21 | format | {EXTERNAL LOCATION} | MacroRules | path |
8737
| main.rs:35:31:35:35 | {:<5} | main.rs:35:40:35:42 | "x" | format argument |
8838
| main.rs:36:13:36:13 | S | main.rs:1:1:1:9 | struct S | path |
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
| main.rs:11:9:11:9 | a | Variable $@ is assigned a value that is never used. | main.rs:11:9:11:9 | a | a |
2-
| main.rs:14:9:14:9 | d | Variable $@ is assigned a value that is never used. | main.rs:14:9:14:9 | d | d |
3-
| main.rs:40:5:40:5 | b | Variable $@ is assigned a value that is never used. | main.rs:31:9:31:9 | b | b |
4-
| main.rs:42:5:42:5 | c | Variable $@ is assigned a value that is never used. | main.rs:32:13:32:13 | c | c |
5-
| main.rs:45:5:45:5 | c | Variable $@ is assigned a value that is never used. | main.rs:32:13:32:13 | c | c |
6-
| main.rs:49:9:49:9 | d | Variable $@ is assigned a value that is never used. | main.rs:33:13:33:13 | d | d |
7-
| main.rs:55:5:55:5 | e | Variable $@ is assigned a value that is never used. | main.rs:34:13:34:13 | e | e |
8-
| main.rs:66:5:66:5 | f | Variable $@ is assigned a value that is never used. | main.rs:35:13:35:13 | f | f |
9-
| main.rs:68:5:68:5 | f | Variable $@ is assigned a value that is never used. | main.rs:35:13:35:13 | f | f |
10-
| main.rs:70:5:70:5 | g | Variable $@ is assigned a value that is never used. | main.rs:36:9:36:9 | g | g |
11-
| main.rs:96:9:96:9 | a | Variable $@ is assigned a value that is never used. | main.rs:96:9:96:9 | a | a |
12-
| main.rs:117:9:117:10 | is | Variable $@ is assigned a value that is never used. | main.rs:117:9:117:10 | is | is |
13-
| main.rs:140:13:140:17 | total | Variable $@ is assigned a value that is never used. | main.rs:140:13:140:17 | total | total |
14-
| main.rs:285:13:285:17 | total | Variable $@ is assigned a value that is never used. | main.rs:253:13:253:17 | total | total |
15-
| main.rs:322:12:322:12 | j | Variable $@ is assigned a value that is never used. | main.rs:322:12:322:12 | j | j |
16-
| main.rs:382:9:382:9 | x | Variable $@ is assigned a value that is never used. | main.rs:382:9:382:9 | x | x |
17-
| main.rs:390:17:390:17 | x | Variable $@ is assigned a value that is never used. | main.rs:390:17:390:17 | x | x |
18-
| main.rs:536:9:536:20 | var_in_macro | Variable $@ is assigned a value that is never used. | main.rs:536:9:536:20 | var_in_macro | var_in_macro |
19-
| main.rs:545:9:545:9 | c | Variable $@ is assigned a value that is never used. | main.rs:545:9:545:9 | c | c |
1+
| main.rs:12:9:12:9 | a | Variable $@ is assigned a value that is never used. | main.rs:12:9:12:9 | a | a |
2+
| main.rs:15:9:15:9 | d | Variable $@ is assigned a value that is never used. | main.rs:15:9:15:9 | d | d |
3+
| main.rs:41:5:41:5 | b | Variable $@ is assigned a value that is never used. | main.rs:32:9:32:9 | b | b |
4+
| main.rs:43:5:43:5 | c | Variable $@ is assigned a value that is never used. | main.rs:33:13:33:13 | c | c |
5+
| main.rs:46:5:46:5 | c | Variable $@ is assigned a value that is never used. | main.rs:33:13:33:13 | c | c |
6+
| main.rs:50:9:50:9 | d | Variable $@ is assigned a value that is never used. | main.rs:34:13:34:13 | d | d |
7+
| main.rs:56:5:56:5 | e | Variable $@ is assigned a value that is never used. | main.rs:35:13:35:13 | e | e |
8+
| main.rs:67:5:67:5 | f | Variable $@ is assigned a value that is never used. | main.rs:36:13:36:13 | f | f |
9+
| main.rs:69:5:69:5 | f | Variable $@ is assigned a value that is never used. | main.rs:36:13:36:13 | f | f |
10+
| main.rs:71:5:71:5 | g | Variable $@ is assigned a value that is never used. | main.rs:37:9:37:9 | g | g |
11+
| main.rs:97:9:97:9 | a | Variable $@ is assigned a value that is never used. | main.rs:97:9:97:9 | a | a |
12+
| main.rs:118:9:118:10 | is | Variable $@ is assigned a value that is never used. | main.rs:118:9:118:10 | is | is |
13+
| main.rs:141:13:141:17 | total | Variable $@ is assigned a value that is never used. | main.rs:141:13:141:17 | total | total |
14+
| main.rs:286:13:286:17 | total | Variable $@ is assigned a value that is never used. | main.rs:254:13:254:17 | total | total |
15+
| main.rs:323:12:323:12 | j | Variable $@ is assigned a value that is never used. | main.rs:323:12:323:12 | j | j |
16+
| main.rs:383:9:383:9 | x | Variable $@ is assigned a value that is never used. | main.rs:383:9:383:9 | x | x |
17+
| main.rs:391:17:391:17 | x | Variable $@ is assigned a value that is never used. | main.rs:391:17:391:17 | x | x |
18+
| main.rs:537:9:537:20 | var_in_macro | Variable $@ is assigned a value that is never used. | main.rs:537:9:537:20 | var_in_macro | var_in_macro |
19+
| main.rs:546:9:546:9 | c | Variable $@ is assigned a value that is never used. | main.rs:546:9:546:9 | c | c |
2020
| 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 |
2121
| 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 |
2222
| more.rs:65:13:65:17 | f_ptr | Variable $@ is assigned a value that is never used. | more.rs:65:13:65:17 | f_ptr | f_ptr |
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
| main.rs:30:9:30:9 | a | Variable 'a' is not used. |
2-
| main.rs:99:13:99:13 | d | Variable 'd' is not used. |
3-
| main.rs:148:5:148:5 | y | Variable 'y' is not used. |
4-
| main.rs:175:9:175:9 | x | Variable 'x' is not used. |
5-
| main.rs:255:17:255:17 | a | Variable 'a' is not used. |
6-
| main.rs:263:20:263:22 | val | Variable 'val' is not used. |
7-
| main.rs:277:14:277:16 | val | Variable 'val' is not used. |
8-
| main.rs:292:22:292:24 | val | Variable 'val' is not used. |
9-
| main.rs:299:24:299:26 | val | Variable 'val' is not used. |
10-
| main.rs:307:13:307:15 | num | Variable 'num' is not used. |
11-
| main.rs:342:25:342:25 | y | Variable 'y' is not used. |
12-
| main.rs:345:28:345:28 | a | Variable 'a' is not used. |
13-
| main.rs:348:9:348:9 | p | Variable 'p' is not used. |
14-
| main.rs:366:9:366:13 | right | Variable 'right' is not used. |
15-
| main.rs:372:9:372:14 | right2 | Variable 'right2' is not used. |
16-
| main.rs:383:13:383:13 | y | Variable 'y' is not used. |
17-
| main.rs:391:21:391:21 | y | Variable 'y' is not used. |
18-
| main.rs:436:26:436:28 | val | Variable 'val' is not used. |
19-
| main.rs:439:21:439:23 | acc | Variable 'acc' is not used. |
20-
| main.rs:460:9:460:14 | unused | Variable 'unused' is not used. |
1+
#select
2+
| main.rs:31:9:31:9 | a | Variable 'a' is not used. |
3+
| main.rs:100:13:100:13 | d | Variable 'd' is not used. |
4+
| main.rs:149:5:149:5 | y | Variable 'y' is not used. |
5+
| main.rs:176:9:176:9 | x | Variable 'x' is not used. |
6+
| main.rs:256:17:256:17 | a | Variable 'a' is not used. |
7+
| main.rs:264:20:264:22 | val | Variable 'val' is not used. |
8+
| main.rs:278:14:278:16 | val | Variable 'val' is not used. |
9+
| main.rs:293:22:293:24 | val | Variable 'val' is not used. |
10+
| main.rs:300:24:300:26 | val | Variable 'val' is not used. |
11+
| main.rs:308:13:308:15 | num | Variable 'num' is not used. |
12+
| main.rs:343:25:343:25 | y | Variable 'y' is not used. |
13+
| main.rs:346:28:346:28 | a | Variable 'a' is not used. |
14+
| main.rs:349:9:349:9 | p | Variable 'p' is not used. |
15+
| main.rs:367:9:367:13 | right | Variable 'right' is not used. |
16+
| main.rs:373:9:373:14 | right2 | Variable 'right2' is not used. |
17+
| main.rs:384:13:384:13 | y | Variable 'y' is not used. |
18+
| main.rs:392:21:392:21 | y | Variable 'y' is not used. |
19+
| main.rs:437:26:437:28 | val | Variable 'val' is not used. |
20+
| main.rs:440:21:440:23 | acc | Variable 'acc' is not used. |
21+
| main.rs:461:9:461:14 | unused | Variable 'unused' is not used. |
22+
| main.rs:571:29:571:29 | z | Variable 'z' is not used. |
2123
| more.rs:24:9:24:11 | val | Variable 'val' is not used. |
24+
testFailures
25+
| main.rs:571:29:571:29 | Variable 'z' is not used. | Unexpected result: Alert |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(let_chains)]
2+
#![feature(if_let_guard)]
23
mod more;
34
mod unreachable;
45

@@ -564,6 +565,14 @@ trait MyTrait {
564565
fn my_func2(&self, x: i32) -> i32;
565566
}
566567

568+
fn foo() {
569+
let x = Some(32);
570+
match x {
571+
Some(y) if let Some(z) = Some(y) => println!("found a value: {}", z),
572+
_ => println!("no value"),
573+
}
574+
}
575+
567576
// --- main ---
568577

569578
fn main() {

0 commit comments

Comments
 (0)