From a396f9345eb6a5344bfa5fbc8093129b6a4ee1da Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Tue, 5 Aug 2025 15:05:43 +0200 Subject: [PATCH] Rust: Remove restriction in `PathTypeMention` --- rust/ql/lib/codeql/rust/internal/Type.qll | 2 +- .../lib/codeql/rust/internal/TypeMention.qll | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/Type.qll b/rust/ql/lib/codeql/rust/internal/Type.qll index 1c3262c3e89f..275776741a37 100644 --- a/rust/ql/lib/codeql/rust/internal/Type.qll +++ b/rust/ql/lib/codeql/rust/internal/Type.qll @@ -59,7 +59,7 @@ newtype TType = TSelfTypeParameter(Trait t) or TSliceTypeParameter() -predicate implTraitTypeParam(ImplTraitTypeRepr implTrait, int i, TypeParam tp) { +private predicate implTraitTypeParam(ImplTraitTypeRepr implTrait, int i, TypeParam tp) { implTrait.isInReturnPos() and tp = implTrait.getFunction().getGenericParamList().getTypeParam(i) and // Only include type parameters of the function that occur inside the impl diff --git a/rust/ql/lib/codeql/rust/internal/TypeMention.qll b/rust/ql/lib/codeql/rust/internal/TypeMention.qll index b2d2f5842077..f7c5f2f25e0e 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeMention.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeMention.qll @@ -75,21 +75,7 @@ class SliceTypeReprMention extends TypeMention instanceof SliceTypeRepr { } } -/** Holds if `path` is used as a type mention during type inference. */ -predicate relevantPathTypeMention(Path path) { - path = - [ - any(PathTypeRepr r).getPath(), - any(StructExpr s).getPath().getQualifier*(), - any(CallExpr ce).getFunction().(PathExpr).getPath().getQualifier*(), - any(StructPat p).getPath(), - any(TupleStructPat p).getPath() - ] -} - -abstract class PathTypeMention extends TypeMention, Path { - PathTypeMention() { relevantPathTypeMention(this) } -} +abstract class PathTypeMention extends TypeMention, Path { } class AliasPathTypeMention extends PathTypeMention { TypeAlias resolved; @@ -241,7 +227,8 @@ class NonAliasPathTypeMention extends PathTypeMention { ) } - Type resolveRootType() { + pragma[nomagic] + private Type resolveRootType() { result = TStruct(resolved) or result = TEnum(resolved)