Using derive(Adhoc) for internal purposes can leak your struct
Currently, the macro_rules
macro generated by #[derive(Adhoc)]
is always exported with #[macro_export]
.
This means that applying #[derive(Adhoc)]
to a pub struct
with private innards, produces a semver hazard: your callers cannot access your fields, but they can make other structs that mirror yours and then mess with their fields and possibly cause trouble. Also having the exported macro appear in your list of public items is probably not great either.
I suggest that the macro should be exported only when:
- The item the macro is applied to is itself
pub
, and: - The item is not marked
#[non_exhaustive]
(it is possible that this will work properly only if the attributes are in the proper order, but I don't think we can work around that if not) - For structs/unions: there are no non-
pub
fields. - In the future, if we support things other than structs/enums/unions, only those and traits will be exported.
There ought to be a way to override this. I suggest #[derive_adhoc(pub)]
, #[derive_adhoc(pub(self))]
, etc. That doesn't clash with #[derive_adhoc(ReuseableMacro)]
because no-one but a lunatic would call a reuseable macro pub
so we can totally forbid that.