From 11bd3343701ab98ab4449e987bca73fba3b0dec5 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Fri, 9 Jan 2026 11:40:16 +0100 Subject: [PATCH] Rust: Use `TypeItem` in path resolution --- .../codeql/rust/internal/PathResolution.qll | 76 +++---------------- 1 file changed, 10 insertions(+), 66 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index e62f11b8e830..e23efc60ee44 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -629,14 +629,14 @@ private class ConstItemNode extends AssocItemNode instanceof Const { override TypeParam getTypeParam(int i) { none() } } -private class EnumItemNode extends TypeItemNode instanceof Enum { - override string getName() { result = Enum.super.getName().getText() } +private class TypeItemTypeItemNode extends TypeItemNode instanceof TypeItem { + override string getName() { result = TypeItem.super.getName().getText() } override Namespace getNamespace() { result.isType() } - override Visibility getVisibility() { result = Enum.super.getVisibility() } + override Visibility getVisibility() { result = TypeItem.super.getVisibility() } - override Attr getAnAttr() { result = Enum.super.getAnAttr() } + override Attr getAnAttr() { result = TypeItem.super.getAnAttr() } override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) } @@ -982,9 +982,8 @@ private class ImplItemNodeImpl extends ImplItemNode { TraitItemNodeImpl resolveTraitTyCand() { result = resolvePathCand(this.getTraitPath()) } } -private class StructItemNode extends TypeItemNode, ParameterizableItemNode instanceof Struct { - override string getName() { result = Struct.super.getName().getText() } - +private class StructItemNode extends TypeItemTypeItemNode, ParameterizableItemNode instanceof Struct +{ override Namespace getNamespace() { result.isType() // the struct itself or @@ -992,40 +991,17 @@ private class StructItemNode extends TypeItemNode, ParameterizableItemNode insta result.isValue() // the constructor } - override Visibility getVisibility() { result = Struct.super.getVisibility() } - - override Attr getAnAttr() { result = Struct.super.getAnAttr() } - override int getArity() { result = super.getFieldList().(TupleFieldList).getNumberOfFields() } - override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) } - - override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) } - - bindingset[c] - private string getCanonicalPathPart(Crate c, int i) { - i = 0 and - result = this.getCanonicalPathPrefix(c) - or - i = 1 and - result = "::" - or - i = 2 and - result = this.getName() - } - language[monotonicAggregates] override string getCanonicalPath(Crate c) { this.hasCanonicalPath(c) and ( - this = - any(Builtins::BuiltinType t | - not t.hasVisibility() and - result = t.getDisplayName() - ) + not super.hasVisibility() and + result = this.(Builtins::BuiltinType).getDisplayName() or - not this = any(Builtins::BuiltinType t | not t.hasVisibility()) and - result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i) + (super.hasVisibility() or not this instanceof Builtins::BuiltinType) and + result = TypeItemTypeItemNode.super.getCanonicalPath(c) ) } } @@ -1122,38 +1098,6 @@ private class TypeAliasItemNodeImpl extends TypeAliasItemNode instanceof TypeAli } } -private class UnionItemNode extends TypeItemNode instanceof Union { - override string getName() { result = Union.super.getName().getText() } - - override Namespace getNamespace() { result.isType() } - - override Visibility getVisibility() { result = Union.super.getVisibility() } - - override Attr getAnAttr() { result = Union.super.getAnAttr() } - - override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) } - - override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) } - - bindingset[c] - private string getCanonicalPathPart(Crate c, int i) { - i = 0 and - result = this.getCanonicalPathPrefix(c) - or - i = 1 and - result = "::" - or - i = 2 and - result = this.getName() - } - - language[monotonicAggregates] - override string getCanonicalPath(Crate c) { - this.hasCanonicalPath(c) and - result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i) - } -} - private class UseItemNode extends ItemNode instanceof Use { override string getName() { result = "(use)" }