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: Include index in Format.getArgument #18445

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 8, 2025

A Format can have multiple FormatArguments, so getArgument must take an index. I have added two new consistency checks as well, one of which (multipleChildren) would fail prior to this PR.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jan 8, 2025
@hvitved hvitved force-pushed the rust/format-args-index branch from 198d94b to 033cd17 Compare January 8, 2025 13:05
@hvitved hvitved force-pushed the rust/format-args-index branch from 6cb3ef0 to 0dccbb9 Compare January 8, 2025 13:30
@hvitved hvitved marked this pull request as ready for review January 9, 2025 08:02
@Copilot Copilot bot review requested due to automatic review settings January 9, 2025 08:02

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 7 out of 13 changed files in this pull request and generated no comments.

Files not reviewed (6)
  • rust/ql/.generated.list: Language not supported
  • rust/ql/lib/codeql/rust/AstConsistency.qll: Language not supported
  • rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/FormatArgumentImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll: Language not supported
  • rust/ql/test/query-tests/diagnostics/AstConsistencyCounts.expected: Language not supported

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

@hvitved hvitved requested a review from aibaars January 9, 2025 14:17
Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this bug. Not sure what the purpose of argument: in the schema was. We could also just drop it.

@@ -40,6 +40,16 @@ module Impl {

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

/** Gets the position of this argument. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This predicate might be a bit confusing. I think it should be dropped.

There are named and positional arguments which can be mixed to some extent. Not sure what the "position" of a named argument would mean, and it would be strange if getPosition does not coincide with the position of a positional argument. For example:

let width = 2;
println!("Value {value:#precision$.0$}", width, precision = 3, value = 100);

would have getPosition() = 2 for 0 .

@@ -42,7 +42,9 @@ module Impl {

override int getIndex() { result = index }

override FormatArgument getArgument() { result.getParent() = this }
override FormatArgument getArgument(int i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old definition of getArgument() was clearly wrong. I think I simply forgot to remove the argument field from the schema, so we could just delete this predicate. If you want to keep it, that's fine too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants