Skip to content

Commit 92bce4e

Browse files
committed
Rust: Split getFunctionReturnPos into two predicates
1 parent 9761580 commit 92bce4e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

rust/ql/lib/codeql/rust/elements/internal/ImplTraitTypeReprImpl.qll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ module Impl {
2323
* ```
2424
*/
2525
class ImplTraitTypeRepr extends Generated::ImplTraitTypeRepr {
26-
/**
27-
* Gets the function for which this impl trait type occurs in the return
28-
* type, if any.
29-
*/
30-
Function getFunctionReturnPos() { this.getParentNode*() = result.getRetType().getTypeRepr() }
26+
/** Gets the function for which this impl trait type occurs, if any. */
27+
Function getFunction() {
28+
this.getParentNode*() = [result.getRetType().getTypeRepr(), result.getAParam().getTypeRepr()]
29+
}
30+
31+
/** Holds if this impl trait type occurs in the return type of a function. */
32+
predicate isInReturnPos() {
33+
this.getParentNode*() = this.getFunction().getRetType().getTypeRepr()
34+
}
3135
}
3236
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ newtype TType =
6060
TSliceTypeParameter()
6161

6262
predicate implTraitTypeParam(ImplTraitTypeRepr implTrait, int i, TypeParam tp) {
63-
tp = implTrait.getFunctionReturnPos().getGenericParamList().getTypeParam(i) and
63+
implTrait.isInReturnPos() and
64+
tp = implTrait.getFunction().getGenericParamList().getTypeParam(i) and
6465
// Only include type parameters of the function that occur inside the impl
6566
// trait type.
6667
exists(Path path | path.getParentNode*() = implTrait and resolvePath(path) = tp)
@@ -317,7 +318,7 @@ class DynTraitType extends Type, TDynTraitType {
317318
class ImplTraitReturnType extends ImplTraitType {
318319
private Function function;
319320

320-
ImplTraitReturnType() { function = impl.getFunctionReturnPos() }
321+
ImplTraitReturnType() { impl.isInReturnPos() and function = impl.getFunction() }
321322

322323
override Function getFunction() { result = function }
323324
}

0 commit comments

Comments
 (0)