@@ -27,10 +27,6 @@ newtype TType =
27
27
* types, such as traits and implementation blocks.
28
28
*/
29
29
abstract class Type extends TType {
30
- /** Gets the method `name` belonging to this type, if any. */
31
- pragma [ nomagic]
32
- abstract Function getMethod ( string name ) ;
33
-
34
30
/** Gets the struct field `name` belonging to this type, if any. */
35
31
pragma [ nomagic]
36
32
abstract StructField getStructField ( string name ) ;
@@ -45,25 +41,6 @@ abstract class Type extends TType {
45
41
/** Gets a type parameter of this type. */
46
42
final TypeParameter getATypeParameter ( ) { result = this .getTypeParameter ( _) }
47
43
48
- /**
49
- * Gets an AST node that mentions a base type of this type, if any.
50
- *
51
- * Although Rust doesn't have traditional OOP-style inheritance, we model trait
52
- * bounds and `impl` blocks as base types. Example:
53
- *
54
- * ```rust
55
- * trait T1 {}
56
- *
57
- * trait T2 {}
58
- *
59
- * trait T3 : T1, T2 {}
60
- * // ^^ `this`
61
- * // ^^ `result`
62
- * // ^^ `result`
63
- * ```
64
- */
65
- abstract TypeMention getABaseTypeMention ( ) ;
66
-
67
44
/** Gets a textual representation of this type. */
68
45
abstract string toString ( ) ;
69
46
@@ -73,21 +50,6 @@ abstract class Type extends TType {
73
50
74
51
abstract private class StructOrEnumType extends Type {
75
52
abstract ItemNode asItemNode ( ) ;
76
-
77
- final override Function getMethod ( string name ) {
78
- result = this .asItemNode ( ) .getASuccessor ( name ) and
79
- exists ( ImplOrTraitItemNode impl | result = impl .getAnAssocItem ( ) |
80
- impl instanceof Trait
81
- or
82
- impl .( ImplItemNode ) .isFullyParametric ( )
83
- )
84
- }
85
-
86
- /** Gets all of the fully parametric `impl` blocks that target this type. */
87
- final override ImplMention getABaseTypeMention ( ) {
88
- this .asItemNode ( ) = result .resolveSelfTy ( ) and
89
- result .isFullyParametric ( )
90
- }
91
53
}
92
54
93
55
/** A struct type. */
@@ -138,8 +100,6 @@ class TraitType extends Type, TTrait {
138
100
139
101
TraitType ( ) { this = TTrait ( trait ) }
140
102
141
- override Function getMethod ( string name ) { result = trait .( ItemNode ) .getASuccessor ( name ) }
142
-
143
103
override StructField getStructField ( string name ) { none ( ) }
144
104
145
105
override TupleField getTupleField ( int i ) { none ( ) }
@@ -151,14 +111,6 @@ class TraitType extends Type, TTrait {
151
111
any ( AssociatedTypeTypeParameter param | param .getTrait ( ) = trait and param .getIndex ( ) = i )
152
112
}
153
113
154
- pragma [ nomagic]
155
- private TypeReprMention getABoundMention ( ) {
156
- result = trait .getTypeBoundList ( ) .getABound ( ) .getTypeRepr ( )
157
- }
158
-
159
- /** Gets any of the trait bounds of this trait. */
160
- override TypeMention getABaseTypeMention ( ) { result = this .getABoundMention ( ) }
161
-
162
114
override string toString ( ) { result = trait .toString ( ) }
163
115
164
116
override Location getLocation ( ) { result = trait .getLocation ( ) }
@@ -220,8 +172,6 @@ class ImplType extends Type, TImpl {
220
172
221
173
ImplType ( ) { this = TImpl ( impl ) }
222
174
223
- override Function getMethod ( string name ) { result = impl .( ItemNode ) .getASuccessor ( name ) }
224
-
225
175
override StructField getStructField ( string name ) { none ( ) }
226
176
227
177
override TupleField getTupleField ( int i ) { none ( ) }
@@ -230,9 +180,6 @@ class ImplType extends Type, TImpl {
230
180
result = TTypeParamTypeParameter ( impl .getGenericParamList ( ) .getTypeParam ( i ) )
231
181
}
232
182
233
- /** Get the trait implemented by this `impl` block, if any. */
234
- override TypeMention getABaseTypeMention ( ) { result = impl .getTrait ( ) }
235
-
236
183
override string toString ( ) { result = impl .toString ( ) }
237
184
238
185
override Location getLocation ( ) { result = impl .getLocation ( ) }
@@ -247,8 +194,6 @@ class ImplType extends Type, TImpl {
247
194
class ArrayType extends Type , TArrayType {
248
195
ArrayType ( ) { this = TArrayType ( ) }
249
196
250
- override Function getMethod ( string name ) { none ( ) }
251
-
252
197
override StructField getStructField ( string name ) { none ( ) }
253
198
254
199
override TupleField getTupleField ( int i ) { none ( ) }
@@ -257,8 +202,6 @@ class ArrayType extends Type, TArrayType {
257
202
none ( ) // todo
258
203
}
259
204
260
- override TypeMention getABaseTypeMention ( ) { none ( ) }
261
-
262
205
override string toString ( ) { result = "[]" }
263
206
264
207
override Location getLocation ( ) { result instanceof EmptyLocation }
@@ -273,8 +216,6 @@ class ArrayType extends Type, TArrayType {
273
216
class RefType extends Type , TRefType {
274
217
RefType ( ) { this = TRefType ( ) }
275
218
276
- override Function getMethod ( string name ) { none ( ) }
277
-
278
219
override StructField getStructField ( string name ) { none ( ) }
279
220
280
221
override TupleField getTupleField ( int i ) { none ( ) }
@@ -284,17 +225,13 @@ class RefType extends Type, TRefType {
284
225
i = 0
285
226
}
286
227
287
- override TypeMention getABaseTypeMention ( ) { none ( ) }
288
-
289
228
override string toString ( ) { result = "&" }
290
229
291
230
override Location getLocation ( ) { result instanceof EmptyLocation }
292
231
}
293
232
294
233
/** A type parameter. */
295
234
abstract class TypeParameter extends Type {
296
- override TypeMention getABaseTypeMention ( ) { none ( ) }
297
-
298
235
override StructField getStructField ( string name ) { none ( ) }
299
236
300
237
override TupleField getTupleField ( int i ) { none ( ) }
@@ -318,19 +255,9 @@ class TypeParamTypeParameter extends TypeParameter, TTypeParamTypeParameter {
318
255
319
256
TypeParam getTypeParam ( ) { result = typeParam }
320
257
321
- override Function getMethod ( string name ) {
322
- // NOTE: If the type parameter has trait bounds, then this finds methods
323
- // on the bounding traits.
324
- result = typeParam .( ItemNode ) .getASuccessor ( name )
325
- }
326
-
327
258
override string toString ( ) { result = typeParam .toString ( ) }
328
259
329
260
override Location getLocation ( ) { result = typeParam .getLocation ( ) }
330
-
331
- final override TypeMention getABaseTypeMention ( ) {
332
- result = typeParam .getTypeBoundList ( ) .getABound ( ) .getTypeRepr ( )
333
- }
334
261
}
335
262
336
263
/**
@@ -377,19 +304,13 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
377
304
378
305
int getIndex ( ) { traitAliasIndex ( _, result , typeAlias ) }
379
306
380
- override Function getMethod ( string name ) { none ( ) }
381
-
382
307
override string toString ( ) { result = typeAlias .getName ( ) .getText ( ) }
383
308
384
309
override Location getLocation ( ) { result = typeAlias .getLocation ( ) }
385
-
386
- override TypeMention getABaseTypeMention ( ) { none ( ) }
387
310
}
388
311
389
312
/** An implicit reference type parameter. */
390
313
class RefTypeParameter extends TypeParameter , TRefTypeParameter {
391
- override Function getMethod ( string name ) { none ( ) }
392
-
393
314
override string toString ( ) { result = "&T" }
394
315
395
316
override Location getLocation ( ) { result instanceof EmptyLocation }
@@ -409,15 +330,34 @@ class SelfTypeParameter extends TypeParameter, TSelfTypeParameter {
409
330
410
331
Trait getTrait ( ) { result = trait }
411
332
412
- override TypeMention getABaseTypeMention ( ) { result = trait }
333
+ override string toString ( ) { result = "Self [" + trait .toString ( ) + "]" }
334
+
335
+ override Location getLocation ( ) { result = trait .getLocation ( ) }
336
+ }
337
+
338
+ /** A type abstraction. */
339
+ abstract class TypeAbstraction extends AstNode {
340
+ abstract TypeParameter getATypeParameter ( ) ;
341
+ }
413
342
414
- override Function getMethod ( string name ) {
415
- // The `Self` type parameter is an implementation of the trait, so it has
416
- // all the trait's methods.
417
- result = trait .( ItemNode ) .getASuccessor ( name )
343
+ final class ImplTypeAbstraction extends TypeAbstraction , Impl {
344
+ override TypeParamTypeParameter getATypeParameter ( ) {
345
+ result .getTypeParam ( ) = this .getGenericParamList ( ) .getATypeParam ( )
418
346
}
347
+ }
419
348
420
- override string toString ( ) { result = "Self [" + trait .toString ( ) + "]" }
349
+ final class TraitTypeAbstraction extends TypeAbstraction , Trait {
350
+ override TypeParamTypeParameter getATypeParameter ( ) {
351
+ result .getTypeParam ( ) = this .getGenericParamList ( ) .getATypeParam ( )
352
+ }
353
+ }
421
354
422
- override Location getLocation ( ) { result = trait .getLocation ( ) }
355
+ final class TypeBoundTypeAbstraction extends TypeAbstraction , TypeBound {
356
+ override TypeParamTypeParameter getATypeParameter ( ) { none ( ) }
357
+ }
358
+
359
+ final class SelfTypeBoundTypeAbstraction extends TypeAbstraction , Name {
360
+ SelfTypeBoundTypeAbstraction ( ) { any ( Trait trait ) .getName ( ) = this }
361
+
362
+ override TypeParamTypeParameter getATypeParameter ( ) { none ( ) }
423
363
}
0 commit comments