Rust: Only adjust access type for method call expressions

This commit is contained in:
Simon Friis Vindum
2025-06-11 15:08:41 +02:00
parent 03c9a78bfb
commit f138f77cc1
2 changed files with 12 additions and 8 deletions

View File

@@ -675,12 +675,13 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
apos = dpos
}
bindingset[apos, target, path, t]
bindingset[a, apos, target, path, t]
pragma[inline_late]
predicate adjustAccessType(
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
Type tAdj
) {
if apos.isSelf()
if apos.isSelf() and a.receiverImplicitlyBorrowed()
then
exists(Type selfParamType |
selfParamType = target.getParameterType(TSelfDeclarationPosition(), TypePath::nil())
@@ -844,11 +845,13 @@ private module FieldExprMatchingInput implements MatchingInputSig {
apos = dpos
}
bindingset[apos, target, path, t]
bindingset[a, apos, target, path, t]
pragma[inline_late]
predicate adjustAccessType(
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
Type tAdj
) {
exists(a) and
exists(target) and
if apos.isSelf()
then

View File

@@ -847,9 +847,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
* the inferred type of `42` is `int`, but it should be adjusted to `int?`
* when matching against `M`.
*/
bindingset[apos, target, path, t]
bindingset[a, apos, target, path, t]
default predicate adjustAccessType(
AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj, Type tAdj
Access a, AccessPosition apos, Declaration target, TypePath path, Type t, TypePath pathAdj,
Type tAdj
) {
pathAdj = path and
tAdj = t
@@ -876,7 +877,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
target = a.getTarget() and
exists(TypePath path0, Type t0 |
t0 = a.getInferredType(apos, path0) and
adjustAccessType(apos, target, path0, t0, path, t)
adjustAccessType(a, apos, target, path0, t0, path, t)
)
}