Skip to content

Commit fa59a8a

Browse files
committed
Rust: Implement TypeMention for paths that access associated types on concrete types
1 parent 4526afc commit fa59a8a

File tree

6 files changed

+677
-528
lines changed

6 files changed

+677
-528
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ abstract class Type extends TType {
7575
abstract TypeParameter getPositionalTypeParameter(int i);
7676

7777
/** Gets the default type for the `i`th type parameter, if any. */
78-
TypeMention getTypeParameterDefault(int i) { none() }
78+
TypeRepr getTypeParameterDefault(int i) { none() }
7979

8080
/**
8181
* Gets a type parameter of this type.
@@ -129,7 +129,7 @@ class DataType extends Type, TDataType {
129129
result = TTypeParamTypeParameter(typeItem.getGenericParamList().getTypeParam(i))
130130
}
131131

132-
override TypeMention getTypeParameterDefault(int i) {
132+
override TypeRepr getTypeParameterDefault(int i) {
133133
result = typeItem.getGenericParamList().getTypeParam(i).getDefaultType()
134134
}
135135

@@ -189,7 +189,7 @@ class TraitType extends Type, TTrait {
189189
result.(SelfTypeParameter).getTrait() = trait
190190
}
191191

192-
override TypeMention getTypeParameterDefault(int i) {
192+
override TypeRepr getTypeParameterDefault(int i) {
193193
result = trait.getGenericParamList().getTypeParam(i).getDefaultType()
194194
}
195195

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

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

135135
module TypePath = M1::TypePath;
136136

137-
private module Input2 implements InputSig2<TypeMention> {
138-
TypeMention getABaseTypeMention(Type t) { none() }
137+
private module Input2 implements InputSig2<PreTypeMention> {
138+
PreTypeMention getABaseTypeMention(Type t) { none() }
139139

140140
Type getATypeParameterConstraint(TypeParameter tp, TypePath path) {
141141
exists(TypeMention tm | result = tm.getTypeAt(path) |
@@ -158,7 +158,7 @@ private module Input2 implements InputSig2<TypeMention> {
158158
* inference module for more information.
159159
*/
160160
predicate conditionSatisfiesConstraint(
161-
TypeAbstraction abs, TypeMention condition, TypeMention constraint, boolean transitive
161+
TypeAbstraction abs, PreTypeMention condition, PreTypeMention constraint, boolean transitive
162162
) {
163163
// `impl` blocks implementing traits
164164
transitive = false and
@@ -208,7 +208,7 @@ private module Input2 implements InputSig2<TypeMention> {
208208
}
209209
}
210210

211-
private module M2 = Make2<TypeMention, Input2>;
211+
private module M2 = Make2<PreTypeMention, Input2>;
212212

213213
import M2
214214

@@ -1960,7 +1960,7 @@ private module MethodResolution {
19601960
pragma[nomagic]
19611961
predicate hasTypeQualifiedCandidate(ImplItemNode impl) {
19621962
exists(getCallExprTypeQualifier(this, _)) and
1963-
CallExprImpl::getResolvedFunction(this) = impl.getASuccessor(_)
1963+
CallExprImpl::getResolvedFunction(this) = impl.getADescendant()
19641964
}
19651965

19661966
pragma[nomagic]

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ private import TypeInference::Consistency as Consistency
1010
import TypeInference::Consistency
1111

1212
query predicate illFormedTypeMention(TypeMention tm) {
13-
Consistency::illFormedTypeMention(tm) and
13+
// NOTE: We do not use `illFormedTypeMention` from the shared library as it is
14+
// instantiated with `PreTypeMention` and we are interested in inconsistencies
15+
// for `TypeMention`.
16+
not exists(tm.getTypeAt(TypePath::nil())) and
17+
exists(tm.getLocation()) and
1418
// avoid overlap with `PathTypeMention`
1519
not tm instanceof PathTypeReprMention and
1620
// known limitation for type mentions that would mention an escaping type parameter

0 commit comments

Comments
 (0)