Skip to content
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

Better macro errors for get_struct_fields #17639

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

Conversation

ecoskey
Copy link
Contributor

@ecoskey ecoskey commented Feb 2, 2025

Objective

  • Currently, the error span for get_struct_field when encountering an enum or union points to the macro invocation, rather than the enum or union token. It also doesn't mention which macro reported the error.

Solution

  • Report the correct error span
  • Add parameter for passing in the name of the macro invocation

Testing

Bevy compiles fine with this change

Migration Guide

// before
let fields = get_struct_fields(&ast.data);

// after
let fields = get_struct_fields(&ast.data, "derive(Bundle)");

@ecoskey ecoskey added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Utils Utility functions and types S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Macros Code that generates Rust code D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Feb 2, 2025
/// `meta` should be the name of the macro calling this function.
pub fn get_struct_fields<'a>(
data: &'a Data,
meta: &str,
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't change much, but meta could be only the name of the trait being derived instead of derive{trait}

Copy link
Contributor Author

@ecoskey ecoskey Feb 2, 2025

Choose a reason for hiding this comment

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

This is meant to accomodate attribute macros, which don't fit the derive() pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Utils Utility functions and types 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-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants