Skip to content

Commit 4739c88

Browse files
committed
Rust: Also apply adjustedAccessType in RelevantAccess
1 parent 75caa18 commit 4739c88

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ mod trait_associated_type {
697697
println!("{:?}", x3.put(1).unwrap()); // $ method=S::put method=unwrap
698698

699699
// Call to default implementation in `trait` block
700-
println!("{:?}", x3.putTwo(2, 3).unwrap()); // $ method=putTwo MISSING: method=unwrap
700+
println!("{:?}", x3.putTwo(2, 3).unwrap()); // $ method=putTwo method=unwrap
701701

702702
let x4 = g(S); // $ MISSING: type=x4:AT
703703
println!("{:?}", x4);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,9 @@ inferType
778778
| main.rs:697:33:697:33 | 1 | | {EXTERNAL LOCATION} | i32 |
779779
| main.rs:700:18:700:23 | "{:?}\\n" | | {EXTERNAL LOCATION} | str |
780780
| main.rs:700:26:700:27 | x3 | | main.rs:619:5:620:13 | S |
781+
| main.rs:700:26:700:40 | x3.putTwo(...) | | main.rs:568:5:571:5 | Wrapper |
782+
| main.rs:700:26:700:40 | x3.putTwo(...) | A | main.rs:639:36:639:50 | AssociatedParam |
783+
| main.rs:700:26:700:49 | ... .unwrap() | | main.rs:639:36:639:50 | AssociatedParam |
781784
| main.rs:700:36:700:36 | 2 | | {EXTERNAL LOCATION} | i32 |
782785
| main.rs:700:39:700:39 | 3 | | {EXTERNAL LOCATION} | i32 |
783786
| main.rs:702:20:702:20 | S | | main.rs:619:5:620:13 | S |

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -979,17 +979,18 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
979979

980980
private module AccessConstraint {
981981
predicate relevantAccessConstraint(
982-
Access a, AccessPosition apos, TypePath path, Type constraint
982+
Access a, Declaration target, AccessPosition apos, TypePath path, Type constraint
983983
) {
984984
exists(DeclarationPosition dpos |
985985
accessDeclarationPositionMatch(apos, dpos) and
986-
typeParameterConstraintHasTypeParameter(a.getTarget(), dpos, path, _, constraint, _, _)
986+
target = a.getTarget() and
987+
typeParameterConstraintHasTypeParameter(target, dpos, path, _, constraint, _, _)
987988
)
988989
}
989990

990991
private newtype TRelevantAccess =
991-
MkRelevantAccess(Access a, AccessPosition apos, TypePath path) {
992-
relevantAccessConstraint(a, apos, path, _)
992+
MkRelevantAccess(Access a, Declaration target, AccessPosition apos, TypePath path) {
993+
relevantAccessConstraint(a, target, apos, path, _)
993994
}
994995

995996
/**
@@ -998,19 +999,20 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
998999
*/
9991000
private class RelevantAccess extends MkRelevantAccess {
10001001
Access a;
1002+
Declaration target;
10011003
AccessPosition apos;
10021004
TypePath path;
10031005

1004-
RelevantAccess() { this = MkRelevantAccess(a, apos, path) }
1006+
RelevantAccess() { this = MkRelevantAccess(a, target, apos, path) }
10051007

10061008
Type getTypeAt(TypePath suffix) {
1007-
a.getInferredType(apos, path.appendInverse(suffix)) = result
1009+
adjustedAccessType(a, apos, target, path.appendInverse(suffix), result)
10081010
}
10091011

10101012
/** Holds if this relevant access has the type `type` and should satisfy `constraint`. */
10111013
predicate hasTypeConstraint(Type type, Type constraint) {
1012-
type = a.getInferredType(apos, path) and
1013-
relevantAccessConstraint(a, apos, path, constraint)
1014+
adjustedAccessType(a, apos, target, path, type) and
1015+
relevantAccessConstraint(a, target, apos, path, constraint)
10141016
}
10151017

10161018
string toString() {
@@ -1075,7 +1077,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
10751077
RelevantAccess at, TypeAbstraction abs, TypeMention sub, Type t0, TypePath prefix0,
10761078
TypeMention constraintMention
10771079
|
1078-
at = MkRelevantAccess(a, apos, prefix) and
1080+
at = MkRelevantAccess(a, _, apos, prefix) and
10791081
hasConstraintMention(at, abs, sub, constraint, constraintMention) and
10801082
conditionSatisfiesConstraintTypeAt(abs, sub, constraintMention, prefix0, t0)
10811083
|

0 commit comments

Comments
 (0)