Skip to content

Reflect derive is broken on main for empty enums #18277

Closed
@eugineerd

Description

@eugineerd

Bevy version

Commit: ec822c8

What you did

#[derive(Reflect)]
enum Empty {}

What went wrong

cargo build:

error[E0277]: `!` does not implement `Reflect` so cannot be fully reflected
  --> examples/reflection/reflection.rs:51:10
   |
51 | #[derive(Reflect)]
   |          ^^^^^^^ the trait `bevy_reflect::Reflect` is not implemented for `!`
   |
   = note: consider annotating `!` with `#[derive(Reflect)]`
   = help: the following other types implement trait `bevy_reflect::Reflect`:
             &'static std::panic::Location<'static>
             &'static std::path::Path
             &'static str
             ()
             (A, B)
             (A, B, C)
             (A, B, C, D)
             (A, B, C, D, E)
           and 735 others
   = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information)
   = help: did you intend to use the type `()` here instead?
   = note: required for the cast from `Box<!>` to `Box<dyn bevy_reflect::Reflect>`
   = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)

rust-analayzer:

missing match arm: type `&Empty` is non-empty

Additional information

Seem that the problem is in this code generated by Reflect derive macro:

#[inline]
#[allow(
    unreachable_code,
    reason = "Ignored fields without a `clone` attribute will early-return with an error"
)]
fn reflect_clone(
    &self,
) -> ::core::result::Result<
    bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>,
    bevy_reflect::ReflectCloneError,
> {
    let this = self;
    ::core::result::Result::Ok(bevy_reflect::__macro_exports::alloc_utils::Box::new(
        match this {},
    ))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-BugAn unexpected or incorrect behaviorD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions