Skip to content

Use absolute paths in procedural macros#23784

Merged
alice-i-cecile merged 6 commits intobevyengine:mainfrom
DavidCrossman:proc_macro_absolute_paths
May 4, 2026
Merged

Use absolute paths in procedural macros#23784
alice-i-cecile merged 6 commits intobevyengine:mainfrom
DavidCrossman:proc_macro_absolute_paths

Conversation

@DavidCrossman
Copy link
Copy Markdown
Contributor

Objective

Solution

  • Use absolute paths in all procedural macros.

Testing

  • Ran cargo run -p ci -- compile

Notes

  • I've qualified Vec as ::std::vec::Vec in the AsBindGroup derive because bevy_render requires std. If bevy_render supports no_std in the future, this will need to be changed to use the __macro_exports strategy used by bevy_ecs and bevy_reflect. Perhaps bevy_macro_utils itself could export no_std compatible paths for alloc types like Vec and Box to avoid repeating the same strategy in every crate which generates alloc types in macros.
  • I haven't used absolute paths for primitives (::core::primitive::bool vs bool) since even serde doesn't, but I can do so in this PR if desired.

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change D-Macros Code that generates Rust code labels Apr 13, 2026
Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I like the notion of this in general, but can you explain why the FQ types are better than the core types here? Shouldn't core always be available?

@alice-i-cecile alice-i-cecile added A-Cross-Cutting Impacts the entire engine 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 labels Apr 13, 2026
@DavidCrossman
Copy link
Copy Markdown
Contributor Author

DavidCrossman commented Apr 13, 2026

I like the notion of this in general, but can you explain why the FQ types are better than the core types here? Shouldn't core always be available?

I'm following the precedent set by bevy_reflect; it uses the FQ types whenever possible. I've used the FQ types in bevy_ecs and elsewhere for consistency.
Personally, I think the FQ types are a little nicer since ::core::... in quote! is noisy, and it's easy to forget the leading :: in the path. The FQ types expand to ::core::... anyway (they are never in the expanded code). However, I think that FQBox is problematic and should be removed/reworked since it expands to ::std::boxed::Box and can't be used in no_std. FQBox is currently unused in the codebase. If bevy_macro_utils had a __macro_exports module, then FQBox could expand to #bevy_macro_utils_path::__macro_exports::alloc_utils::Box, which would reduce a lot of noise in quote!s in bevy_ecs and bevy_reflect.

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Apr 29, 2026
Ok(quote! {
impl #impl_generics #bevy_asset_path::VisitAssetDependencies for #struct_name #type_generics #where_clause {
fn visit_dependencies(&self, #visit: &mut impl FnMut(#bevy_asset_path::UntypedAssetId)) {
fn visit_dependencies(&self, #visit: &mut impl ::core::ops::FnMut(#bevy_asset_path::UntypedAssetId)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it make sense to introduce an  FQFnMut  here, similar to other FQ types used elsewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what the policy should be for adding new FQ types; adding every type in core/std would be excessive, so just the ones we use? I added FQIterator and FQInto because they appeared a few times (Iterator 6 times, Into 9 times). I could add FQFnMut, since FnMut appears 3 times, but I would also need to add FQFn (appears once) and FQFnOnce (doesn't appear) for parity.

I'd like to keep changes to the fq_std module small in this PR, as the focus is fixing hygiene issues. I think the module could be improved (FQBox in particular) in a later PR focused on code quality.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 3, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 3, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch May 3, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 3, 2026
Merged via the queue into bevyengine:main with commit 242f512 May 4, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Cross-Cutting Impacts the entire engine C-Code-Quality A section of code that is hard to understand or change D-Macros Code that generates Rust code D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants