Skip to content

Commit f897614

Browse files
authored
Merge pull request github#18224 from github/redsun82/rust-tweaks
Rust: tweak/define more `toString` implementations
2 parents 829a934 + b59b90b commit f897614

File tree

18 files changed

+64
-58
lines changed

18 files changed

+64
-58
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ module Impl {
2020
* ```
2121
*/
2222
class MethodCallExpr extends Generated::MethodCallExpr {
23-
override string toString() { result = "... ." + this.getNameRef().toString() + "(...)" }
23+
override string toString() {
24+
exists(string base, string separator |
25+
base = this.getReceiver().toAbbreviatedString() and
26+
(if base = "..." then separator = " ." else separator = ".") and
27+
result = base + separator + this.getNameRef().toString() + "(...)"
28+
)
29+
}
2430
}
2531
}

rust/ql/lib/codeql/rust/elements/internal/StructImpl.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 `Struct`.
43
*
@@ -12,11 +11,14 @@ private import codeql.rust.elements.internal.generated.Struct
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 Struct. For example:
1717
* ```rust
1818
* todo!()
1919
* ```
2020
*/
21-
class Struct extends Generated::Struct { }
21+
class Struct extends Generated::Struct {
22+
override string toString() { result = "struct " + this.getName().getText() }
23+
}
2224
}

rust/ql/lib/codeql/rust/elements/internal/VariantImpl.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 `Variant`.
43
*
@@ -12,11 +11,14 @@ private import codeql.rust.elements.internal.generated.Variant
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 Variant. For example:
1717
* ```rust
1818
* todo!()
1919
* ```
2020
*/
21-
class Variant extends Generated::Variant { }
21+
class Variant extends Generated::Variant {
22+
override string toString() { result = this.getName().getText() }
23+
}
2224
}

rust/ql/test/extractor-tests/canonical_path/canonical_paths.expected

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
canonicalPaths
22
| anonymous.rs:1:1:1:26 | Use | None | None |
33
| anonymous.rs:3:1:32:1 | fn canonicals | repo::test | crate::anonymous::canonicals |
4-
| anonymous.rs:4:5:4:23 | Struct | repo::test | {0}::OtherStruct |
4+
| anonymous.rs:4:5:4:23 | struct OtherStruct | repo::test | {0}::OtherStruct |
55
| anonymous.rs:6:5:8:5 | trait OtherTrait | repo::test | {0}::OtherTrait |
66
| anonymous.rs:7:9:7:20 | fn g | repo::test | {0}::OtherTrait::g |
77
| anonymous.rs:10:5:12:5 | impl OtherTrait for OtherStruct { ... } | None | None |
@@ -11,13 +11,13 @@ canonicalPaths
1111
| anonymous.rs:18:5:20:5 | impl ...::Trait for OtherStruct { ... } | None | None |
1212
| anonymous.rs:19:9:19:22 | fn f | repo::test | <{0}::OtherStruct as crate::regular::Trait>::f |
1313
| anonymous.rs:22:5:24:5 | fn nested | repo::test | {0}::nested |
14-
| anonymous.rs:23:9:23:27 | Struct | repo::test | {1}::OtherStruct |
14+
| anonymous.rs:23:9:23:27 | struct OtherStruct | repo::test | {1}::OtherStruct |
1515
| anonymous.rs:26:5:31:5 | fn usage | repo::test | {0}::usage |
1616
| anonymous.rs:34:1:36:1 | fn other | repo::test | crate::anonymous::other |
17-
| anonymous.rs:35:5:35:23 | Struct | repo::test | {36}::OtherStruct |
17+
| anonymous.rs:35:5:35:23 | struct OtherStruct | repo::test | {36}::OtherStruct |
1818
| lib.rs:1:1:1:14 | mod anonymous | repo::test | crate::anonymous |
1919
| lib.rs:2:1:2:12 | mod regular | repo::test | crate::regular |
20-
| regular.rs:1:1:2:18 | Struct | repo::test | crate::regular::Struct |
20+
| regular.rs:1:1:2:18 | struct Struct | repo::test | crate::regular::Struct |
2121
| regular.rs:4:1:6:1 | trait Trait | repo::test | crate::regular::Trait |
2222
| regular.rs:5:5:5:16 | fn f | repo::test | crate::regular::Trait::f |
2323
| regular.rs:8:1:10:1 | impl Trait for Struct { ... } | None | None |
@@ -38,17 +38,17 @@ canonicalPaths
3838
resolvedPaths
3939
| anonymous.rs:27:17:27:30 | OtherStruct {...} | repo::test | {0}::OtherStruct |
4040
| anonymous.rs:28:9:28:9 | s | None | None |
41-
| anonymous.rs:28:9:28:13 | ... .f(...) | repo::test | <{0}::OtherStruct as crate::regular::Trait>::f |
41+
| anonymous.rs:28:9:28:13 | s.f(...) | repo::test | <{0}::OtherStruct as crate::regular::Trait>::f |
4242
| anonymous.rs:29:9:29:9 | s | None | None |
43-
| anonymous.rs:29:9:29:13 | ... .g(...) | repo::test | <{0}::OtherStruct as {0}::OtherTrait>::g |
43+
| anonymous.rs:29:9:29:13 | s.g(...) | repo::test | <{0}::OtherStruct as {0}::OtherTrait>::g |
4444
| anonymous.rs:30:9:30:14 | nested | repo::test | {0}::nested |
4545
| regular.rs:27:13:27:21 | Struct {...} | repo::test | crate::regular::Struct |
4646
| regular.rs:28:5:28:5 | s | None | None |
47-
| regular.rs:28:5:28:9 | ... .f(...) | repo::test | <crate::regular::Struct as crate::regular::Trait>::f |
47+
| regular.rs:28:5:28:9 | s.f(...) | repo::test | <crate::regular::Struct as crate::regular::Trait>::f |
4848
| regular.rs:29:5:29:5 | s | None | None |
49-
| regular.rs:29:5:29:9 | ... .g(...) | repo::test | <crate::regular::Struct>::g |
49+
| regular.rs:29:5:29:9 | s.g(...) | repo::test | <crate::regular::Struct>::g |
5050
| regular.rs:30:5:30:5 | s | None | None |
51-
| regular.rs:30:5:30:9 | ... .h(...) | repo::test | <_ as crate::regular::TraitWithBlanketImpl>::h |
51+
| regular.rs:30:5:30:9 | s.h(...) | repo::test | <_ as crate::regular::TraitWithBlanketImpl>::h |
5252
| regular.rs:31:5:31:8 | free | repo::test | crate::regular::free |
5353
| regular.rs:41:9:41:26 | ...::None::<...> | lang:core | crate::option::Option::None |
5454
| regular.rs:42:9:42:20 | ...::Some | lang:core | crate::option::Option::Some |

rust/ql/test/extractor-tests/generated/MacroItems/CONSISTENCY/AstConsistency.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
noLocation
2-
| file://:0:0:0:0 | ... .parent(...) |
32
| file://:0:0:0:0 | ... .unwrap(...) |
43
| file://:0:0:0:0 | ...: ... |
54
| file://:0:0:0:0 | ...::Path |
@@ -35,6 +34,7 @@ noLocation
3534
| file://:0:0:0:0 | path |
3635
| file://:0:0:0:0 | path |
3736
| file://:0:0:0:0 | path |
37+
| file://:0:0:0:0 | path.parent(...) |
3838
| file://:0:0:0:0 | std |
3939
| file://:0:0:0:0 | std |
4040
| file://:0:0:0:0 | std |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| gen_method_call_expr.rs:5:5:5:13 | ... .foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | no | hasNameRef: | yes | hasReceiver: | yes |
2-
| gen_method_call_expr.rs:6:5:6:25 | ... .foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | yes | hasNameRef: | yes | hasReceiver: | yes |
1+
| gen_method_call_expr.rs:5:5:5:13 | x.foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | no | hasNameRef: | yes | hasReceiver: | yes |
2+
| gen_method_call_expr.rs:6:5:6:25 | x.foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | yes | hasNameRef: | yes | hasReceiver: | yes |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| gen_method_call_expr.rs:5:5:5:13 | ... .foo(...) | gen_method_call_expr.rs:5:10:5:13 | ArgList |
2-
| gen_method_call_expr.rs:6:5:6:25 | ... .foo(...) | gen_method_call_expr.rs:6:22:6:25 | ArgList |
1+
| gen_method_call_expr.rs:5:5:5:13 | x.foo(...) | gen_method_call_expr.rs:5:10:5:13 | ArgList |
2+
| gen_method_call_expr.rs:6:5:6:25 | x.foo(...) | gen_method_call_expr.rs:6:22:6:25 | ArgList |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| gen_method_call_expr.rs:6:5:6:25 | ... .foo(...) | gen_method_call_expr.rs:6:10:6:21 | <...> |
1+
| gen_method_call_expr.rs:6:5:6:25 | x.foo(...) | gen_method_call_expr.rs:6:10:6:21 | <...> |

0 commit comments

Comments
 (0)