Skip to content

Commit 46fdbdd

Browse files
committed
wip4
1 parent 5328c34 commit 46fdbdd

2 files changed

Lines changed: 16 additions & 46 deletions

File tree

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,43 +1130,8 @@ private class FunctionDeclaration extends Function {
11301130
this = i.asSome().getAnAssocItem()
11311131
}
11321132

1133-
private TypeParam getTypeParam(ImplOrTraitItemNodeOption i, int j) {
1134-
i = parent and
1135-
(
1136-
result = this.getGenericParamList().getTypeParam(j)
1137-
or
1138-
result = i.asSome().getTypeParam(_) and
1139-
j = -1
1140-
)
1141-
}
1142-
1143-
private TypeParameter getTypeParameter(ImplOrTraitItemNodeOption i, int pos) {
1144-
(
1145-
result = TTypeParamTypeParameter(this.getTypeParam(i, pos))
1146-
or
1147-
// For every `TypeParam` of this function, any associated types accessed on
1148-
// the type parameter are also type parameters.
1149-
result.(TypeParamAssociatedTypeTypeParameter).getTypeParam() = this.getTypeParam(i, _) and
1150-
pos = -1
1151-
or
1152-
i = parent and
1153-
pos = -1 and
1154-
(
1155-
result = TSelfTypeParameter(i.asSome())
1156-
or
1157-
result.(AssociatedTypeTypeParameter).getTrait() = i.asSome()
1158-
or
1159-
this = result.(ImplTraitTypeTypeParameter).getFunction()
1160-
)
1161-
)
1162-
}
1163-
11641133
TypeParameter getTypeParameter(int pos) {
1165-
exists(ImplOrTraitItemNodeOption i | result = this.getTypeParameter(i, pos) |
1166-
i.isNone()
1167-
or
1168-
i.asSome().getAnAssocItem() = this
1169-
)
1134+
result = TTypeParamTypeParameter(this.getGenericParamList().getTypeParam(pos))
11701135
}
11711136
}
11721137

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,9 +1441,12 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
14411441
Access a, AccessEnvironment e, Declaration target, TypePath path, Type t, TypeParameter tp
14421442
) {
14431443
exists(AccessPosition apos, TypePath pathToTp |
1444-
argRootTypeSatisfiesTargetTypeCand(_, a, e, target, apos, tp, pathToTp) and
1445-
SatisfiesParameterConstraint::satisfiesConstraint(MkRelevantAccess(a, apos, e),
1446-
MkRelevantTarget(target, apos), pathToTp.appendInverse(path), t)
1444+
argRootTypeSatisfiesTargetTypeCand(_, a, e, target, pragma[only_bind_into](apos), tp,
1445+
pathToTp) and
1446+
SatisfiesParameterConstraint::satisfiesConstraint(MkRelevantAccess(a,
1447+
pragma[only_bind_into](apos), e),
1448+
MkRelevantTarget(target, pragma[only_bind_into](apos)), pathToTp.appendInverse(path),
1449+
t)
14471450
)
14481451
}
14491452
}
@@ -1559,8 +1562,12 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
15591562
private predicate typeParameterHasConstraint(
15601563
Declaration target, TypeParameter constrainedTp, TypeMention constraint
15611564
) {
1562-
constrainedTp = target.getTypeParameter(_) and
1563-
constraint = getATypeParameterConstraint(constrainedTp, target)
1565+
constraint = getATypeParameterConstraint(constrainedTp, target) and
1566+
(
1567+
constrainedTp = target.getDeclaredType(_, _)
1568+
or
1569+
constrainedTp = target.getTypeParameter(_)
1570+
)
15641571
}
15651572

15661573
/**
@@ -1587,7 +1594,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
15871594
TypeParameter tp
15881595
) {
15891596
typeParameterHasConstraint(target, constrainedTp, constraint) and
1590-
tp = target.getTypeParameter(_) and
15911597
tp = constraint.getTypeAt(pathToTp) and
15921598
constrainedTp != tp
15931599
}
@@ -2085,9 +2091,9 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
20852091
/**
20862092
* Gets the type parameter at position `pos` of this element, if any.
20872093
*
2088-
* TODO:
2089-
* This should include type parameters declared on the element itself,
2090-
* as well as type parameters declared on the enclosing declaration(s).
2094+
* This should only include type parameters declared directly on the element
2095+
* itself; any type parameters that are in scope from the declaring element
2096+
* are handled via `getDeclaringType`.
20912097
*/
20922098
TypeParameter getTypeParameter(int pos);
20932099

@@ -2645,7 +2651,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
26452651
exists(Parameterizable target, TypeParameter tp |
26462652
target = invocation.(InvocationMatchingGetTypeArgumentInput::Access).getTarget() and
26472653
parameterizableReturnContextTypedAt(target, path, tp) and
2648-
tp = target.getTypeParameter(_) and
26492654
// check that no explicit type arguments have been supplied which bind `tp`
26502655
not exists(TypeParameter supplied |
26512656
tp = getAConstrained*(supplied) and

0 commit comments

Comments
 (0)