From e0e493a9e394db76df291de54c6ad7761ac06e0d Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Fri, 19 Dec 2025 13:53:38 +0100 Subject: [PATCH] Rust: Address review comments --- rust/ql/lib/codeql/rust/internal/Type.qll | 18 ++++++++++++------ .../lib/codeql/rust/internal/TypeInference.qll | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/Type.qll b/rust/ql/lib/codeql/rust/internal/Type.qll index 50dd99fb73a..9b409e20f76 100644 --- a/rust/ql/lib/codeql/rust/internal/Type.qll +++ b/rust/ql/lib/codeql/rust/internal/Type.qll @@ -133,26 +133,32 @@ class DataType extends Type, TDataType { /** A struct type. */ class StructType extends DataType { - StructType() { super.getTypeItem() instanceof Struct } + private Struct struct; + + StructType() { struct = super.getTypeItem() } /** Gets the struct that this struct type represents. */ - override Struct getTypeItem() { result = super.getTypeItem() } + override Struct getTypeItem() { result = struct } } /** An enum type. */ class EnumType extends DataType { - EnumType() { super.getTypeItem() instanceof Enum } + private Enum enum; + + EnumType() { enum = super.getTypeItem() } /** Gets the enum that this enum type represents. */ - override Enum getTypeItem() { result = super.getTypeItem() } + override Enum getTypeItem() { result = enum } } /** A union type. */ class UnionType extends DataType { - UnionType() { super.getTypeItem() instanceof Union } + private Union union; + + UnionType() { union = super.getTypeItem() } /** Gets the union that this union type represents. */ - override Union getTypeItem() { result = super.getTypeItem() } + override Union getTypeItem() { result = union } } /** A trait type. */ diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index b05e2921d3e..c994cab6bb2 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -907,7 +907,7 @@ private module StructExprMatchingInput implements MatchingInputSig { result = this.getTypeParameter(_) and path = TypePath::singleton(result) or - // type of the struct itself + // type of the struct or enum itself dpos.isStructPos() and path.isEmpty() and result = TDataType(this.getTypeItem()) @@ -2860,7 +2860,7 @@ private class TupleLikeStruct extends TupleLikeConstructor instanceof Struct { override TypeItem getTypeItem() { result = this } - override TupleField getTupleField(int i) { result = this.(Struct).getTupleField(i) } + override TupleField getTupleField(int i) { result = Struct.super.getTupleField(i) } } private class TupleLikeVariant extends TupleLikeConstructor instanceof Variant { @@ -2868,7 +2868,7 @@ private class TupleLikeVariant extends TupleLikeConstructor instanceof Variant { override TypeItem getTypeItem() { result = super.getEnum() } - override TupleField getTupleField(int i) { result = this.(Variant).getTupleField(i) } + override TupleField getTupleField(int i) { result = Variant.super.getTupleField(i) } } /**