bevy/crates/bevy_macro_utils/src
Zachary Harrold 6963b58eba
Modify derive_label to support no_std environments (#15465)
# Objective

- Contributes to #15460

## Solution

- Wrap `derive_label` `quote!` in an anonymous constant which contains
an `extern crate alloc` statement, allowing use of the `alloc` namespace
even when a user has not brought in the crate themselves.

## Testing

- CI passed locally.

## Notes

We can't generate code that uses `::std::boxed::Box` in `no_std`
environments, but we also can't rely on `::alloc::boxed::Box` either,
since the user might not have declared `extern crate alloc`. To resolve
this, the generated code is wrapped in an anonymous constant which
contains the `extern crate alloc` invocation.

This does mean the macro is no longer hygienic against cases where the
user provides an alternate `alloc` crate, however I believe this is an
acceptable compromise.

Additionally, this crate itself doesn't need to be `no_std`, it just
needs to _generate_ `no_std` compatible code.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2024-09-27 20:23:26 +00:00
..
attrs.rs Moved fq_std from bevy_reflect_derive to bevy_macro_utils (#9956) 2023-10-02 00:22:57 +00:00
bevy_manifest.rs fix deprecations from toml_edit (#12421) 2024-03-11 17:53:38 +00:00
fq_std.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
label.rs Modify derive_label to support no_std environments (#15465) 2024-09-27 20:23:26 +00:00
lib.rs Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
shape.rs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
symbol.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00