bevy/crates/bevy_reflect/derive/src
Nicholas Nethercote 1b4cf02fc8
bevy_reflect: streamline generated FromReflect::from_reflect (#19906)
# Objective

Generated `from_reflect` methods use closures in a weird way, e.g.:
```rust
    x: (|| {
        <f32 as ::bevy::reflect::FromReflect>::from_reflect(
            ::bevy::reflect::Struct::field(__ref_struct, "x")?,
        )   
    })()?,
```
The reason for this is because when `#[reflect(Default)]` is used, you
instead get stuff like this:
```rust
    if let ::core::option::Option::Some(__field) = (|| {
        <f32 as ::bevy::reflect::FromReflect>::from_reflect(
            ::bevy::reflect::Struct::field(__ref_struct, "x")?,
        )   
    })() {
        __this.x = __field;
    } 
```
and the closure is necessary to contain the scope of the `?`. But the
first case is more common.

Helps with #19873.

## Solution

Avoid the closure in the common case.

## Testing

I used cargo expand to confirm the closures are no longer produced in
the common case.

`-Zmacro-stats` output tells me this reduces the size of the `Reflect`
code produced for `bevy_ui` by 0.5%.
2025-07-02 14:59:20 +00:00
..
impls Avoid unnecessary ReflectMeta arguments (#19919) 2025-07-02 14:53:52 +00:00
attribute_parser.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
container_attributes.rs Address Lints in bevy_reflect (#18479) 2025-03-23 23:53:31 +00:00
custom_attributes.rs bevy_reflect: avoid useless with_{custom_attributes,docs} calls (#19875) 2025-06-30 23:29:24 +00:00
derive_data.rs Avoid unnecessary ReflectMeta arguments (#19919) 2025-07-02 14:53:52 +00:00
documentation.rs bevy_reflect: avoid useless with_{custom_attributes,docs} calls (#19875) 2025-06-30 23:29:24 +00:00
enum_utility.rs bevy_reflect: Reflection-based cloning (#13432) 2025-03-11 06:02:59 +00:00
field_attributes.rs bevy_reflect: Reflection-based cloning (#13432) 2025-03-11 06:02:59 +00:00
from_reflect.rs bevy_reflect: streamline generated FromReflect::from_reflect (#19906) 2025-07-02 14:59:20 +00:00
generics.rs Add no_std support to bevy_reflect (#16256) 2024-12-05 21:15:21 +00:00
ident.rs split bevy_reflect::derive::utilities into proper modules (#15354) 2024-09-22 14:24:14 +00:00
lib.rs bevy_reflect: Reflection-based cloning (#13432) 2025-03-11 06:02:59 +00:00
meta.rs Use one BevyManifest instance in proc macros (#16766) 2024-12-15 15:00:05 +00:00
reflect_opaque.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
registration.rs Avoid unnecessary ReflectMeta arguments (#19919) 2025-07-02 14:53:52 +00:00
remote.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
result_sifter.rs split bevy_reflect::derive::utilities into proper modules (#15354) 2024-09-22 14:24:14 +00:00
serialization.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
string_expr.rs bevy_reflect: Fix TypePath string concatenation (#18609) 2025-03-29 21:01:53 +00:00
struct_utility.rs bevy_reflect: Reflection-based cloning (#13432) 2025-03-11 06:02:59 +00:00
trait_reflection.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
type_path.rs Rename bevy_reflect_derive folder to derive (#13269) 2024-05-07 07:55:32 +00:00
where_clause_options.rs Avoid unnecessary ReflectMeta arguments (#19919) 2025-07-02 14:53:52 +00:00