Skip to content

Rust: Skip parentheses in extraction - #22997

Draft
hvitved wants to merge 4 commits into
mainfrom
hvitved-rust-parenthesized-entities
Draft

hvitved wants to merge 4 commits into
mainfrom
hvitved-rust-parenthesized-entities

Conversation

@hvitved

@hvitved hvitved commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This PR aligns Rust extraction with other languages by skipping parentheses during extraction. This will make it much easier e.g. to switch over to the new CFG library (which is what prompted the change in the first place).

Some care must be taken in order to handle attributes and comments on parenthesized expressions: these are instead pushed into the inner expression, potentially merging with existing comments/attributes.

@hvitved hvitved changed the title Rust: Remove parenthesized expression and pattern nodes Rust: Skip parentheses in extraction Nov 3, 2026
@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Nov 3, 2026
@hvitved
hvitved force-pushed the hvitved-rust-parenthesized-entities branch from d43b652 to 2e4caa1 Compare November 3, 2026 13:44
@hvitved
hvitved force-pushed the hvitved-rust-parenthesized-entities branch from 83e6479 to 2534933 Compare November 3, 2026 19:57
@hvitved
hvitved requested a max review from Copilot November 3, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The change misattaches attributes on non-leaf expressions, loses parenthesized-expression attributes during database upgrades, and drops comments inside expression and pattern parentheses.

3 open issues
What changed in this PR

This PR makes parenthesized Rust expressions and patterns transparent in CodeQL’s extracted AST, simplifying analysis consumers.

Changes:

  • Remove wrapper nodes from the schema, extractor, and generated QL APIs.
  • Simplify control-flow, data-flow, and type-inference handling, with schema upgrade and downgrade support.
  • Refresh test expectations and document improved detection of accesses through expired field pointers.
File Description
rust/​schema/​ast.py Removes expression and pattern wrapper definitions.
rust/​schema/​annotations.py Removes annotations for the deleted wrappers.
rust/​ql/​test/​query-tests/​security/​CWE-825/​lifetime.rs Updates inline expectations for newly detected field-pointer accesses.
rust/​ql/​test/​query-tests/​security/​CWE-825/​AccessAfterLifetime.expected Records additional alerts and flow paths.
rust/​ql/​test/​query-tests/​security/​CWE-798/​HardcodedCryptographicValue.expected Updates expression labels after unwrapping.
rust/​ql/​test/​library-tests/​type-inference/​type-inference.expected Removes results for wrapper nodes.
rust/​ql/​test/​library-tests/​dataflow/​lambdas/​inline-flow.expected Updates closure-capture flow paths.
rust/​ql/​test/​library-tests/​dataflow/​global/​inline-flow.expected Updates post-update flow paths.
rust/​ql/​test/​extractor-tests/​macro-expansion/​PrintAst.expected Reflects flattened macro-expansion ASTs.
rust/​ql/​test/​extractor-tests/​generated/​ParenPat/​ParenPat.ql Removes the generated pattern-wrapper test query.
rust/​ql/​test/​extractor-tests/​generated/​ParenPat/​gen_paren_pat.rs Removes its generated Rust fixture.
rust/​ql/​test/​extractor-tests/​generated/​ParenExpr/​ParenExpr.ql Removes the generated expression-wrapper test query.
rust/​ql/​test/​extractor-tests/​generated/​ParenExpr/​gen_paren_expr.rs Removes its generated Rust fixture.
rust/​ql/​test/​extractor-tests/​generated/​.gitattributes Removes deleted fixture entries.
rust/​ql/​test/​extractor-tests/​generated/​.generated_tests.list Updates the generated fixture inventory.
rust/​ql/​lib/​upgrades/​9487e73d9da6508522f07a34bc4aafa8d55c0f5f/​upgrade.ql Migrates AST references past removed wrappers.
rust/​ql/​lib/​upgrades/​9487e73d9da6508522f07a34bc4aafa8d55c0f5f/​upgrade.properties Registers relation migrations and deletions.
rust/​ql/​lib/​rust.dbscheme Removes wrapper entities and relations.
rust/​ql/​lib/​codeql/​rust/​internal/​typeinference/​TypeInference.qll Removes wrapper handling while retaining the required abstract adapter.
rust/​ql/​lib/​codeql/​rust/​elements/​ParenPat.qll Removes the public pattern-wrapper class.
rust/​ql/​lib/​codeql/​rust/​elements/​ParenExpr.qll Removes the public expression-wrapper class.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​ParenPatImpl.qll Removes the pattern-wrapper implementation.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​ParenPatConstructor.qll Removes its constructor hook.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​ParenExprImpl.qll Removes the expression-wrapper implementation.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​ParenExprConstructor.qll Removes its constructor hook.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​generated/​SynthConstructors.qll Removes wrapper constructor imports.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​generated/​Synth.qll Removes synthesized wrapper types and conversions.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​generated/​Raw.qll Removes raw wrapper classes and accessors.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​generated/​ParentChild.qll Removes wrapper child traversal.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​generated/​ParenPat.qll Removes generated pattern-wrapper bindings.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​generated/​ParenExpr.qll Removes generated expression-wrapper bindings.
rust/​ql/​lib/​codeql/​rust/​elements.qll Removes public wrapper imports.
rust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​DataFlowImpl.qll Removes wrapper-specific flow and capture handling.
rust/​ql/​lib/​codeql/​rust/​controlflow/​internal/​ControlFlowGraphImpl.qll Removes wrapper control-flow trees.
rust/​ql/​lib/​codeql/​rust/​controlflow/​internal/​Completion.qll Removes completion propagation through parentheses.
rust/​ql/​lib/​codeql/​rust/​controlflow/​internal/​CfgNodes.qll Simplifies desugaring to identity.
rust/​ql/​lib/​codeql/​rust/​controlflow/​internal/​CfgConsistency.qll Removes the wrapper consistency exception.
rust/​ql/​lib/​change-notes/​2026-11-03-parenthesized-expressions-and-patterns.md Documents AST and lifetime-analysis changes.
rust/​ql/​.gitattributes Removes deleted generated-file entries.
rust/​ql/​.generated.list Updates generated-file entries and hashes.
rust/​extractor/​src/​translate/​generated.rs Emits inner nodes and integrates attribute forwarding.
rust/​extractor/​src/​translate/​base.rs Adds transparent expression emission and attribute helpers.
rust/​extractor/​src/​generated/​top.rs Removes wrapper trap-entry types.
rust/​extractor/​src/​generated/​.generated.list Updates the generated extractor hash.
rust/​downgrades/​2b1782c73acb36c74060f9e344fc6cd841face4c/​upgrade.properties Adds partial schema-downgrade metadata.
rust/​ast-generator/​templates/​extractor.mustache Supports custom variant emission and attribute merging.
rust/​ast-generator/​src/​main.rs Configures transparent wrapper emission and attribute metadata.

