Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Implement toString on type aliases and add docs #19130

Merged
merged 2 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions rust/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rust/ql/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions rust/ql/lib/codeql/rust/elements/GenericParamList.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions rust/ql/lib/codeql/rust/elements/TypeAlias.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ module Impl {

// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* A GenericParamList. For example:
* A list of generic parameters. For example:
* ```rust
* todo!()
* fn f<A, B>(a: A, b: B) {}
* // ^^^^^^
* type Foo<T1, T2> = (T1, T2);
* // ^^^^^^^^
* ```
*/
class GenericParamList extends Generated::GenericParamList {
Expand Down
23 changes: 19 additions & 4 deletions rust/ql/lib/codeql/rust/elements/internal/TypeAliasImpl.qll
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// generated by codegen, remove this comment if you wish to edit this file
/**
* This module provides a hand-modifiable wrapper around the generated class `TypeAlias`.
*
Expand All @@ -12,11 +11,27 @@ private import codeql.rust.elements.internal.generated.TypeAlias
* be referenced directly.
*/
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* A TypeAlias. For example:
* A type alias. For example:
* ```rust
* todo!()
* type Point = (u8, u8);
*
* trait Trait {
* type Output;
* // ^^^^^^^^^^^
* }
* ```
*/
class TypeAlias extends Generated::TypeAlias { }
class TypeAlias extends Generated::TypeAlias {
override string toStringImpl() { result = concat(int i | | this.toStringPart(i) order by i) }

private string toStringPart(int index) {
index = 0 and result = "type "
or
index = 1 and result = this.getName().getText()
or
index = 2 and result = this.getGenericParamList().toAbbreviatedString()
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/ql/test/extractor-tests/generated/.generated_tests.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| gen_generic_param_list.rs:5:9:5:14 | <...> | getNumberOfGenericParams: | 2 |
| gen_generic_param_list.rs:7:13:7:20 | <...> | getNumberOfGenericParams: | 2 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| gen_generic_param_list.rs:5:9:5:14 | <...> | 0 | gen_generic_param_list.rs:5:10:5:10 | A |
| gen_generic_param_list.rs:5:9:5:14 | <...> | 1 | gen_generic_param_list.rs:5:13:5:13 | B |
| gen_generic_param_list.rs:7:13:7:20 | <...> | 0 | gen_generic_param_list.rs:7:14:7:15 | T1 |
| gen_generic_param_list.rs:7:13:7:20 | <...> | 1 | gen_generic_param_list.rs:7:18:7:19 | T2 |

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| gen_trait.rs:4:20:8:1 | AssocItemList | 0 | gen_trait.rs:5:3:5:18 | TypeAlias |
| gen_trait.rs:4:20:8:1 | AssocItemList | 1 | gen_trait.rs:6:3:6:20 | TypeAlias |
| gen_trait.rs:4:20:8:1 | AssocItemList | 0 | gen_trait.rs:5:3:5:18 | type Frobinator |
| gen_trait.rs:4:20:8:1 | AssocItemList | 1 | gen_trait.rs:6:3:6:20 | type Result |
| gen_trait.rs:4:20:8:1 | AssocItemList | 2 | gen_trait.rs:7:3:7:72 | fn frobinize_with |
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| 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 |
| 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 number Diff line number Diff line change
@@ -0,0 +1,2 @@
| gen_type_alias.rs:4:5:5:26 | type Point | gen_type_alias.rs:5:10:5:14 | Point |
| gen_type_alias.rs:8:9:8:20 | type Output | gen_type_alias.rs:8:14:8:19 | Output |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| gen_type_alias.rs:4:5:5:26 | type Point | gen_type_alias.rs:5:18:5:25 | TupleTypeRepr |

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ resolvePath
| main.rs:261:17:261:17 | C | main.rs:254:9:254:9 | C |
| main.rs:274:16:274:16 | T | main.rs:268:7:268:7 | T |
| main.rs:275:14:275:17 | Self | main.rs:266:5:276:5 | trait MyParamTrait |
| main.rs:275:14:275:33 | ...::AssociatedType | main.rs:270:9:270:28 | TypeAlias |
| main.rs:275:14:275:33 | ...::AssociatedType | main.rs:270:9:270:28 | type AssociatedType |
| main.rs:284:13:284:17 | crate | main.rs:0:0:0:0 | Crate([email protected]) |
| main.rs:284:13:284:22 | ...::m13 | main.rs:279:1:292:1 | mod m13 |
| main.rs:284:13:284:25 | ...::f | main.rs:280:5:280:17 | fn f |
Expand Down
16 changes: 12 additions & 4 deletions rust/schema/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,12 @@ class _:
@annotate(GenericParamList)
class _:
"""
A GenericParamList. For example:
A list of generic parameters. For example:
```rust
todo!()
fn f<A, B>(a: A, b: B) {}
// ^^^^^^
type Foo<T1, T2> = (T1, T2);
// ^^^^^^^^
```
"""

Expand Down Expand Up @@ -1705,9 +1708,14 @@ class _:
@annotate(TypeAlias)
class _:
"""
A TypeAlias. For example:
A type alias. For example:
```rust
todo!()
type Point = (u8, u8);

trait Trait {
type Output;
// ^^^^^^^^^^^
}
```
"""

Expand Down