diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index bcc18342c007..15daf6d2f179 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -1812,8 +1812,12 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi } pragma[nomagic] - private Type getInferredSelfType(string derefChain, boolean borrow, TypePath path) { - result = this.getACandidateReceiverTypeAt(derefChain, borrow, path) + private Type getInferredSelfType(AccessPosition apos, string derefChainBorrow, TypePath path) { + exists(string derefChain, boolean borrow | + result = this.getACandidateReceiverTypeAt(derefChain, borrow, path) and + derefChainBorrow = encodeDerefChainBorrow(derefChain, borrow) and + apos.isSelf() + ) } pragma[nomagic] @@ -1839,11 +1843,7 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi bindingset[derefChainBorrow] Type getInferredType(string derefChainBorrow, AccessPosition apos, TypePath path) { - exists(string derefChain, boolean borrow | - derefChainBorrow = encodeDerefChainBorrow(derefChain, borrow) and - apos.isSelf() and - result = this.getInferredSelfType(derefChain, borrow, path) - ) + result = this.getInferredSelfType(apos, derefChainBorrow, path) or result = this.getInferredNonSelfType(apos, path) } diff --git a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll index ff9ccf3c192b..0b259df92116 100644 --- a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll +++ b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll @@ -1160,7 +1160,7 @@ module Make1 Input1> { pragma[nomagic] private predicate directTypeMatch0( - Access a, AccessEnvironment e, Declaration target, DeclarationPosition dpos, + Access a, DeclarationPosition dpos, AccessEnvironment e, Declaration target, TypePath pathToTypeParam, TypeParameter tp ) { not exists(getTypeArgument(a, target, tp, _)) and @@ -1177,7 +1177,7 @@ module Make1 Input1> { Access a, AccessEnvironment e, Declaration target, TypePath path, Type t, TypeParameter tp ) { exists(AccessPosition apos, DeclarationPosition dpos, TypePath pathToTypeParam | - directTypeMatch0(a, e, target, dpos, pathToTypeParam, tp) and + directTypeMatch0(a, dpos, e, target, pathToTypeParam, tp) and accessDeclarationPositionMatch(apos, dpos) and t = a.getInferredType(e, apos, pathToTypeParam.appendInverse(path)) ) @@ -1269,7 +1269,7 @@ module Make1 Input1> { } private newtype TRelevantAccess = - MkRelevantAccess(Access a, AccessEnvironment e, AccessPosition apos, TypePath path) { + MkRelevantAccess(Access a, AccessPosition apos, AccessEnvironment e, TypePath path) { relevantAccessConstraint(a, e, _, apos, path, _) } @@ -1279,11 +1279,11 @@ module Make1 Input1> { */ private class RelevantAccess extends MkRelevantAccess { Access a; - AccessEnvironment e; AccessPosition apos; + AccessEnvironment e; TypePath path; - RelevantAccess() { this = MkRelevantAccess(a, e, apos, path) } + RelevantAccess() { this = MkRelevantAccess(a, apos, e, path) } Type getTypeAt(TypePath suffix) { result = a.getInferredType(e, apos, path.appendInverse(suffix)) @@ -1314,7 +1314,7 @@ module Make1 Input1> { Type constraint, TypePath path, Type t ) { exists(RelevantAccess ra | - ra = MkRelevantAccess(a, e, apos, prefix) and + ra = MkRelevantAccess(a, apos, e, prefix) and SatisfiesConstraint::satisfiesConstraintType(ra, constraint, path, t) and constraint = ra.getConstraint(target)