Skip to content

Commit e49a5be

Browse files
author
Paolo Tranquilli
committed
Rust: fix parent/child relationship for format entities
1 parent 44c94e0 commit e49a5be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+317
-41
lines changed

rust/ql/.generated.list

Lines changed: 19 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/Format.qll

Lines changed: 1 addition & 0 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/FormatArgsExpr.qll

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/FormatArgument.qll

Lines changed: 1 addition & 0 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/FormatArgsExprImpl.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ module Impl {
1616
/**
1717
* A FormatArgsExpr. For example:
1818
* ```rust
19-
* todo!()
19+
* format_args!("no args");
20+
* format_args!("{} foo {:?}", 1, 2);
21+
* format_args!("{b} foo {a:?}", a=1, b=2);
22+
* let (x, y) = (1, 42);
23+
* format_args!("{x}, {y}");
2024
* ```
2125
*/
2226
class FormatArgsExpr extends Generated::FormatArgsExpr {
23-
/**
24-
* Gets the `index`th format of this `FormatArgsExpr`'s formatting template (0-based).
25-
*/
26-
Format getFormat(int index) {
27-
result =
28-
rank[index + 1](Format f, int i | f.getParent() = this and f.getIndex() = i | f order by i)
27+
override Format getFormat(int index) {
28+
result.getParent() = this and result.getIndex() = index + 1
2929
}
3030
}
3131
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ module Impl {
3939
override string toString() { result = name }
4040

4141
override Format getParent() { result = Synth::TFormat(parent, index, _, _) }
42+
43+
override FormatTemplateVariableAccess getVariable() { result.getArgument() = this }
4244
}
4345

4446
private class FormatSynthLocationImpl extends FormatArgument, LocatableImpl::SynthLocatable {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module Impl {
3838

3939
override int getIndex() { result = index }
4040

41+
override FormatArgument getArgument() { result.getParent() = this }
42+
4143
/**
4244
* Gets the name or position reference of this format, if any. For example `name` and `0` in:
4345
* ```rust

rust/ql/lib/codeql/rust/elements/internal/generated/Format.qll

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)