From ffaf1c0a24eeddc7adf2c5ad70000f7829db5a5e Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 22 Jan 2026 13:02:06 +0100 Subject: [PATCH] Rust: Change `getATypeParameterConstraint` to not require a `TypeMention` --- .../internal/typeinference/TypeInference.qll | 22 +++++++++---------- .../typeinference/internal/TypeInference.qll | 9 +++----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll index 10df835cc08a..ebf7bd2aa82d 100644 --- a/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll @@ -141,17 +141,17 @@ private module Input2 implements InputSig2 { TypeMention getABaseTypeMention(Type t) { none() } - TypeMention getATypeParameterConstraint(TypeParameter tp) { - result = tp.(TypeParamTypeParameter).getTypeParam().getATypeBound().getTypeRepr() - or - result = tp.(SelfTypeParameter).getTrait() - or - result = - tp.(ImplTraitTypeTypeParameter) - .getImplTraitTypeRepr() - .getTypeBoundList() - .getABound() - .getTypeRepr() + Type getATypeParameterConstraint(TypeParameter tp, TypePath path) { + exists(TypeMention tm | result = tm.resolveTypeAt(path) | + tm = tp.(TypeParamTypeParameter).getTypeParam().getATypeBound().getTypeRepr() or + tm = tp.(SelfTypeParameter).getTrait() or + tm = + tp.(ImplTraitTypeTypeParameter) + .getImplTraitTypeRepr() + .getTypeBoundList() + .getABound() + .getTypeRepr() + ) } /** diff --git a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll index 5295048623e1..0a20bd59f1b2 100644 --- a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll +++ b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll @@ -343,7 +343,7 @@ module Make1 Input1> { * ``` * the type parameter `T` has the constraint `IComparable`. */ - TypeMention getATypeParameterConstraint(TypeParameter tp); + Type getATypeParameterConstraint(TypeParameter tp, TypePath path); /** * Holds if @@ -1451,13 +1451,10 @@ module Make1 Input1> { accessDeclarationPositionMatch(apos, dpos) and constrainedTp = target.getTypeParameter(_) and tp = target.getTypeParameter(_) and + tp = getATypeParameterConstraint(constrainedTp, pathToTp) and constrainedTp != tp and constrainedTp = target.getDeclaredType(dpos, pathToConstrained) and - exists(TypeMention tm | - tm = getATypeParameterConstraint(constrainedTp) and - tm.resolveTypeAt(pathToTp) = tp and - constraint = resolveTypeMentionRoot(tm) - ) + constraint = getATypeParameterConstraint(constrainedTp, TypePath::nil()) ) }