Skip to content

Commit add2e0f

Browse files
committed
Rust: Extend methodResolutionDependsOnArgument to parameterized implementations
1 parent 961e620 commit add2e0f

File tree

4 files changed

+19
-42974
lines changed

4 files changed

+19
-42974
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,17 @@ private Function getTypeParameterMethod(TypeParameter tp, string name) {
12201220
result = getMethodSuccessor(tp.(ImplTraitTypeTypeParameter).getImplTraitTypeRepr(), name)
12211221
}
12221222

1223+
pragma[nomagic]
1224+
private Type resolveNonTypeParameterTypeAt(TypeMention tm, TypePath path) {
1225+
result = tm.resolveTypeAt(path) and
1226+
not result instanceof TypeParameter
1227+
}
1228+
12231229
bindingset[t1, t2]
12241230
private predicate typeMentionEqual(TypeMention t1, TypeMention t2) {
1225-
forex(TypePath path, Type type | t1.resolveTypeAt(path) = type | t2.resolveTypeAt(path) = type)
1231+
forex(TypePath path, Type type | resolveNonTypeParameterTypeAt(t1, path) = type |
1232+
resolveNonTypeParameterTypeAt(t2, path) = type
1233+
)
12261234
}
12271235

12281236
pragma[nomagic]
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
multipleCallTargets
22
| dereference.rs:61:15:61:24 | e1.deref() |
3-
| main.rs:2032:13:2032:31 | ...::from(...) |
4-
| main.rs:2033:13:2033:31 | ...::from(...) |
5-
| main.rs:2034:13:2034:31 | ...::from(...) |
6-
| main.rs:2040:13:2040:31 | ...::from(...) |
7-
| main.rs:2041:13:2041:31 | ...::from(...) |
8-
| main.rs:2042:13:2042:31 | ...::from(...) |
9-
| main.rs:2078:21:2078:43 | ...::from(...) |
3+
| main.rs:2076:13:2076:31 | ...::from(...) |
4+
| main.rs:2077:13:2077:31 | ...::from(...) |
5+
| main.rs:2078:13:2078:31 | ...::from(...) |
6+
| main.rs:2084:13:2084:31 | ...::from(...) |
7+
| main.rs:2085:13:2085:31 | ...::from(...) |
8+
| main.rs:2086:13:2086:31 | ...::from(...) |
9+
| main.rs:2122:21:2122:43 | ...::from(...) |

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,9 +2028,9 @@ mod method_determined_by_argument_type {
20282028
x.my_add(&5i64); // $ method=MyAdd<&i64>::my_add
20292029
x.my_add(true); // $ method=MyAdd<bool>::my_add
20302030

2031-
S(1i64).my_add(S(2i64)); // $ method=S::my_add1 $ SPURIOUS method=S::my_add2 $ SPURIOUS method=S::my_add3
2032-
S(1i64).my_add(3i64); // $ method=S::my_add2 $ SPURIOUS method=S::my_add1 $ SPURIOUS method=S::my_add3
2033-
S(1i64).my_add(&3i64); // $ method=S::my_add3 $ SPURIOUS method=S::my_add1 $ SPURIOUS method=S::my_add2
2031+
S(1i64).my_add(S(2i64)); // $ method=S::my_add1
2032+
S(1i64).my_add(3i64); // $ MISSING: method=S::my_add2
2033+
S(1i64).my_add(&3i64); // $ method=S::my_add3
20342034
}
20352035
}
20362036

0 commit comments

Comments
 (0)