@@ -7,6 +7,7 @@ private import codeql.rust.internal.CachedStages
77private import codeql.rust.elements.internal.generated.Raw
88private import codeql.rust.elements.internal.generated.Synth
99private import codeql.rust.frameworks.stdlib.Stdlib
10+ private import codeql.rust.frameworks.stdlib.Builtins as Builtins
1011
1112/**
1213 * Holds if a dyn trait type should have a type parameter associated with `n`. A
@@ -44,24 +45,20 @@ newtype TType =
4445 TEnum ( Enum e ) or
4546 TTrait ( Trait t ) or
4647 TUnion ( Union u ) or
47- TArrayType ( ) or // todo: add size?
4848 TRefType ( ) or // todo: add mut?
4949 TImplTraitType ( ImplTraitTypeRepr impl ) or
5050 TDynTraitType ( Trait t ) { t = any ( DynTraitTypeRepr dt ) .getTrait ( ) } or
51- TSliceType ( ) or
5251 TNeverType ( ) or
5352 TPtrType ( ) or
5453 TTupleTypeParameter ( int arity , int i ) { exists ( TTuple ( arity ) ) and i in [ 0 .. arity - 1 ] } or
5554 TTypeParamTypeParameter ( TypeParam t ) or
5655 TAssociatedTypeTypeParameter ( TypeAlias t ) { any ( TraitItemNode trait ) .getAnAssocItem ( ) = t } or
57- TArrayTypeParameter ( ) or
5856 TDynTraitTypeParameter ( AstNode n ) { dynTraitTypeParameter ( _, n ) } or
5957 TImplTraitTypeParameter ( ImplTraitTypeRepr implTrait , TypeParam tp ) {
6058 implTraitTypeParam ( implTrait , _, tp )
6159 } or
6260 TRefTypeParameter ( ) or
6361 TSelfTypeParameter ( Trait t ) or
64- TSliceTypeParameter ( ) or
6562 TPtrTypeParameter ( )
6663
6764private predicate implTraitTypeParam ( ImplTraitTypeRepr implTrait , int i , TypeParam tp ) {
@@ -228,17 +225,10 @@ class UnionType extends Type, TUnion {
228225 * Array types like `[i64; 5]` are modeled as normal generic types
229226 * with a single type argument.
230227 */
231- class ArrayType extends Type , TArrayType {
232- ArrayType ( ) { this = TArrayType ( ) }
228+ class ArrayType extends StructType {
229+ ArrayType ( ) { this . getStruct ( ) instanceof Builtins :: ArrayType }
233230
234- override TypeParameter getPositionalTypeParameter ( int i ) {
235- result = TArrayTypeParameter ( ) and
236- i = 0
237- }
238-
239- override string toString ( ) { result = "[]" }
240-
241- override Location getLocation ( ) { result instanceof EmptyLocation }
231+ override string toString ( ) { result = "[;]" }
242232}
243233
244234/**
@@ -339,17 +329,10 @@ class ImplTraitReturnType extends ImplTraitType {
339329 * Slice types like `[i64]` are modeled as normal generic types
340330 * with a single type argument.
341331 */
342- class SliceType extends Type , TSliceType {
343- SliceType ( ) { this = TSliceType ( ) }
344-
345- override TypeParameter getPositionalTypeParameter ( int i ) {
346- result = TSliceTypeParameter ( ) and
347- i = 0
348- }
332+ class SliceType extends StructType {
333+ SliceType ( ) { this .getStruct ( ) instanceof Builtins:: SliceType }
349334
350335 override string toString ( ) { result = "[]" }
351-
352- override Location getLocation ( ) { result instanceof EmptyLocation }
353336}
354337
355338class NeverType extends Type , TNeverType {
@@ -392,7 +375,14 @@ class TypeParamTypeParameter extends TypeParameter, TTypeParamTypeParameter {
392375
393376 TypeParam getTypeParam ( ) { result = typeParam }
394377
395- override string toString ( ) { result = typeParam .toString ( ) }
378+ override string toString ( ) {
379+ if this = any ( ArrayType at ) .getATypeParameter ( )
380+ then result = "[T;...]"
381+ else
382+ if this = any ( SliceType st ) .getATypeParameter ( )
383+ then result = "[T]"
384+ else result = typeParam .toString ( )
385+ }
396386
397387 override Location getLocation ( ) { result = typeParam .getLocation ( ) }
398388}
@@ -454,13 +444,6 @@ class TupleTypeParameter extends TypeParameter, TTupleTypeParameter {
454444 TupleType getTupleType ( ) { result = TTuple ( arity ) }
455445}
456446
457- /** An implicit array type parameter. */
458- class ArrayTypeParameter extends TypeParameter , TArrayTypeParameter {
459- override string toString ( ) { result = "[T;...]" }
460-
461- override Location getLocation ( ) { result instanceof EmptyLocation }
462- }
463-
464447class DynTraitTypeParameter extends TypeParameter , TDynTraitTypeParameter {
465448 private AstNode n ;
466449
@@ -515,13 +498,6 @@ class RefTypeParameter extends TypeParameter, TRefTypeParameter {
515498 override Location getLocation ( ) { result instanceof EmptyLocation }
516499}
517500
518- /** An implicit slice type parameter. */
519- class SliceTypeParameter extends TypeParameter , TSliceTypeParameter {
520- override string toString ( ) { result = "[T]" }
521-
522- override Location getLocation ( ) { result instanceof EmptyLocation }
523- }
524-
525501class PtrTypeParameter extends TypeParameter , TPtrTypeParameter {
526502 override string toString ( ) { result = "*T" }
527503
0 commit comments