Skip to content

Conversation

sakupan102
Copy link
Contributor

@sakupan102 sakupan102 commented Aug 1, 2025

To distinguish between items that are automatically generated by #[derive()] and those that aren't, I added a derived flag to Item.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add derived flag to Item.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_extern_block):
	Add derived flag to Item.
	* hir/rust-ast-lower-enumitem.h: Add derived flag to Item.
	* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit):
	Add derived flag to Item.
	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add derived flag to Item.
	* hir/tree/rust-hir-item.cc: Add derived flag to Item.
	* hir/tree/rust-hir-item.h: Add derived flag to Item.

Signed-off-by: Ryutaro Okada <[email protected]>
@philberty philberty requested review from CohenArthur, P-E-P and powerboat9 and removed request for CohenArthur August 1, 2025 09:56
@philberty philberty added the AST label Aug 1, 2025
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

This LGTM but lets see what @P-E-P and @CohenArthur say.

Another option to avoid changing the HIR could be to make a std::map<NodeId, bool AST::Item&

in the rust-mappings.h and during hir lowering you can look that up to determine if an ITEM was derived.

But yeah see what the guys think.

@powerboat9
Copy link
Collaborator

powerboat9 commented Aug 1, 2025

Why distinguish? Producing better errors for derive-generated code?

@P-E-P
Copy link
Member

P-E-P commented Aug 1, 2025

This LGTM but lets see what @P-E-P and @CohenArthur say.

Another option to avoid changing the HIR could be to make a std::map<NodeId, bool AST::Item&

in the rust-mappings.h and during hir lowering you can look that up to determine if an ITEM was derived.

But yeah see what the guys think.

A set instead of a map<NodeId, bool> would probably be better but I agree, this kind of informations should probably be kept outside of the AST.

@philberty
Copy link
Member

yeah sounds like if you need this flag then follow @P-E-P advice

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

change this to use a map and loop instead

@philberty philberty assigned sakupan102 and unassigned P-E-P and CohenArthur Aug 1, 2025
@CohenArthur
Copy link
Member

rustc adds the #[automatically_derived] attribute to the impls it creates, which is something we can consider as well. I'm not sure if the attribute is used for other things

@sakupan102
Copy link
Contributor Author

I will close this PR and create a new issue because the implementation is entirely different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants