Skip to content

Commit f138f77

Browse files
committed
Rust: Only adjust access type for method call expressions
1 parent 03c9a78 commit f138f77

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
@@ -675,12 +675,13 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
675675
apos = dpos
676676
}
677677

678-
bindingset[apos, target, path, t]
678+
bindingset[a, apos, target, path, t]
679679
pragma[inline_late]
680680
predicate adjustAccessType(
681-
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
681+
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
682+
Type tAdj
682683
) {
683-
if apos.isSelf()
684+
if apos.isSelf() and a.receiverImplicitlyBorrowed()
684685
then
685686
exists(Type selfParamType |
686687
selfParamType = target.getParameterType(TSelfDeclarationPosition(), TypePath::nil())
@@ -844,11 +845,13 @@ private module FieldExprMatchingInput implements MatchingInputSig {
844845
apos = dpos
845846
}
846847

847-
bindingset[apos, target, path, t]
848+
bindingset[a, apos, target, path, t]
848849
pragma[inline_late]
849850
predicate adjustAccessType(
850-
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
851+
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
852+
Type tAdj
851853
) {
854+
exists(a) and
852855
exists(target) and
853856
if apos.isSelf()
854857
then

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
847847
* the inferred type of `42` is `int`, but it should be adjusted to `int?`
848848
* when matching against `M`.
849849
*/
850-
bindingset[apos, target, path, t]
850+
bindingset[a, apos, target, path, t]
851851
default predicate adjustAccessType(
852-
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
852+
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
853+
Type tAdj
853854
) {
854855
pathAdj = path and
855856
tAdj = t
@@ -876,7 +877,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
876877
target = a.getTarget() and
877878
exists(TypePath path0, Type t0 |
878879
t0 = a.getInferredType(apos, path0) and
879-
adjustAccessType(apos, target, path0, t0, path, t)
880+
adjustAccessType(a, apos, target, path0, t0, path, t)
880881
)
881882
}
882883

0 commit comments

Comments
 (0)