Skip to content

Error when #[entities] is on the wrong part #19445

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

Conversation

Bleachfuel
Copy link
Contributor

Objective

fixes #19346

Solution

Error when a attribute is on the variant, ideally we would want this not to error for variants with just one unnamed fied, but then we would need different functions for when doing it for components, or for doing it with the derive macro.

@Bleachfuel Bleachfuel changed the title error variant Error when #[entities] is on the wrong part May 30, 2025
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Macros Code that generates Rust code X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jun 2, 2025
Copy link
Contributor

@andriyDev andriyDev left a comment

Choose a reason for hiding this comment

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

Could we have a test in bevy_ecs/compile_fail to show that this check works? We already have a test in bevy_ecs that does this on enum variant fields.

if let Some(attr) = variant.attrs.iter().find(|a| a.path().is_ident(ENTITIES)) {
return Err(syn::Error::new(
attr.span(),
"`#[entities]` should be on the associated type, not on the variant.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of this message - it only applies for tuple variants. How about "entities should be on the fields in the enum variant, not on the variant"?

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Macros Code that generates Rust code D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[entities] should error when put on a enum variant
3 participants