Skip to content

Commit fa7056b

Browse files
committed
Rust: Avoid overlapping path resolution consistency checks
1 parent cdd6245 commit fa7056b

File tree

16 files changed

+696
-515
lines changed

16 files changed

+696
-515
lines changed

rust/ql/consistency-queries/PathResolutionConsistency.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class SourceLocatable extends Locatable {
2020
}
2121
}
2222

23-
query predicate multipleMethodCallTargets(SourceLocatable a, SourceLocatable b) {
24-
PathResolutionConsistency::multipleMethodCallTargets(a, b)
23+
query predicate multipleCallTargets(SourceLocatable a, SourceLocatable b) {
24+
PathResolutionConsistency::multipleCallTargets(a, b)
2525
}
2626

2727
query predicate multiplePathResolutions(SourceLocatable a, SourceLocatable b) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ query predicate multiplePathResolutions(Path p, ItemNode i) {
1717
not use.isGlob() and
1818
not use.hasUseTreeList()
1919
).getPath() and
20+
// avoid overlap with `multipleCallTargets` below
21+
not p = any(CallExpr ce).getFunction().(PathExpr).getPath() and
2022
strictcount(resolvePath(p)) > 1
2123
}
2224

2325
/** Holds if `call` has multiple static call targets including `target`. */
24-
query predicate multipleMethodCallTargets(MethodCallExpr call, Callable target) {
26+
query predicate multipleCallTargets(CallExprBase call, Callable target) {
2527
target = call.getStaticTarget() and
2628
strictcount(call.getStaticTarget()) > 1
2729
}
@@ -51,8 +53,8 @@ int getPathResolutionInconsistencyCounts(string type) {
5153
type = "Multiple path resolutions" and
5254
result = count(Path p | multiplePathResolutions(p, _) | p)
5355
or
54-
type = "Multiple static method call targets" and
55-
result = count(CallExprBase call | multipleMethodCallTargets(call, _) | call)
56+
type = "Multiple static call targets" and
57+
result = count(CallExprBase call | multipleCallTargets(call, _) | call)
5658
or
5759
type = "Multiple record fields" and
5860
result = count(FieldExpr fe | multipleStructFields(fe, _) | fe)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
multipleCallTargets
2+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
3+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
4+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
5+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
6+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
7+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
8+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
9+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
10+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
11+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
12+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
13+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
114
multiplePathResolutions
215
| macro_expansion.rs:1:5:1:14 | proc_macro | file://:0:0:0:0 | Crate(proc_macro@0.0.0) |
316
| macro_expansion.rs:1:5:1:14 | proc_macro | proc_macro.rs:0:0:0:0 | Crate(proc_macro@0.0.1) |
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
multiplePathResolutions
2-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
3-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
4-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
5-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
6-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
7-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
8-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
9-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
10-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
11-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
12-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
13-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
14-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
15-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
1+
multipleCallTargets
2+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
3+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
4+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
5+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
6+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
7+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
8+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
9+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
10+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
11+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
12+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
13+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
14+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
15+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |

0 commit comments

Comments
 (0)