I'm writing a proc_macro_derive macro to target unit type enums.
I'm deriving darling::FromDeriveInput on my model struct, here named TargetEnum, using the #[darling(supports(enum_unit))] to validate the shape of the target, as follows:
#[derive(FromDeriveInput)]
#[darling(supports(enum_unit))]
struct TargetEnum {
ident: Ident,
data: Data<TargetVariant, ()>,
}
Attempting to derive on structs, named fields variants enums, tuple variants enums or newtype variants enums works as expected (clear error message + "Expected" hint), respectively1:
error: Unsupported shape `struct`. Expected enum with no fields.
--> src/main.rs:3:10
|
3 | #[derive(Variants)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Variants` (in Nightly builds, run with -Z macro-backtrace for more info)
error: Unsupported shape `named fields`. Expected no fields.
--> src/main.rs:3:10
|
3 | #[derive(Variants)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Variants` (in Nightly builds, run with -Z macro-backtrace for more info)
error: Unsupported shape `unnamed fields`. Expected no fields.
--> src/main.rs:3:10
|
3 | #[derive(Variants)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Variants` (in Nightly builds, run with -Z macro-backtrace for more info)
error: Unsupported shape `one unnamed field`. Expected no fields.
--> src/main.rs:3:10
|
3 | #[derive(Variants)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Variants` (in Nightly builds, run with -Z macro-backtrace for more info)
Now, I would like to grant downstream users with a clear error message even in the remote possibility they attempt to derive such macro on a unit type. However, the attempt results in the following, undescriptive panic:
error: proc-macro derive panicked
--> src/main.rs:3:10
|
3 | #[derive(Variants)]
| ^^^^^^^^
|
= help: message: internal error: entered unreachable code
Am I doing something wrong or is this to be considered a bug?
In doubt I'm opening a discussion rather than an issue.
P.S. Thank you for such useful library! Made my idea extremely simpler to implement.
Originally posted by @marcoradocchia in #364
I'm writing a
proc_macro_derivemacro to target unit typeenums.I'm deriving
darling::FromDeriveInputon my model struct, here namedTargetEnum, using the#[darling(supports(enum_unit))]to validate the shape of the target, as follows:Attempting to derive on
structs, named fields variantsenums, tuple variantsenumsor newtype variantsenums works as expected (clear error message + "Expected" hint), respectively1:Now, I would like to grant downstream users with a clear error message even in the remote possibility they attempt to derive such macro on a unit type. However, the attempt results in the following, undescriptive panic:
Am I doing something wrong or is this to be considered a bug?
In doubt I'm opening a discussion rather than an issue.
P.S. Thank you for such useful library! Made my idea extremely simpler to implement.
Originally posted by @marcoradocchia in #364
Footnotes
Variantsis my macro's name ↩