Skip to content

Commit e8e46ac

Browse files
committed
Rust: Refine AssociatedTypeTypeParameter.toString
1 parent 06f0c11 commit e8e46ac

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,11 @@ class TypeParamTypeParameter extends TypeParameter, TTypeParamTypeParameter {
439439
*/
440440
class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypeParameter {
441441
private Trait trait;
442-
private TypeAlias typeAlias;
442+
private AssocType typeAlias;
443443

444444
AssociatedTypeTypeParameter() { this = TAssociatedTypeTypeParameter(trait, typeAlias) }
445445

446-
TypeAlias getTypeAlias() { result = typeAlias }
446+
AssocType getTypeAlias() { result = typeAlias }
447447

448448
/** Gets the trait that contains this associated type declaration. */
449449
TraitItemNode getTrait() { result = trait }
@@ -457,7 +457,13 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
457457
override ItemNode getDeclaringItem() { result = trait }
458458

459459
override string toString() {
460-
result = typeAlias.getName().getText() + "[" + trait.getName().toString() + "]"
460+
exists(string fromString, TraitItemNode trait2 |
461+
result = typeAlias.getName().getText() + "[" + trait.getName() + fromString + "]" and
462+
trait2 = typeAlias.getTrait() and
463+
if trait = trait2
464+
then fromString = ""
465+
else fromString = " (inherited from " + trait2.getName() + ")"
466+
)
461467
}
462468

463469
override Location getLocation() { result = typeAlias.getLocation() }

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ inferCertainType
209209
| associated_types.rs:454:24:454:28 | SelfParam | TRef | associated_types.rs:452:5:455:5 | Self [trait Subtrait] |
210210
| associated_types.rs:463:23:463:27 | SelfParam | | {EXTERNAL LOCATION} | & |
211211
| associated_types.rs:463:23:463:27 | SelfParam | TRef | associated_types.rs:457:5:467:5 | Self [trait Subtrait2] |
212-
| associated_types.rs:463:30:463:31 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
213-
| associated_types.rs:463:48:463:49 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
212+
| associated_types.rs:463:30:463:31 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
213+
| associated_types.rs:463:48:463:49 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
214214
| associated_types.rs:463:66:466:9 | { ... } | | {EXTERNAL LOCATION} | () |
215215
| associated_types.rs:464:13:464:16 | self | | {EXTERNAL LOCATION} | & |
216216
| associated_types.rs:464:13:464:16 | self | TRef | associated_types.rs:457:5:467:5 | Self [trait Subtrait2] |
217-
| associated_types.rs:464:22:464:23 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
217+
| associated_types.rs:464:22:464:23 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
218218
| associated_types.rs:465:13:465:16 | self | | {EXTERNAL LOCATION} | & |
219219
| associated_types.rs:465:13:465:16 | self | TRef | associated_types.rs:457:5:467:5 | Self [trait Subtrait2] |
220-
| associated_types.rs:465:22:465:23 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
220+
| associated_types.rs:465:22:465:23 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
221221
| associated_types.rs:474:16:474:20 | SelfParam | | {EXTERNAL LOCATION} | & |
222222
| associated_types.rs:474:16:474:20 | SelfParam | TRef | associated_types.rs:469:5:469:24 | MyType |
223223
| associated_types.rs:474:16:474:20 | SelfParam | TRef.T | associated_types.rs:471:10:471:16 | T |
@@ -5441,17 +5441,17 @@ inferType
54415441
| associated_types.rs:454:24:454:28 | SelfParam | TRef | associated_types.rs:452:5:455:5 | Self [trait Subtrait] |
54425442
| associated_types.rs:463:23:463:27 | SelfParam | | {EXTERNAL LOCATION} | & |
54435443
| associated_types.rs:463:23:463:27 | SelfParam | TRef | associated_types.rs:457:5:467:5 | Self [trait Subtrait2] |
5444-
| associated_types.rs:463:30:463:31 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
5445-
| associated_types.rs:463:48:463:49 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
5444+
| associated_types.rs:463:30:463:31 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
5445+
| associated_types.rs:463:48:463:49 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
54465446
| associated_types.rs:463:66:466:9 | { ... } | | {EXTERNAL LOCATION} | () |
54475447
| associated_types.rs:464:13:464:16 | self | | {EXTERNAL LOCATION} | & |
54485448
| associated_types.rs:464:13:464:16 | self | TRef | associated_types.rs:457:5:467:5 | Self [trait Subtrait2] |
54495449
| associated_types.rs:464:13:464:24 | self.set(...) | | {EXTERNAL LOCATION} | () |
5450-
| associated_types.rs:464:22:464:23 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
5450+
| associated_types.rs:464:22:464:23 | c1 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
54515451
| associated_types.rs:465:13:465:16 | self | | {EXTERNAL LOCATION} | & |
54525452
| associated_types.rs:465:13:465:16 | self | TRef | associated_types.rs:457:5:467:5 | Self [trait Subtrait2] |
54535453
| associated_types.rs:465:13:465:24 | self.set(...) | | {EXTERNAL LOCATION} | () |
5454-
| associated_types.rs:465:22:465:23 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2] |
5454+
| associated_types.rs:465:22:465:23 | c2 | | associated_types.rs:20:5:20:16 | Output[Subtrait2 (inherited from GetSet)] |
54555455
| associated_types.rs:474:16:474:20 | SelfParam | | {EXTERNAL LOCATION} | & |
54565456
| associated_types.rs:474:16:474:20 | SelfParam | TRef | associated_types.rs:469:5:469:24 | MyType |
54575457
| associated_types.rs:474:16:474:20 | SelfParam | TRef.T | associated_types.rs:471:10:471:16 | T |

0 commit comments

Comments
 (0)