Skip to content

Commit ee3a3f5

Browse files
committed
Rust: avoid missing toString for PathSegment without name
1 parent 68f3b24 commit ee3a3f5

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ module Impl {
2121
class PathSegment extends Generated::PathSegment {
2222
override string toString() {
2323
// TODO: this does not cover everything
24-
if this.hasGenericArgList()
25-
then result = this.getNameRef().toString() + "::<...>"
26-
else result = this.getNameRef().toString()
24+
exists(string name |
25+
name = this.getNameRef().getText()
26+
or
27+
name = "" and not exists(this.getNameRef())
28+
|
29+
if this.hasGenericArgList() then result = name + "::<...>" else result = name
30+
)
2731
}
2832
}
2933
}

rust/ql/test/extractor-tests/types/types.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ exprTypes
7676
| main.rs:47:14:47:18 | false | bool |
7777
| main.rs:51:14:53:1 | BlockExpr | () |
7878
| main.rs:52:5:52:11 | $crate::boxed::Box::new | fn new<[i32; 1]>([i32; 1]) -> Box<[i32; 1], Global> |
79-
| main.rs:52:5:52:11 | (no string representation) | fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global> |
79+
| main.rs:52:5:52:11 | ::into_vec | fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global> |
8080
| main.rs:52:5:52:11 | MacroExpr | Vec<i32, Global> |
8181
| main.rs:52:10:52:10 | 1 | i32 |
8282
| main.rs:52:10:52:10 | ArrayExpr | [i32; 1] |

0 commit comments

Comments
 (0)