Skip to content

Rust: expand derive macros #19824

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 9 commits into
base: main
Choose a base branch
from

Conversation

redsun82
Copy link
Contributor

No description provided.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 20, 2025
@@ -6,6 +6,7 @@
import codeql.files.FileSystem
import codeql.rust.elements.Abi
import codeql.rust.elements.Addressable
import codeql.rust.elements.Adt

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
codeql.rust.elements.Enum
.
Redundant import, the module is already imported inside
codeql.rust.elements.Struct
.
Redundant import, the module is already imported inside
codeql.rust.elements.Union
.
*/

private import internal.AdtImpl
import codeql.rust.elements.Item

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
codeql.rust.elements.MacroItems
.

private import internal.AdtImpl
import codeql.rust.elements.Item
import codeql.rust.elements.MacroItems

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
codeql.rust.elements.Item
.
"""
An ADT (Abstract Data Type) definition, such as `Struct`, `Enum`, or `Union`.
"""
derive_macro_expansions: list[MacroItems] | child | rust.detach
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see, perhaps we should remove

grammar.enums.retain(|x| x.name != "Adt");

@@ -2,6 +2,9 @@

from .prelude import *

class Adt(AstNode, ):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's already done in the annotations

@annotate(Adt, replace_bases={AstNode: Item})

@@ -2,6 +2,9 @@

from .prelude import *

class Adt(AstNode, ):
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! Your are changing things faster than I can review them ;-)

Comment on lines 47 to 50
(Struct, $self:ident, $node:ident, $label:ident) => {
$self.emit_derive_expansion($node, $label);
$self.extract_canonical_origin($node, $label.into());
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would a single block like this work?

    (Adt, $self:ident, $node:ident, $label:ident) => {
        $self.emit_derive_expansion($node, $label);
    };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, because the macro needs to exactly match the concrete type to kick in.

If we had trait specializations we could whip something up like that.

@redsun82 redsun82 marked this pull request as ready for review June 20, 2025 15:21
@redsun82 redsun82 requested review from a team as code owners June 20, 2025 15:21
aibaars
aibaars previously approved these changes Jun 20, 2025
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.

Looks good to me!

@aibaars aibaars force-pushed the redsun82/rust-derive-macro-expansion branch from 9f6e446 to f4bdd4d Compare June 20, 2025 17:32
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