Skip to content

Rust: Fix paths of derive-generated items - #23206

Open
hvitved wants to merge 2 commits into
github:mainfrom
hvitved:hvitved-fix-issue-23146
Open

hvitved wants to merge 2 commits into
github:mainfrom
hvitved:hvitved-fix-issue-23146

Conversation

@hvitved

@hvitved hvitved commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Derive-generated items are siblings of the type they derive from, not nested inside it. Treating them as nested produced incorrect canonical paths and prevented references to generated types from resolving.

Fixes #23146

DCA is fine.

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Nov 23, 2026
@hvitved
hvitved force-pushed the hvitved-fix-issue-23146 branch 3 times, most recently from 1849efc to 864f1a8 Compare November 23, 2026 10:30
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Nov 23, 2026
@hvitved
hvitved marked this pull request as ready for review November 23, 2026 13:30
@hvitved
hvitved requested a review from a team as a code owner November 23, 2026 13:30
@hvitved
hvitved requested review from paldepind and an adaptive review from Copilot November 23, 2026 13:30

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

Derive-generated items still have incorrect parent scopes through expansion wrappers, and glob-shadowing checks can incorrectly resolve name collisions; both issues need fixes and regression coverage.

2 open issues
What changed in this PR

This PR corrects Rust path resolution so derive-generated items are treated as siblings of the originating type, addressing the canonical-path and name-resolution problem in #23146.

Changes:

  • Adjusts immediate-parent lookup for derive-generated items.
  • Adds a builder-generating derive fixture and checks canonical paths and reference resolution.
  • Updates expected query results and AST output.
File Description
rust/​ql/​test/​extractor-tests/​macro-expansion/​test.ql Adds canonical-path and reference-resolution checks.
rust/​ql/​test/​extractor-tests/​macro-expansion/​test.expected Records expected builder paths and resolved references.
rust/​ql/​test/​extractor-tests/​macro-expansion/​proc_macro.rs Adds the GenerateBuilder derive macro.
rust/​ql/​test/​extractor-tests/​macro-expansion/​PrintAst.expected Updates AST expectations for the new fixture.
rust/​ql/​test/​extractor-tests/​macro-expansion/​macro_expansion.rs Adds Config and sibling uses of ConfigBuilder.
rust/​ql/​lib/​codeql/​rust/​internal/​PathResolution.qll Reparents direct derive output to the originating type’s enclosing scope.

Review effort: Balanced (adaptive)

@hvitved
hvitved marked this pull request as draft November 23, 2026 13:46
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@hvitved
hvitved force-pushed the hvitved-fix-issue-23146 branch from b4dc290 to bdcc19b Compare November 23, 2026 14:54
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@hvitved
hvitved force-pushed the hvitved-fix-issue-23146 branch from bdcc19b to ca1733f Compare November 23, 2026 18:52
@hvitved
hvitved marked this pull request as ready for review November 24, 2026 08:29

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

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust: a type generated by a derive macro is placed inside its struct (wrong canonical path, name not resolved)

3 participants