Skip to content

Commit f939e98

Browse files
committed
Rust: Extend methodResolutionDependsOnArgument to parameterized implementations
1 parent b841e3e commit f939e98

File tree

3 files changed

+12
-42967
lines changed

3 files changed

+12
-42967
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]

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)