Skip to content

Remove ability to #[reflect(ignore)] enum variants #5983

@MrGVSV

Description

@MrGVSV

What problem does this solve or what need does it fill?

#4761 added the ability to reflect enums. With this, it also allowed for entire variants to be excluded from reflection using the #[reflect(ignore)] attribute. As mentioned in this comment, this can cause some problems.

Essentially, the code will panic if we try to call certain methods on an ignored variant.

#[derive(Reflect)]
enum Foo {
  #[reflect(ignore)]
  Bar
}

let value = Foo::Bar;

let name = Enum::variant_name(&value); // <-- PANIC!

What solution would you like?

Remove the ability to ignore entire variants (along with the relevant tests).

What alternative(s) have you considered?

Other solutions could be to:

  1. Allow ignored variants to be used by certain methods
  2. Return default-able values (Option<T> rather than T)
  3. Ignore only the fields within the variant, not the variant itself

Option 1 is probably the best, but now we break the reflection promise that the variant is ignored since we have to use and return its data.

Option 2 negatively affects ergonomics.

Option 3 is okay, but it's not obvious that we are ignoring the fields and not the variant itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions