Skip to content

Commit ffaf1c0

Browse files
committed
Rust: Change getATypeParameterConstraint to not require a TypeMention
1 parent 2015125 commit ffaf1c0

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ private module Input2 implements InputSig2 {
141141

142142
TypeMention getABaseTypeMention(Type t) { none() }
143143

144-
TypeMention getATypeParameterConstraint(TypeParameter tp) {
145-
result = tp.(TypeParamTypeParameter).getTypeParam().getATypeBound().getTypeRepr()
146-
or
147-
result = tp.(SelfTypeParameter).getTrait()
148-
or
149-
result =
150-
tp.(ImplTraitTypeTypeParameter)
151-
.getImplTraitTypeRepr()
152-
.getTypeBoundList()
153-
.getABound()
154-
.getTypeRepr()
144+
Type getATypeParameterConstraint(TypeParameter tp, TypePath path) {
145+
exists(TypeMention tm | result = tm.resolveTypeAt(path) |
146+
tm = tp.(TypeParamTypeParameter).getTypeParam().getATypeBound().getTypeRepr() or
147+
tm = tp.(SelfTypeParameter).getTrait() or
148+
tm =
149+
tp.(ImplTraitTypeTypeParameter)
150+
.getImplTraitTypeRepr()
151+
.getTypeBoundList()
152+
.getABound()
153+
.getTypeRepr()
154+
)
155155
}
156156

157157
/**

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
343343
* ```
344344
* the type parameter `T` has the constraint `IComparable<T>`.
345345
*/
346-
TypeMention getATypeParameterConstraint(TypeParameter tp);
346+
Type getATypeParameterConstraint(TypeParameter tp, TypePath path);
347347

348348
/**
349349
* Holds if
@@ -1451,13 +1451,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
14511451
accessDeclarationPositionMatch(apos, dpos) and
14521452
constrainedTp = target.getTypeParameter(_) and
14531453
tp = target.getTypeParameter(_) and
1454+
tp = getATypeParameterConstraint(constrainedTp, pathToTp) and
14541455
constrainedTp != tp and
14551456
constrainedTp = target.getDeclaredType(dpos, pathToConstrained) and
1456-
exists(TypeMention tm |
1457-
tm = getATypeParameterConstraint(constrainedTp) and
1458-
tm.resolveTypeAt(pathToTp) = tp and
1459-
constraint = resolveTypeMentionRoot(tm)
1460-
)
1457+
constraint = getATypeParameterConstraint(constrainedTp, TypePath::nil())
14611458
)
14621459
}
14631460

0 commit comments

Comments
 (0)