Open NyxCode opened 4 months ago
As far as I can tell, the only attributes valid in this position are
#[cfg(..)]
and #[cfg_attr(..)]
Specifically, attribute-style proc macros are not allowed there.
Maybe this (removing all attributes except built-ins) is something syn's Generics::split_for_impl
should do?
This was proposed in https://github.com/dtolnay/syn/issues/422, but the issue was closed.
When the derive macros generate the
impl Serialize
andimpl Deserialize
, all attributes on generic parameters are preserved.Example:
results in
causing this error:
cannot find attribute 'some_helper_attribute' in this scope
This becomes a problem when
#[derive(Serialize)]
is used together with other derive macros which use helper attributes on generic parameters.In the example above,
#[some_helper_attribute]
is a helper attribute of the derive macroOtherMacro
.These helper attributes are preserved by serde, and copied into the
impl
block. There, they are outside of the context of the derive macroOtherMacro
, and cause a "cannot find attribute .. in this scope" error.