-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when re-exporting bytemuck
and using derive macros
#93
Comments
https://github.com/Lokathor/bytemuck/blob/main/derive/src/traits.rs#L93 (and the similar methods on the other derives) seems to be the offender. They're always using I'm not super familiar with the derive code, but given that it's deriving unsafe traits i think the extra caution in the import path is probably appropriate. If someone can submit a PR to fix this without causing potential problems with other traits under the same name ending up derivable and leading to strange bugs I'm all for that. Otherwise I might just say that in this particular case people should just use the full import path to work around this problem. Safety beats ergonomics in this case. |
This is a known hard problem for proc-macros. I've been recently re-thinking about this, and here is the least-bad solution I can think of:
Another approach, more classic but imho more cumbersome for the 2nd-degree dependency, would be for This could even palliate a bit better the At that point the pub use ::middle_crate::bytemuck::{self, Zeroable};
#[derive(…, Zeroable)]
#[zeroable(unsafe { crate = bytemuck })]
// or
#[zeroable(unsafe { crate = ::middle_crate::bytemuck })]
struct Foo …
Footnotes
|
I re-export from one crate like this:
...and then import
Zeroable
andPod
from this re-exported location. Then I add#[derive(Clone, Copy, Debug, Default, Zeroable, Pod)]
This triggers a compiler error:
When I add
bytemuck
as a dependency directly, and useZeroable
andPod
from there, the error goes away. It seems that the internals of the derive macro can't handle an alternative export path?The text was updated successfully, but these errors were encountered: