Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Nov 6, 2025

Follows up on #20454 and removes elements superseded by attribute macro expansions entirely from the Element type. We only ever care about the expanded version, which will typically contain a copy of the original definition.

DCA looks good: we reduce inconsistencies, increase call resolution rates, and eliminate rust/unused-variable false positives.

@github-actions github-actions bot added Rust Pull requests that update Rust code Swift labels Nov 6, 2025
@hvitved hvitved force-pushed the rust/attribute-macro-expansion-filter branch 7 times, most recently from e305f21 to 20bb58d Compare November 9, 2025 18:24
@hvitved hvitved force-pushed the rust/attribute-macro-expansion-filter branch from 20bb58d to c81f5f5 Compare November 10, 2025 08:19
@github-actions github-actions bot removed the Swift label Nov 10, 2025
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Nov 10, 2025
@hvitved hvitved requested a review from paldepind November 10, 2025 11:30
@hvitved hvitved marked this pull request as ready for review November 10, 2025 11:30
@hvitved hvitved requested a review from a team as a code owner November 10, 2025 11:30
Copilot AI review requested due to automatic review settings November 10, 2025 11:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors macro expansion handling in the Rust QL library by consolidating logic into a central MacroExpansion module and introducing the isFromMacroExpansion() predicate to better distinguish between macro arguments and macro-generated code. The changes improve code organization, reduce duplication, and update test expectations to reflect the new behavior.

  • Centralized macro expansion logic from MacroCallImpl and PathResolution into ElementImpl::MacroExpansion
  • Introduced isFromMacroExpansion() to exclude macro arguments from expansion checks
  • Updated queries to use the new predicate where appropriate
  • Added custom toString() for items with attribute macro expansions

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rust/ql/lib/codeql/rust/elements/internal/ElementImpl.qll Adds centralized MacroExpansion module with logic for classifying macro-related elements
rust/ql/lib/codeql/rust/elements/internal/AstNodeImpl.qll Updates isInMacroExpansion() and isFromMacroExpansion() to delegate to MacroExpansion module
rust/ql/lib/codeql/rust/elements/internal/MacroCallImpl.qll Removes isInMacroExpansion() and getATokenTreeNode() logic, now in ElementImpl
rust/ql/lib/codeql/rust/elements/internal/ItemImpl.qll Adds custom toString() for items with attribute macro expansions
rust/ql/lib/codeql/rust/elements/internal/LocatableImpl.qll Updates to use new getImmediatelyEnclosingMacroInvocation() helper
rust/ql/lib/codeql/rust/internal/PathResolution.qll Simplifies ItemNode constructor by removing supersededByAttributeMacroExpansion()
rust/ql/src/queries/unusedentities/UnusedValue.ql Updates to use isFromMacroExpansion() instead of isInMacroExpansion()
rust/ql/src/queries/unusedentities/UnreachableCode.ql Updates to use isFromMacroExpansion() instead of isInMacroExpansion()
rust/ql/src/queries/unusedentities/UnusedVariable.qll Adds TODO comment noting future migration to isFromMacroExpansion()
rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qll Simplifies itemAt() by removing unused inMacro parameter
rust/ql/test/library-tests/variables/variables.ql Updates to use isFromMacroExpansion() instead of isInMacroExpansion()
Test expectation files Updates expected test outputs to reflect deduplication and new behavior
.gitattributes and .generated.list Removes ItemImpl.qll from generated file list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

1 participant