Why are proc-macro derives prohibited for Unions?

I wrote a procedural macro for union types but noticed that custom deriving is allowed only for struct/enum.

Unions support some built-in derives, so it is reasonable to allow custom derives.
Is there any reason for this limitation?

error: proc-macro derives may only be applied to struct/enum items
  --> src/value.rs:48:10
   |
48 | #[derive(Still)]
   |          ^^^^^
1 Like

This looks 100% like an omission. I didn't find anything digging around the issue tracker, so I suggest raising an issue.

Thank you! I'll open an issue.

opened: https://github.com/rust-lang/rust/issues/50223

1 Like

Guess its down unsafe.

From pr (Quick scan seems to have been removed/replaced.)
+Since accessing union fields reliably requires extra knowledge, traits trying to
+do it (e.g. PartialEq) cannot be derived automatically.

1 Like

Yes, some traits cannot be implemented safely.

I want to create a derive to guarantee that all union fields implement a specific trait.
Such derives are safe for any unions because their fields are not accessed at run-time.