Skip to content

Reflection of references is broken in bevy_reflect 0.17 #21282

@oliver-dew

Description

@oliver-dew

Minimal reproducible example: https://github.com/oliver-dew/ReflectMRE

Bevy version and features

  • bevy_reflect 0.17-rc.2

What you did

Previously, you could reflect a reference (see bevy0.16 tag in above repo):

/// Builds in bevy_reflect 0.16
#[derive(Reflect)]
struct A<'a> {
    b: &'a i32
}

What went wrong

In 0.17, the above does not build (see bevy0.17 tag in above repo). You get these errors:

error[E0277]: `&'a i32` does not implement `GetTypeRegistration` so cannot be registered for reflection
 --> src/lib.rs:6:8
  |
6 |     b: &'a i32
  |        ^^^^^^^ the trait `GetTypeRegistration` is not implemented for `&'a i32`
  |
  = note: consider annotating `&'a i32` with `#[derive(Reflect)]`
  = note: required for `&'a i32` to implement `RegisterForReflection`
help: consider removing the leading `&`-reference
  |
6 -     b: &'a i32
6 +     b: i32
  |

error[E0277]: `&'a i32` does not implement `Typed` so cannot provide static type information
  --> src/lib.rs:6:8
   |
6  |     b: &'a i32
   |        ^^^^^^^ the trait `Typed` is not implemented for `&'a i32`
   |
   = note: consider annotating `&'a i32` with `#[derive(Reflect)]`
   = note: required for `&'a i32` to implement `MaybeTyped`
note: required by a bound in `NamedField::new`
  --> /Users/oliverdew/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_reflect-0.17.0-rc.2/src/fields.rs:23:36
   |
23 |     pub fn new<T: PartialReflect + MaybeTyped + TypePath>(name: &'static str) -> Self {
   |                                    ^^^^^^^^^^ required by this bound in `NamedField::new`
help: consider removing the leading `&`-reference
   |
6  -     b: &'a i32
6  +     b: i32
   |

error[E0277]: `&'a i32` does not implement `PartialReflect` so cannot be introspected
 --> src/lib.rs:4:10
  |
4 | #[derive(Reflect)]
  |          ^^^^^^^ the trait `PartialReflect` is not implemented for `&'a i32`
  |
  = note: consider annotating `&'a i32` with `#[derive(Reflect)]`
  = help: the trait `PartialReflect` is implemented for `i32`
  = note: required for the cast from `&&'a i32` to `&dyn PartialReflect`
  = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `&'a i32` does not implement `PartialReflect` so cannot be introspected
 --> src/lib.rs:4:10
  |
4 | #[derive(Reflect)]
  |          ^^^^^^^ the trait `PartialReflect` is not implemented for `&'a i32`
  |
  = note: consider annotating `&'a i32` with `#[derive(Reflect)]`
  = help: the trait `PartialReflect` is implemented for `i32`
  = note: required for the cast from `&mut &'a i32` to `&mut (dyn PartialReflect + 'static)`
  = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `&i32` does not implement `PartialReflect` so cannot be introspected
 --> src/lib.rs:4:10
  |
4 | #[derive(Reflect)]
  |          ^^^^^^^ the trait `PartialReflect` is not implemented for `&i32`
  |
  = note: consider annotating `&i32` with `#[derive(Reflect)]`
  = help: the trait `PartialReflect` is implemented for `i32`
  = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `&'a i32` does not implement `PartialReflect` so cannot be introspected
 --> src/lib.rs:6:8
  |
6 |     b: &'a i32
  |        ^^^^^^^ the trait `PartialReflect` is not implemented for `&'a i32`
  |
  = note: consider annotating `&'a i32` with `#[derive(Reflect)]`
help: consider removing the leading `&`-reference
  |
6 -     b: &'a i32
6 +     b: i32
  |

error[E0277]: `&'a i32` does not implement `FromReflect` so cannot be created through reflection
 --> src/lib.rs:6:8
  |
6 |     b: &'a i32
  |        ^^^^^^^ the trait `FromReflect` is not implemented for `&'a i32`
  |
  = note: consider annotating `&'a i32` with `#[derive(Reflect)]`
help: consider removing the leading `&`-reference
  |
6 -     b: &'a i32
6 +     b: i32

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions