From e41b4f40224391279af17c18f6162d7a534c136c Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Tue, 10 Jun 2025 15:45:34 +0200 Subject: [PATCH] Rust: Use `get(An){Arg,Param}` helper predicates --- rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll | 2 +- .../codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll | 4 ++-- rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll | 2 +- rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll | 4 ++-- rust/ql/lib/codeql/rust/internal/Type.qll | 2 +- rust/ql/lib/codeql/rust/internal/TypeInference.qll | 4 ++-- rust/ql/src/utils/modelgenerator/internal/CaptureModels.qll | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll b/rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll index e32028885110..dc08c0d32a78 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll @@ -59,7 +59,7 @@ class BreakExprTargetChildMapping extends ParentAstNode, Expr { } class CallExprBaseChildMapping extends ParentAstNode, CallExprBase { - override predicate relevantChild(AstNode child) { child = this.getArgList().getAnArg() } + override predicate relevantChild(AstNode child) { child = this.getAnArg() } } class StructExprChildMapping extends ParentAstNode, StructExpr { diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll index 522eaf59fe6d..58cb9f6a95f1 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll @@ -87,7 +87,7 @@ class CallableScopeTree extends StandardTree, PreOrderTree, PostOrderTree, Scope i = 0 and result = this.getParamList().getSelfParam() or - result = this.getParamList().getParam(i - 1) + result = this.getParam(i - 1) or i = this.getParamList().getNumberOfParams() + 1 and result = this.getBody() @@ -543,7 +543,7 @@ module ExprTrees { class MethodCallExprTree extends StandardPostOrderTree, MethodCallExpr { override AstNode getChildNode(int i) { - if i = 0 then result = this.getReceiver() else result = this.getArgList().getArg(i - 1) + if i = 0 then result = this.getReceiver() else result = this.getArg(i - 1) } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll index e9ec4339d1ac..e5262014ab49 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll @@ -55,7 +55,7 @@ module Impl { pragma[nomagic] private PathResolution::ItemNode getResolvedFunctionAndPos(int pos) { result = getResolvedFunction(this) and - exists(this.getArgList().getArg(pos)) + exists(this.getArg(pos)) } /** diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll index 790186bf2c9f..b645092a016a 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll @@ -95,9 +95,9 @@ module Impl { not text.charAt(0).isUppercase() and // exclude parameters from functions without a body as these are trait method declarations // without implementations - not exists(Function f | not f.hasBody() and f.getParamList().getAParam().getPat() = pat) and + not exists(Function f | not f.hasBody() and f.getAParam().getPat() = pat) and // exclude parameters from function pointer types (e.g. `x` in `fn(x: i32) -> i32`) - not exists(FnPtrTypeRepr fp | fp.getParamList().getParam(_).getPat() = pat) + not exists(FnPtrTypeRepr fp | fp.getParamList().getAParam().getPat() = pat) ) } diff --git a/rust/ql/lib/codeql/rust/internal/Type.qll b/rust/ql/lib/codeql/rust/internal/Type.qll index a751fd0d1a0e..a88bc8e344f4 100644 --- a/rust/ql/lib/codeql/rust/internal/Type.qll +++ b/rust/ql/lib/codeql/rust/internal/Type.qll @@ -352,7 +352,7 @@ class SelfTypeParameter extends TypeParameter, TSelfTypeParameter { class ImplTraitTypeTypeParameter extends ImplTraitType, TypeParameter { private Function function; - ImplTraitTypeTypeParameter() { impl = function.getParamList().getAParam().getTypeRepr() } + ImplTraitTypeTypeParameter() { impl = function.getAParam().getTypeRepr() } override Function getFunction() { result = function } diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index 5ff98b9131f2..9d775760fa34 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -1100,7 +1100,7 @@ private module AwaitExprMatchingInput implements MatchingInputSig { Type getDeclaredType(DeclarationPosition dpos, TypePath path) { dpos.isSelf() and - result = this.getParamList().getParam(0).getTypeRepr().(TypeMention).resolveTypeAt(path) + result = this.getParam(0).getTypeRepr().(TypeMention).resolveTypeAt(path) or dpos.isOutput() and result = this.getRetType().getTypeRepr().(TypeMention).resolveTypeAt(path) @@ -1199,7 +1199,7 @@ private module MethodCall { Expr receiver; CallExprMethodCall() { - receiver = this.getArgList().getArg(0) and + receiver = this.getArg(0) and exists(Path path, Function f | path = this.getFunction().(PathExpr).getPath() and f = resolvePath(path) and diff --git a/rust/ql/src/utils/modelgenerator/internal/CaptureModels.qll b/rust/ql/src/utils/modelgenerator/internal/CaptureModels.qll index 58f90cc33a0d..d30157b5090d 100644 --- a/rust/ql/src/utils/modelgenerator/internal/CaptureModels.qll +++ b/rust/ql/src/utils/modelgenerator/internal/CaptureModels.qll @@ -79,7 +79,7 @@ module ModelGeneratorCommonInput implements bindingset[c] string paramReturnNodeAsExactOutput(Callable c, DataFlowImpl::ParameterPosition pos) { - result = parameterExactAccess(c.getParamList().getParam(pos.getPosition())) + result = parameterExactAccess(c.getParam(pos.getPosition())) or pos.isSelf() and result = qualifierString() }