Review effort: Max

Comment thread rust/ast-generator/src/main.rs Resolved
@hvitved
hvitved force-pushed the hvitved-rust-parenthesized-entities branch 3 times, most recently from 9080458 to 323cddb Compare November 4, 2026 08:17
@hvitved
hvitved requested a max review from Copilot November 4, 2026 08:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues cause wrapper attributes to be lost during extraction and upgrades, and leave gaps in array element indexes when empty parenthesized expressions are removed.

3 open issues
3 resolved since last review

Review effort: Max

Comment thread rust/extractor/src/translate/base.rs Resolved
@hvitved
hvitved force-pushed the hvitved-rust-parenthesized-entities branch from 323cddb to 93178ce Compare November 4, 2026 09:31
@hvitved
hvitved force-pushed the hvitved-rust-parenthesized-entities branch from 93178ce to 6e8c233 Compare November 4, 2026 09:37
@hvitved
hvitved requested a max review from Copilot November 4, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread rust/ql/lib/rust.dbscheme Resolved
hvitved and others added 4 commits November 4, 2026 11:31
Extract parenthesized expressions and patterns as their inner entities, and update QL consumers and generated schema. Preserve comments and attributes on the unwrapped nodes, with regression tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Transfer parenthesized expression attributes and references to their unwrapped nodes when upgrading existing databases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@hvitved
hvitved force-pushed the hvitved-rust-parenthesized-entities branch from 6e8c233 to bbeda86 Compare November 4, 2026 10:36
@hvitved
hvitved requested a max review from Copilot November 4, 2026 10:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Missing schema snapshots block Rust database upgrades and downgrades, and public API removals need a breaking-change note rather than a patch-level release classification.

3 open issues
4 resolved since last review

Review effort: Max

Comment thread misc/codegen/lib/schemadefs.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants