Skip to content

Commit 035c681

Browse files
committed
Rust: address comments
1 parent cb6f48f commit 035c681

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

rust/extractor/src/crate_graph.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,17 @@ fn emit_reexport(
206206
PathKind::Plain => (),
207207
PathKind::Super(0) => path_components.push("self".to_owned()),
208208
PathKind::Super(n) => {
209-
path_components.extend(std::iter::repeat_n("parent".to_owned(), n.into()));
209+
path_components.extend(std::iter::repeat_n("super".to_owned(), n.into()));
210210
}
211211
PathKind::Crate => path_components.push("crate".to_owned()),
212212
PathKind::Abs => path_components.push("".to_owned()),
213-
PathKind::DollarCrate(_) => path_components.push("$crate".to_owned()),
213+
PathKind::DollarCrate(crate_id) => {
214+
let crate_name = crate_graph[crate_id]
215+
.display_name
216+
.as_ref()
217+
.map(|x| x.canonical_name().to_string());
218+
path_components.push(crate_name.unwrap_or("crate".to_owned()));
219+
}
214220
}
215221
path_components.extend(path.segments().iter().map(|x| x.as_str().to_owned()));
216222
match kind {

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ module Impl {
2323
*/
2424
class UseTree extends Generated::UseTree {
2525
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-
)
26+
result = strictconcat(int i | | this.toStringPart(i) order by i)
27+
}
28+
29+
private string toStringPart(int index) {
30+
result = this.getPath().toStringImpl() and index = 0
31+
or
32+
result = "::{...}" and this.hasUseTreeList() and index = 1
33+
or
34+
result = "::*" and this.isGlob() and index = 2
35+
or
36+
result = " as " + this.getRename().getName().getText() and index = 3
3537
}
3638
}
3739
}

0 commit comments

Comments
 (0)