Skip to content

Commit 765685c

Browse files
committed
Rust: Improve a few toString implementations
1 parent aa9d299 commit 765685c

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

rust/ql/.generated.list

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/ImplTraitTypeReprImpl.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@ module Impl {
3636
predicate isInReturnPos() {
3737
exists(Function f | f.getRetType().getTypeRepr() = this.getFunctionTypeRepr(f))
3838
}
39+
40+
override string toStringImpl() {
41+
result = "impl " + this.getTypeBoundList().toAbbreviatedString()
42+
}
3943
}
4044
}

rust/ql/lib/codeql/rust/elements/internal/LifetimeImpl.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ module Impl {
2222
* ```
2323
*/
2424
class Lifetime extends Generated::Lifetime {
25-
override string toStringImpl() {
25+
override string toStringImpl() { result = this.toAbbreviatedString() }
26+
27+
override string toAbbreviatedString() {
2628
result = this.getText()
2729
or
2830
not this.hasText() and result = "'_"

rust/ql/lib/codeql/rust/elements/internal/TypeBoundImpl.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `TypeBound`.
43
*
@@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.TypeBound
1211
* be referenced directly.
1312
*/
1413
module Impl {
14+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1515
/**
1616
* A type bound in a trait or generic parameter.
1717
*
@@ -23,5 +23,12 @@ module Impl {
2323
* // ^^^^^^^^^^^^^^^^^^^^^
2424
* ```
2525
*/
26-
class TypeBound extends Generated::TypeBound { }
26+
class TypeBound extends Generated::TypeBound {
27+
override string toAbbreviatedString() {
28+
result = this.getLifetime().toAbbreviatedString()
29+
or
30+
not this.hasLifetime() and
31+
result = "..."
32+
}
33+
}
2734
}

rust/ql/lib/codeql/rust/elements/internal/TypeBoundListImpl.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `TypeBoundList`.
43
*
@@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.TypeBoundList
1211
* be referenced directly.
1312
*/
1413
module Impl {
14+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1515
/**
1616
* A list of type bounds.
1717
*
@@ -21,5 +21,15 @@ module Impl {
2121
* // ^^^^^^^^^^^^^
2222
* ```
2323
*/
24-
class TypeBoundList extends Generated::TypeBoundList { }
24+
class TypeBoundList extends Generated::TypeBoundList {
25+
override string toStringImpl() { result = this.toAbbreviatedString() }
26+
27+
private string toAbbreviatedStringPart(int index) {
28+
result = this.getBound(index).toAbbreviatedString()
29+
}
30+
31+
override string toAbbreviatedString() {
32+
result = strictconcat(int i | | this.toAbbreviatedStringPart(i), " + " order by i)
33+
}
34+
}
2535
}

0 commit comments

Comments
 (0)