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: add some toString implementations #18035

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
42 changes: 0 additions & 42 deletions rust/ql/.generated.list

Large diffs are not rendered by default.

42 changes: 0 additions & 42 deletions rust/ql/.gitattributes

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

2 changes: 1 addition & 1 deletion rust/ql/integration-tests/hello-project/functions.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| src/main.rs:4:1:6:1 | main |
| src/main.rs:4:1:6:1 | fn main |
4 changes: 2 additions & 2 deletions rust/ql/integration-tests/hello-workspace/functions.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| exe/src/main.rs:5:1:7:1 | main |
| lib/src/a_module/mod.rs:1:1:3:1 | hello |
| exe/src/main.rs:5:1:7:1 | fn main |
| lib/src/a_module/mod.rs:1:1:3:1 | fn hello |
6 changes: 3 additions & 3 deletions rust/ql/integration-tests/options/cfg/functions.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| src/lib.rs:7:1:8:19 | cfg_no_flag |
| src/lib.rs:10:1:11:18 | cfg_no_key |
| src/lib.rs:16:1:17:24 | pointer_width_64 |
| src/lib.rs:7:1:8:19 | fn cfg_no_flag |
| src/lib.rs:10:1:11:18 | fn cfg_no_key |
| src/lib.rs:16:1:17:24 | fn pointer_width_64 |
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| src/lib.rs:1:1:2:16 | cfg_flag |
| src/lib.rs:4:1:5:15 | cfg_key |
| src/lib.rs:13:1:14:12 | test |
| src/lib.rs:19:1:20:24 | pointer_width_32 |
| src/lib.rs:1:1:2:16 | fn cfg_flag |
| src/lib.rs:4:1:5:15 | fn cfg_key |
| src/lib.rs:13:1:14:12 | fn test |
| src/lib.rs:19:1:20:24 | fn pointer_width_32 |
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| src/lib.rs:1:1:2:11 | foo |
| src/lib.rs:4:1:5:11 | bar |
| src/lib.rs:7:1:7:14 | always |
| src/lib.rs:1:1:2:11 | fn foo |
| src/lib.rs:4:1:5:11 | fn bar |
| src/lib.rs:7:1:7:14 | fn always |
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| src/lib.rs:4:1:5:11 | bar |
| src/lib.rs:7:1:7:14 | always |
| src/lib.rs:4:1:5:11 | fn bar |
| src/lib.rs:7:1:7:14 | fn always |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| src/lib.rs:7:1:7:14 | always |
| src/lib.rs:7:1:7:14 | fn always |
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| src/lib.rs:1:1:2:11 | foo |
| src/lib.rs:7:1:7:14 | always |
| src/lib.rs:1:1:2:11 | fn foo |
| src/lib.rs:7:1:7:14 | fn always |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| src/lib.rs:7:1:8:13 | macos |
| src/lib.rs:7:1:8:13 | fn macos |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| src/lib.rs:1:1:2:13 | linux |
| src/lib.rs:1:1:2:13 | fn linux |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| src/lib.rs:4:1:5:15 | windows |
| src/lib.rs:4:1:5:15 | fn windows |
3 changes: 2 additions & 1 deletion rust/ql/integration-tests/qltest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
# (which skips `qltest.{sh,cmd}`)

@pytest.fixture(autouse=True)
def default_options(codeql):
def default_options(codeql, pytestconfig):
codeql.flags.update(
threads = 1,
show_extractor_output = True,
check_databases = False,
learn = pytestconfig.getoption("learn"),
)

@pytest.mark.parametrize("dir", ["lib", "main", "dependencies"])
Expand Down
6 changes: 4 additions & 2 deletions rust/ql/lib/codeql/rust/elements/internal/ArrayExprImpl.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 `ArrayExpr`.
*
Expand All @@ -12,12 +11,15 @@ private import codeql.rust.elements.internal.generated.ArrayExpr
* be referenced directly.
*/
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* An array expression. For example:
* ```rust
* [1, 2, 3];
* [1; 10];
* ```
*/
class ArrayExpr extends Generated::ArrayExpr { }
class ArrayExpr extends Generated::ArrayExpr {
override string toString() { result = "[...]" }
}
}
6 changes: 4 additions & 2 deletions rust/ql/lib/codeql/rust/elements/internal/AwaitExprImpl.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 `AwaitExpr`.
*
Expand All @@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.AwaitExpr
* be referenced directly.
*/
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* An `await` expression. For example:
* ```rust
Expand All @@ -21,5 +21,7 @@ module Impl {
* }
* ```
*/
class AwaitExpr extends Generated::AwaitExpr { }
class AwaitExpr extends Generated::AwaitExpr {
override string toString() { result = "await ..." }
}
}
6 changes: 4 additions & 2 deletions rust/ql/lib/codeql/rust/elements/internal/BecomeExprImpl.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 `BecomeExpr`.
*
Expand All @@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.BecomeExpr
* be referenced directly.
*/
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* A `become` expression. For example:
* ```rust
Expand All @@ -24,5 +24,7 @@ module Impl {
* }
* ```
*/
class BecomeExpr extends Generated::BecomeExpr { }
class BecomeExpr extends Generated::BecomeExpr {
override string toString() { result = "become ..." }
}
}
6 changes: 4 additions & 2 deletions rust/ql/lib/codeql/rust/elements/internal/BlockExprImpl.qll

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

6 changes: 4 additions & 2 deletions rust/ql/lib/codeql/rust/elements/internal/BoxPatImpl.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 `BoxPat`.
*
Expand All @@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.BoxPat
* be referenced directly.
*/
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* A box pattern. For example:
* ```rust
Expand All @@ -21,5 +21,7 @@ module Impl {
* };
* ```
*/
class BoxPat extends Generated::BoxPat { }
class BoxPat extends Generated::BoxPat {
override string toString() { result = "box ..." }
}
}
12 changes: 12 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/BreakExprImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,17 @@ module Impl {
isLabelled(result, label)
)
}

override string toString() {
exists(string label, string expr |
(
result = " " + this.getLifetime().toString()
or
not this.hasLifetime() and result = ""
) and
(if this.hasExpr() then expr = " ..." else expr = "") and
result = "break" + label + expr
)
}
}
}
Loading