Rust: Split getFunctionReturnPos into two predicates

This commit is contained in:
Simon Friis Vindum
2025-07-28 10:45:59 +02:00
parent 9761580b7e
commit 92bce4e432
2 changed files with 12 additions and 7 deletions

View File

@@ -23,10 +23,14 @@ module Impl {
* ```
*/
class ImplTraitTypeRepr extends Generated::ImplTraitTypeRepr {
/**
* Gets the function for which this impl trait type occurs in the return
* type, if any.
*/
Function getFunctionReturnPos() { this.getParentNode*() = result.getRetType().getTypeRepr() }
/** Gets the function for which this impl trait type occurs, if any. */
Function getFunction() {
this.getParentNode*() = [result.getRetType().getTypeRepr(), result.getAParam().getTypeRepr()]
}
/** Holds if this impl trait type occurs in the return type of a function. */
predicate isInReturnPos() {
this.getParentNode*() = this.getFunction().getRetType().getTypeRepr()
}
}
}

View File

@@ -60,7 +60,8 @@ newtype TType =
TSliceTypeParameter()
predicate implTraitTypeParam(ImplTraitTypeRepr implTrait, int i, TypeParam tp) {
tp = implTrait.getFunctionReturnPos().getGenericParamList().getTypeParam(i) and
implTrait.isInReturnPos() and
tp = implTrait.getFunction().getGenericParamList().getTypeParam(i) and
// Only include type parameters of the function that occur inside the impl
// trait type.
exists(Path path | path.getParentNode*() = implTrait and resolvePath(path) = tp)
@@ -317,7 +318,7 @@ class DynTraitType extends Type, TDynTraitType {
class ImplTraitReturnType extends ImplTraitType {
private Function function;
ImplTraitReturnType() { function = impl.getFunctionReturnPos() }
ImplTraitReturnType() { impl.isInReturnPos() and function = impl.getFunction() }
override Function getFunction() { result = function }
}