Skip to content

Commit c749269

Browse files
committed
Rust: Only adjust access type for method call expressions
1 parent 5bdf989 commit c749269

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,13 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
667667
apos = dpos
668668
}
669669

670-
bindingset[apos, target, path, t]
670+
bindingset[a, apos, target, path, t]
671671
pragma[inline_late]
672672
predicate adjustAccessType(
673-
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
673+
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
674+
Type tAdj
674675
) {
675-
if apos.isSelf()
676+
if apos.isSelf() and a.receiverImplicitlyBorrowed()
676677
then
677678
exists(Type selfParamType |
678679
selfParamType = target.getParameterType(TSelfDeclarationPosition(), TypePath::nil())
@@ -836,11 +837,13 @@ private module FieldExprMatchingInput implements MatchingInputSig {
836837
apos = dpos
837838
}
838839

839-
bindingset[apos, target, path, t]
840+
bindingset[a, apos, target, path, t]
840841
pragma[inline_late]
841842
predicate adjustAccessType(
842-
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
843+
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
844+
Type tAdj
843845
) {
846+
exists(a) and
844847
exists(target) and
845848
if apos.isSelf()
846849
then

shared/typeinference/codeql/typeinference/internal/TypeInference.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
841841
* the inferred type of `42` is `int`, but it should be adjusted to `int?`
842842
* when matching against `M`.
843843
*/
844-
bindingset[apos, target, path, t]
844+
bindingset[a, apos, target, path, t]
845845
default predicate adjustAccessType(
846-
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
846+
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
847+
Type tAdj
847848
) {
848849
pathAdj = path and
849850
tAdj = t
@@ -870,7 +871,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
870871
target = a.getTarget() and
871872
exists(TypePath path0, Type t0 |
872873
t0 = a.getInferredType(apos, path0) and
873-
adjustAccessType(apos, target, path0, t0, path, t)
874+
adjustAccessType(a, apos, target, path0, t0, path, t)
874875
)
875876
}
876877

0 commit comments

Comments
 (0)