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: fix parent/child relationship for format entities #18071

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 19 additions & 13 deletions rust/ql/.generated.list

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

12 changes: 9 additions & 3 deletions rust/ql/.gitattributes

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

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

1 change: 1 addition & 0 deletions rust/ql/lib/codeql/rust/elements/Format.qll

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

7 changes: 6 additions & 1 deletion rust/ql/lib/codeql/rust/elements/FormatArgsExpr.qll

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

1 change: 1 addition & 0 deletions rust/ql/lib/codeql/rust/elements/FormatArgument.qll

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

14 changes: 7 additions & 7 deletions rust/ql/lib/codeql/rust/elements/internal/FormatArgsExprImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ module Impl {
/**
* A FormatArgsExpr. For example:
* ```rust
* todo!()
* format_args!("no args");
* format_args!("{} foo {:?}", 1, 2);
* format_args!("{b} foo {a:?}", a=1, b=2);
* let (x, y) = (1, 42);
* format_args!("{x}, {y}");
* ```
*/
class FormatArgsExpr extends Generated::FormatArgsExpr {
/**
* Gets the `index`th format of this `FormatArgsExpr`'s formatting template (0-based).
*/
Format getFormat(int index) {
result =
rank[index + 1](Format f, int i | f.getParent() = this and f.getIndex() = i | f order by i)
override Format getFormat(int index) {
result.getParent() = this and result.getIndex() = index + 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module Impl {
override string toString() { result = name }

override Format getParent() { result = Synth::TFormat(parent, index, _, _) }

override FormatTemplateVariableAccess getVariable() { result.getArgument() = this }
}

private class FormatSynthLocationImpl extends FormatArgument, LocatableImpl::SynthLocatable {
Expand Down
2 changes: 2 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module Impl {

override int getIndex() { result = index }

override FormatArgument getArgument() { result.getParent() = this }

/**
* Gets the name or position reference of this format, if any. For example `name` and `0` in:
* ```rust
Expand Down
11 changes: 11 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/generated/Format.qll

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

Loading