Skip to content

Commit e0e493a

Browse files
committed
Rust: Address review comments
1 parent dde845e commit e0e493a

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

rust/ql/lib/codeql/rust/internal/Type.qll

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,32 @@ class DataType extends Type, TDataType {
133133

134134
/** A struct type. */
135135
class StructType extends DataType {
136-
StructType() { super.getTypeItem() instanceof Struct }
136+
private Struct struct;
137+
138+
StructType() { struct = super.getTypeItem() }
137139

138140
/** Gets the struct that this struct type represents. */
139-
override Struct getTypeItem() { result = super.getTypeItem() }
141+
override Struct getTypeItem() { result = struct }
140142
}
141143

142144
/** An enum type. */
143145
class EnumType extends DataType {
144-
EnumType() { super.getTypeItem() instanceof Enum }
146+
private Enum enum;
147+
148+
EnumType() { enum = super.getTypeItem() }
145149

146150
/** Gets the enum that this enum type represents. */
147-
override Enum getTypeItem() { result = super.getTypeItem() }
151+
override Enum getTypeItem() { result = enum }
148152
}
149153

150154
/** A union type. */
151155
class UnionType extends DataType {
152-
UnionType() { super.getTypeItem() instanceof Union }
156+
private Union union;
157+
158+
UnionType() { union = super.getTypeItem() }
153159

154160
/** Gets the union that this union type represents. */
155-
override Union getTypeItem() { result = super.getTypeItem() }
161+
override Union getTypeItem() { result = union }
156162
}
157163

158164
/** A trait type. */

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
907907
result = this.getTypeParameter(_) and
908908
path = TypePath::singleton(result)
909909
or
910-
// type of the struct itself
910+
// type of the struct or enum itself
911911
dpos.isStructPos() and
912912
path.isEmpty() and
913913
result = TDataType(this.getTypeItem())
@@ -2860,15 +2860,15 @@ private class TupleLikeStruct extends TupleLikeConstructor instanceof Struct {
28602860

28612861
override TypeItem getTypeItem() { result = this }
28622862

2863-
override TupleField getTupleField(int i) { result = this.(Struct).getTupleField(i) }
2863+
override TupleField getTupleField(int i) { result = Struct.super.getTupleField(i) }
28642864
}
28652865

28662866
private class TupleLikeVariant extends TupleLikeConstructor instanceof Variant {
28672867
TupleLikeVariant() { this.isTuple() }
28682868

28692869
override TypeItem getTypeItem() { result = super.getEnum() }
28702870

2871-
override TupleField getTupleField(int i) { result = this.(Variant).getTupleField(i) }
2871+
override TupleField getTupleField(int i) { result = Variant.super.getTupleField(i) }
28722872
}
28732873

28742874
/**

0 commit comments

Comments
 (0)