Skip to content

Commit 8be531e

Browse files
committed
Rust: Implement toString on type aliases and add docs
1 parent 9dd7b20 commit 8be531e

18 files changed

+104
-35
lines changed

rust/ql/.generated.list

+5-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/GenericParamList.qll

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/TypeAlias.qll

+7-2
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/GenericParamListImpl.qll

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ module Impl {
1515

1616
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1717
/**
18-
* A GenericParamList. For example:
18+
* A list of generic parameters. For example:
1919
* ```rust
20-
* todo!()
20+
* fn f<A, B>(a: A, b: B) {}
21+
* // ^^^^^^
22+
* type Foo<T1, T2> = (T1, T2);
23+
* // ^^^^^^^^
2124
* ```
2225
*/
2326
class GenericParamList extends Generated::GenericParamList {

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

+21-4
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 `TypeAlias`.
43
*
@@ -12,11 +11,29 @@ private import codeql.rust.elements.internal.generated.TypeAlias
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
/**
16-
* A TypeAlias. For example:
16+
* A type alias. For example:
1717
* ```rust
18-
* todo!()
18+
* type Point = (u8, u8);
19+
*
20+
* trait Trait {
21+
* type Output;
22+
* // ^^^^^^^^^^^
23+
* }
1924
* ```
2025
*/
21-
class TypeAlias extends Generated::TypeAlias { }
26+
class TypeAlias extends Generated::TypeAlias {
27+
override string toStringImpl() {
28+
result = concat(int i | | this.toStringPart(i), "" order by i)
29+
}
30+
31+
private string toStringPart(int index) {
32+
index = 0 and result = "type "
33+
or
34+
index = 1 and result = this.getName().getText()
35+
or
36+
index = 2 and result = this.getGenericParamList().toAbbreviatedString()
37+
}
38+
}
2239
}

rust/ql/lib/codeql/rust/elements/internal/generated/GenericParamList.qll

+5-2
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/generated/Raw.qll

+12-4
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/generated/TypeAlias.qll

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/test/extractor-tests/generated/.generated_tests.list

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| gen_generic_param_list.rs:5:9:5:14 | <...> | getNumberOfGenericParams: | 2 |
2+
| gen_generic_param_list.rs:7:13:7:20 | <...> | getNumberOfGenericParams: | 2 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| gen_generic_param_list.rs:5:9:5:14 | <...> | 0 | gen_generic_param_list.rs:5:10:5:10 | A |
2+
| gen_generic_param_list.rs:5:9:5:14 | <...> | 1 | gen_generic_param_list.rs:5:13:5:13 | B |
3+
| gen_generic_param_list.rs:7:13:7:20 | <...> | 0 | gen_generic_param_list.rs:7:14:7:15 | T1 |
4+
| gen_generic_param_list.rs:7:13:7:20 | <...> | 1 | gen_generic_param_list.rs:7:18:7:19 | T2 |

rust/ql/test/extractor-tests/generated/GenericParamList/gen_generic_param_list.rs

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| gen_type_alias.rs:4:5:5:26 | type Point | hasExtendedCanonicalPath: | no | hasCrateOrigin: | no | getNumberOfAttrs: | 0 | hasGenericParamList: | no | isDefault: | no | hasName: | yes | hasTypeRepr: | yes | hasTypeBoundList: | no | hasVisibility: | no | hasWhereClause: | no |
2+
| gen_type_alias.rs:8:9:8:20 | type Output | hasExtendedCanonicalPath: | no | hasCrateOrigin: | no | getNumberOfAttrs: | 0 | hasGenericParamList: | no | isDefault: | no | hasName: | yes | hasTypeRepr: | no | hasTypeBoundList: | no | hasVisibility: | no | hasWhereClause: | no |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| gen_type_alias.rs:4:5:5:26 | type Point | gen_type_alias.rs:5:10:5:14 | Point |
2+
| gen_type_alias.rs:8:9:8:20 | type Output | gen_type_alias.rs:8:14:8:19 | Output |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| gen_type_alias.rs:4:5:5:26 | type Point | gen_type_alias.rs:5:18:5:25 | TupleTypeRepr |

rust/ql/test/extractor-tests/generated/TypeAlias/gen_type_alias.rs

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/schema/annotations.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,12 @@ class _:
11231123
@annotate(GenericParamList)
11241124
class _:
11251125
"""
1126-
A GenericParamList. For example:
1126+
A list of generic parameters. For example:
11271127
```rust
1128-
todo!()
1128+
fn f<A, B>(a: A, b: B) {}
1129+
// ^^^^^^
1130+
type Foo<T1, T2> = (T1, T2);
1131+
// ^^^^^^^^
11291132
```
11301133
"""
11311134

@@ -1705,9 +1708,14 @@ class _:
17051708
@annotate(TypeAlias)
17061709
class _:
17071710
"""
1708-
A TypeAlias. For example:
1711+
A type alias. For example:
17091712
```rust
1710-
todo!()
1713+
type Point = (u8, u8);
1714+
1715+
trait Trait {
1716+
type Output;
1717+
// ^^^^^^^^^^^
1718+
}
17111719
```
17121720
"""
17131721

0 commit comments

Comments
 (0)