Skip to content

Commit f9869da

Browse files
committed
Address review comments
1 parent 61d809b commit f9869da

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ pragma[nomagic]
10331033
private Type inferStructExprType0(AstNode n, FunctionPosition pos, TypePath path) {
10341034
exists(StructExprMatchingInput::Access a, StructExprMatchingInput::AccessPosition apos |
10351035
n = a.getNodeAt(apos) and
1036-
if apos.isStructPos() then pos.isReturn() else pos.asPosition() = 0 // the acutal position doesn't matter, as long as it is positional
1036+
if apos.isStructPos() then pos.isReturn() else pos.asPosition() = 0 // the actual position doesn't matter, as long as it is positional
10371037
|
10381038
result = StructExprMatching::inferAccessType(a, apos, path)
10391039
or
@@ -1229,12 +1229,9 @@ private module ContextTyping {
12291229
result = inferCallNonReturnType(n, pos, prefix, path) and
12301230
hasUnknownTypeAt(n, prefix)
12311231
|
1232-
pos.isPosition()
1233-
or
12341232
// Never propagate type information directly into the receiver, since its type
12351233
// must already have been known in order to resolve the call
1236-
pos.isSelf() and
1237-
not prefix.isEmpty()
1234+
if pos.isSelf() then not prefix.isEmpty() else any()
12381235
)
12391236
}
12401237
}
@@ -2648,12 +2645,12 @@ private Type inferMethodCallTypeNonSelf(AstNode n, FunctionPosition pos, TypePat
26482645
* empty, at which point the inferred type can be applied back to `n`.
26492646
*/
26502647
pragma[nomagic]
2651-
private Type inferMethodCallTypeSelf(AstNode n, DerefChain derefChain, TypePath path) {
2648+
private Type inferMethodCallTypeSelf(MethodCall mc, AstNode n, DerefChain derefChain, TypePath path) {
26522649
exists(
26532650
MethodCallMatchingInput::AccessPosition apos, string derefChainBorrow, BorrowKind borrow,
26542651
TypePath path0
26552652
|
2656-
result = inferMethodCallType0(_, apos, n, derefChainBorrow, path0) and
2653+
result = inferMethodCallType0(mc, apos, n, derefChainBorrow, path0) and
26572654
apos.isSelf() and
26582655
MethodCallMatchingInput::decodeDerefChainBorrow(derefChainBorrow, derefChain, borrow)
26592656
|
@@ -2672,7 +2669,7 @@ private Type inferMethodCallTypeSelf(AstNode n, DerefChain derefChain, TypePath
26722669
DerefChain derefChain0, Type t0, TypePath path0, DerefImplItemNode impl, Type selfParamType,
26732670
TypePath selfPath
26742671
|
2675-
t0 = inferMethodCallTypeSelf(n, derefChain0, path0) and
2672+
t0 = inferMethodCallTypeSelf(mc, n, derefChain0, path0) and
26762673
derefChain0.isCons(impl, derefChain) and
26772674
selfParamType = impl.resolveSelfTypeAt(selfPath)
26782675
|
@@ -2692,8 +2689,10 @@ private Type inferMethodCallTypeSelf(AstNode n, DerefChain derefChain, TypePath
26922689
private Type inferMethodCallTypePreCheck(AstNode n, FunctionPosition pos, TypePath path) {
26932690
result = inferMethodCallTypeNonSelf(n, pos, path)
26942691
or
2695-
result = inferMethodCallTypeSelf(n, DerefChain::nil(), path) and
2696-
pos.isSelf()
2692+
exists(MethodCall mc |
2693+
result = inferMethodCallTypeSelf(mc, n, DerefChain::nil(), path) and
2694+
if mc instanceof CallExpr then pos.asPosition() = 0 else pos.isSelf()
2695+
)
26972696
}
26982697

26992698
/**

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ mod context_typed {
26912691
let y = Default::default(); // $ type=y:i32 target=default
26922692
x.push(y); // $ target=push
26932693

2694-
let s = Default::default(); // $ MISSING: target=default type=s:S
2694+
let s = Default::default(); // $ target=default type=s:S
26952695
S::f(s); // $ target=f
26962696
}
26972697
}

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12100,7 +12100,10 @@ inferType
1210012100
| main.rs:2692:9:2692:9 | x | T | {EXTERNAL LOCATION} | i32 |
1210112101
| main.rs:2692:9:2692:17 | x.push(...) | | {EXTERNAL LOCATION} | () |
1210212102
| main.rs:2692:16:2692:16 | y | | {EXTERNAL LOCATION} | i32 |
12103+
| main.rs:2694:13:2694:13 | s | | main.rs:2639:5:2640:13 | S |
12104+
| main.rs:2694:17:2694:34 | ...::default(...) | | main.rs:2639:5:2640:13 | S |
1210312105
| main.rs:2695:9:2695:15 | ...::f(...) | | {EXTERNAL LOCATION} | () |
12106+
| main.rs:2695:14:2695:14 | s | | main.rs:2639:5:2640:13 | S |
1210412107
| main.rs:2702:14:2702:17 | SelfParam | | main.rs:2700:5:2708:5 | Self [trait MyTrait] |
1210512108
| main.rs:2705:14:2705:18 | SelfParam | | {EXTERNAL LOCATION} | & |
1210612109
| main.rs:2705:14:2705:18 | SelfParam | TRef | main.rs:2700:5:2708:5 | Self [trait MyTrait] |

0 commit comments

Comments
 (0)