@@ -32,10 +32,8 @@ private predicate dynTraitTypeParameter(Trait trait, AstNode n) {
3232
3333cached
3434newtype TType =
35- TStruct ( Struct s ) { Stages:: TypeInferenceStage:: ref ( ) } or
36- TEnum ( Enum e ) or
35+ TDataType ( TypeItem ti ) { Stages:: TypeInferenceStage:: ref ( ) } or
3736TTrait ( Trait t ) or
38- TUnion ( Union u ) or
3937TImplTraitType ( ImplTraitTypeRepr impl ) or
4038TDynTraitType ( Trait t ) { t = any ( DynTraitTypeRepr dt ) .getTrait ( ) } or
4139TNeverType ( ) or
@@ -92,7 +90,7 @@ abstract class Type extends TType {
9290class TupleType extends StructType {
9391private int arity ;
9492
95- TupleType ( ) { arity = this .getStruct ( ) .( Builtins:: TupleType ) .getArity ( ) }
93+ TupleType ( ) { arity = this .getTypeItem ( ) .( Builtins:: TupleType ) .getArity ( ) }
9694
9795/** Gets the arity of this tuple type. */
9896int getArity ( ) { result = arity }
@@ -112,48 +110,49 @@ class UnitType extends TupleType {
112110override string toString ( ) { result = "()" }
113111}
114112
115- /** A struct type. */
116- class StructType extends Type , TStruct {
117- private Struct struct ;
113+ class DataType extends Type , TDataType {
114+ private TypeItem typeItem ;
118115
119- StructType ( ) { this = TStruct ( struct ) }
116+ DataType ( ) { this = TDataType ( typeItem ) }
120117
121- /** Gets thestruct that thisstruct type represents. */
122- Struct getStruct ( ) { result = struct }
118+ /** Gets thetype item that thisdata type represents. */
119+ TypeItem getTypeItem ( ) { result = typeItem }
123120
124121override TypeParameter getPositionalTypeParameter ( int i ) {
125- result = TTypeParamTypeParameter ( struct .getGenericParamList ( ) .getTypeParam ( i ) )
122+ result = TTypeParamTypeParameter ( typeItem .getGenericParamList ( ) .getTypeParam ( i ) )
126123}
127124
128125override TypeMention getTypeParameterDefault ( int i ) {
129- result = struct .getGenericParamList ( ) .getTypeParam ( i ) .getDefaultType ( )
126+ result = typeItem .getGenericParamList ( ) .getTypeParam ( i ) .getDefaultType ( )
130127}
131128
132- override string toString ( ) { result = struct .getName ( ) .getText ( ) }
129+ override string toString ( ) { result = typeItem .getName ( ) .getText ( ) }
133130
134- override Location getLocation ( ) { result = struct .getLocation ( ) }
131+ override Location getLocation ( ) { result = typeItem .getLocation ( ) }
135132}
136133
137- /** An enum type. */
138- class EnumType extends Type , TEnum {
139- private Enum enum ;
140-
141- EnumType ( ) { this = TEnum ( enum ) }
134+ /** A struct type. */
135+ class StructType extends DataType {
136+ StructType ( ) { super .getTypeItem ( ) instanceof Struct }
142137
143- /** Gets the enum that this enum type represents. */
144- Enum getEnum ( ) { result = enum }
138+ /** Gets the struct that this struct type represents. */
139+ override Struct getTypeItem ( ) { result = super .getTypeItem ( ) }
140+ }
145141
146- override TypeParameter getPositionalTypeParameter ( int i ) {
147- result = TTypeParamTypeParameter ( enum . getGenericParamList ( ) . getTypeParam ( i ) )
148- }
142+ /** An enum type. */
143+ class EnumType extends DataType {
144+ EnumType ( ) { super . getTypeItem ( ) instanceof Enum }
149145
150- override TypeMention getTypeParameterDefault ( int i ) {
151- result = enum . getGenericParamList ( ) . getTypeParam ( i ) . getDefaultType ( )
152- }
146+ /** Gets the enum that this enum type represents. */
147+ override Enum getTypeItem ( ) { result = super . getTypeItem ( ) }
148+ }
153149
154- override string toString ( ) { result = enum .getName ( ) .getText ( ) }
150+ /** A union type. */
151+ class UnionType extends DataType {
152+ UnionType ( ) { super .getTypeItem ( ) instanceof Union }
155153
156- override Location getLocation ( ) { result = enum .getLocation ( ) }
154+ /** Gets the union that this union type represents. */
155+ override Union getTypeItem ( ) { result = super .getTypeItem ( ) }
157156}
158157
159158/** A trait type. */
@@ -186,35 +185,13 @@ class TraitType extends Type, TTrait {
186185override Location getLocation ( ) { result = trait .getLocation ( ) }
187186}
188187
189- /** A union type. */
190- class UnionType extends Type , TUnion {
191- private Union union ;
192-
193- UnionType ( ) { this = TUnion ( union ) }
194-
195- /** Gets the union that this union type represents. */
196- Union getUnion ( ) { result = union }
197-
198- override TypeParameter getPositionalTypeParameter ( int i ) {
199- result = TTypeParamTypeParameter ( union .getGenericParamList ( ) .getTypeParam ( i ) )
200- }
201-
202- override TypeMention getTypeParameterDefault ( int i ) {
203- result = union .getGenericParamList ( ) .getTypeParam ( i ) .getDefaultType ( )
204- }
205-
206- override string toString ( ) { result = union .getName ( ) .getText ( ) }
207-
208- override Location getLocation ( ) { result = union .getLocation ( ) }
209- }
210-
211188/**
212189 * An array type.
213190 *
214191 * Array types like `[i64; 5]` are modeled as normal generic types.
215192 */
216193class ArrayType extends StructType {
217- ArrayType ( ) { this .getStruct ( ) instanceof Builtins:: ArrayType }
194+ ArrayType ( ) { this .getTypeItem ( ) instanceof Builtins:: ArrayType }
218195
219196override string toString ( ) { result = "[;]" }
220197}
@@ -227,13 +204,13 @@ TypeParamTypeParameter getArrayTypeParameter() {
227204abstract class RefType extends StructType { }
228205
229206class RefMutType extends RefType {
230- RefMutType ( ) { this .getStruct ( ) instanceof Builtins:: RefMutType }
207+ RefMutType ( ) { this .getTypeItem ( ) instanceof Builtins:: RefMutType }
231208
232209override string toString ( ) { result = "&mut" }
233210}
234211
235212class RefSharedType extends RefType {
236- RefSharedType ( ) { this .getStruct ( ) instanceof Builtins:: RefSharedType }
213+ RefSharedType ( ) { this .getTypeItem ( ) instanceof Builtins:: RefSharedType }
237214
238215override string toString ( ) { result = "&" }
239216}
@@ -330,7 +307,7 @@ class ImplTraitReturnType extends ImplTraitType {
330307 * with a single type argument.
331308 */
332309class SliceType extends StructType {
333- SliceType ( ) { this .getStruct ( ) instanceof Builtins:: SliceType }
310+ SliceType ( ) { this .getTypeItem ( ) instanceof Builtins:: SliceType }
334311
335312override string toString ( ) { result = "[]" }
336313}
@@ -356,13 +333,13 @@ TypeParamTypeParameter getPtrTypeParameter() {
356333}
357334
358335class PtrMutType extends PtrType {
359- PtrMutType ( ) { this .getStruct ( ) instanceof Builtins:: PtrMutType }
336+ PtrMutType ( ) { this .getTypeItem ( ) instanceof Builtins:: PtrMutType }
360337
361338override string toString ( ) { result = "*mut" }
362339}
363340
364341class PtrConstType extends PtrType {
365- PtrConstType ( ) { this .getStruct ( ) instanceof Builtins:: PtrConstType }
342+ PtrConstType ( ) { this .getTypeItem ( ) instanceof Builtins:: PtrConstType }
366343
367344override string toString ( ) { result = "*const" }
368345}
@@ -624,7 +601,7 @@ pragma[nomagic]
624601predicate validSelfType ( Type t ) {
625602t instanceof RefType
626603or
627- exists ( Struct s | t = TStruct ( s ) |
604+ exists ( Struct s | t = TDataType ( s ) |
628605s instanceof BoxStruct or
629606s instanceof RcStruct or
630607s instanceof ArcStruct or