-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: main
Are you sure you want to change the base?
Rust: expand derive macros #19824
Conversation
@@ -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
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
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
codeql.rust.elements.Item
""" | ||
An ADT (Abstract Data Type) definition, such as `Struct`, `Enum`, or `Union`. | ||
""" | ||
derive_macro_expansions: list[MacroItems] | child | rust.detach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not generated from the rust.ungram? https://github.com/rust-lang/rust-analyzer/blob/master/crates/syntax/rust.ungram#L278-L284
There was a problem hiding this comment.
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
codeql/rust/ast-generator/src/main.rs
Line 488 in 8c2bda3
grammar.enums.retain(|x| x.name != "Adt"); |
@@ -2,6 +2,9 @@ | |||
|
|||
from .prelude import * | |||
|
|||
class Adt(AstNode, ): |
There was a problem hiding this comment.
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
codeql/rust/schema/annotations.py
Line 19 in 52c0028
@annotate(Adt, replace_bases={AstNode: Item}) |
@@ -2,6 +2,9 @@ | |||
|
|||
from .prelude import * | |||
|
|||
class Adt(AstNode, ): |
There was a problem hiding this comment.
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 ;-)
(Struct, $self:ident, $node:ident, $label:ident) => { | ||
$self.emit_derive_expansion($node, $label); | ||
$self.extract_canonical_origin($node, $label.into()); | ||
}; |
There was a problem hiding this comment.
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);
};
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
9f6e446
to
f4bdd4d
Compare
No description provided.