Skip to content

Commit 2f4d1c7

Browse files
committed
Rust: implement Use::toString
1 parent da5fd0b commit 2f4d1c7

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

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/UseImpl.qll

Lines changed: 4 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 `Use`.
43
*
@@ -12,11 +11,14 @@ private import codeql.rust.elements.internal.generated.Use
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 Use. For example:
1717
* ```rust
1818
* todo!()
1919
* ```
2020
*/
21-
class Use extends Generated::Use { }
21+
class Use extends Generated::Use {
22+
override string toStringImpl() { result = "use " + this.getUseTree() }
23+
}
2224
}

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

Lines changed: 14 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 `UseTree`.
43
*
@@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.UseTree
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 UseTree. For example:
1717
* ```rust
@@ -21,5 +21,17 @@ module Impl {
2121
* use std::collections::{self, HashMap, HashSet};
2222
* ```
2323
*/
24-
class UseTree extends Generated::UseTree { }
24+
class UseTree extends Generated::UseTree {
25+
override string toStringImpl() {
26+
result =
27+
this.getPath().toStringImpl() +
28+
any(string list | if this.hasUseTreeList() then list = "::{...}" else list = "") +
29+
any(string glob | if this.isGlob() then glob = "::*" else glob = "") +
30+
any(string rename |
31+
rename = " as " + this.getRename().getName().getText()
32+
or
33+
rename = "" and not this.hasRename()
34+
)
35+
}
36+
}
2537
}

0 commit comments

Comments
 (0)