Skip to content

Commit 227c985

Browse files
committed
WIP
1 parent 5320133 commit 227c985

File tree

5 files changed

+229
-130
lines changed

5 files changed

+229
-130
lines changed

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class TypePath = M1::TypePath;
134134

135135
module TypePath = M1::TypePath;
136136

137-
private module Input2 implements InputSig2 {
137+
private module Input2 implements InputSig2<PreTypeMention> {
138138
private import TypeMention as TM
139139

140140
class TypeMention = TM::TypeMention;
@@ -162,7 +162,7 @@ private module Input2 implements InputSig2 {
162162
* inference module for more information.
163163
*/
164164
predicate conditionSatisfiesConstraint(
165-
TypeAbstraction abs, TypeMention condition, TypeMention constraint, boolean transitive
165+
TypeAbstraction abs, PreTypeMention condition, PreTypeMention constraint, boolean transitive
166166
) {
167167
// `impl` blocks implementing traits
168168
transitive = false and
@@ -212,7 +212,7 @@ private module Input2 implements InputSig2 {
212212
}
213213
}
214214

215-
private module M2 = Make2<Input2>;
215+
private module M2 = Make2<PreTypeMention, Input2>;
216216

217217
import M2
218218

@@ -236,6 +236,27 @@ module Consistency {
236236
}
237237
}
238238

239+
signature predicate relevantTraitSig(AstNode n, Trait t);
240+
241+
module TermSatisfiesTrait<relevantTraitSig/2 relevantTrait> {
242+
private class RelevantTerm extends AstNode {
243+
RelevantTerm() { relevantTrait(this, _) }
244+
245+
Type getTypeAt(TypePath path) { result = inferType(this, path) }
246+
}
247+
248+
private module MethodCallSatisfiesDerefConstraintInput implements
249+
SatisfiesConstraintInputSig<RelevantTerm>
250+
{
251+
pragma[nomagic]
252+
predicate relevantConstraint(RelevantTerm term, Type constraint) {
253+
relevantTrait(term, constraint.(TraitType).getTrait())
254+
}
255+
256+
predicate useUniversalConditions() { none() }
257+
}
258+
}
259+
239260
/** A function without a `self` parameter. */
240261
private class NonMethodFunction extends Function {
241262
NonMethodFunction() { not this.hasSelfParam() }
@@ -382,7 +403,7 @@ pragma[nomagic]
382403
private Type inferAnnotatedType(AstNode n, TypePath path) {
383404
result = getTypeAnnotation(n).resolveTypeAt(path)
384405
or
385-
result = n.(ShorthandSelfParameterMention).resolveTypeAt(path)
406+
result = n.(SelfParam).(TypeMention).resolveTypeAt(path)
386407
}
387408

388409
pragma[nomagic]
@@ -3770,12 +3791,12 @@ private module ForIterableSatisfiesConstraintInput implements
37703791

37713792
pragma[nomagic]
37723793
private AssociatedTypeTypeParameter getIteratorItemTypeParameter() {
3773-
result.getTypeAlias() = any(IteratorTrait t).getItemType()
3794+
result = getAssociatedTypeTypeParameter(any(IteratorTrait t).getItemType())
37743795
}
37753796

37763797
pragma[nomagic]
37773798
private AssociatedTypeTypeParameter getIntoIteratorItemTypeParameter() {
3778-
result.getTypeAlias() = any(IntoIteratorTrait t).getItemType()
3799+
result = getAssociatedTypeTypeParameter(any(IntoIteratorTrait t).getItemType())
37793800
}
37803801

37813802
pragma[nomagic]
@@ -4121,9 +4142,9 @@ private module Debug {
41214142
Input2::conditionSatisfiesConstraint(abs, condition, constraint, transitive)
41224143
}
41234144

4124-
predicate debugInferShorthandSelfType(ShorthandSelfParameterMention self, TypePath path, Type t) {
4145+
predicate debugInferShorthandSelfType(SelfParam self, TypePath path, Type t) {
41254146
self = getRelevantLocatable() and
4126-
t = self.resolveTypeAt(path)
4147+
t = self.(TypeMention).resolveTypeAt(path)
41274148
}
41284149

41294150
predicate debugInferMethodCallType(AstNode n, TypePath path, Type t) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ query predicate illFormedTypeMention(TypeMention tm) {
1515
not tm instanceof PathTypeReprMention and
1616
// known limitation for type mentions that would mention an escaping type parameter
1717
not tm =
18-
any(PathTypeMention ptm |
18+
any(PathPreTypeMentionImpl ptm |
1919
exists(ptm.resolvePathTypeAt(TypePath::nil())) and
2020
not exists(ptm.resolveType())
2121
or
22-
ptm.(NonAliasPathTypeMention).getResolved() instanceof TypeAlias
22+
ptm.(NonAliasPathPreTypeMentionImpl).getResolved() instanceof TypeAlias
2323
) and
2424
// Only include inconsistencies in the source, as we otherwise get
2525
// inconsistencies from library code in every project.

0 commit comments

Comments
 (0)