Skip to content

Rust: expand attribute macros on AssocItem #19786

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

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

Conversation

redsun82
Copy link
Contributor

It turned out that #19334 was not covering the case of items in Impl or Trait blocks, because internally those are AssocItem instances rather than Item ones. This covers that case.

@Copilot Copilot AI review requested due to automatic review settings June 16, 2025 15:59
@redsun82 redsun82 requested a review from a team as a code owner June 16, 2025 15:59
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 16, 2025
Copy link
Contributor

@Copilot 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 generalizes attribute-macro expansions to both top-level Items and associated items (AssocItem) by introducing a new ExpandableItem type and wiring it through the schema, extractor, and QL libraries.

  • Introduce ExpandableItem in the AST schema and annotate both Item and AssocItem as bases
  • Update the DB scheme to define @expandable_item and replace the old item_attribute_macro_expansions relation
  • Enhance the Rust extractor (base.rs) to pre- and post-emit attribute expansions for AssocItem as well as Item

Reviewed Changes

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

Show a summary per file
File Description
rust/schema/prelude.py Adds new ExpandableItem ASTNode
rust/schema/annotations.py Annotates AssocItem & Item to inherit from ExpandableItem
rust/ql/lib/rust.dbscheme Defines @expandable_item, removes old relation, re-adds @assoc_item later
rust/ql/lib/codeql/rust/elements/ExpandableItem*.qll Generates public and internal QLL wrappers for ExpandableItem
rust/ql/lib/codeql/rust/elements/Item.qll & AssocItem.qll Switch imports to use ExpandableItem
rust/extractor/src/translate/base.rs Extends translator macros and methods to handle AssocItem expansions
rust/ql/integration-tests/macro-expansion Updates expected outputs and test fixtures for assoc-item expansions
rust/ql/lib/upgrades/.../upgrade.properties Adds upgrade to rename the expansion relation
rust/ql/lib/downgrades/.../downgrade.ql Provides downgrade path
Comments suppressed due to low confidence (1)

rust/extractor/src/translate/base.rs:708

  • The return type was changed to Option<Label<generated::MacroCall>>, but callers in the pre‐emit and post‐emit macros expect labels for Item or AssocItem. This mismatch may lead to compilation errors—consider restoring the original Label<generated::Item> return type or updating the macros to handle MacroCall labels explicitly.
pub(crate) fn prepare_item_expansion(

@redsun82 redsun82 requested a review from a team as a code owner June 17, 2025 08:18
@github-actions github-actions bot added the Swift label Jun 17, 2025
@redsun82 redsun82 added the no-change-note-required This PR does not need a change note label Jun 17, 2025
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 Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant