-
Notifications
You must be signed in to change notification settings - Fork 791
Description
Seems like this has been discussed in various places, but I'm not sure if there's a single issue that tracks this. Feel free to close in favor of one of those.
In google/zerocopy#2982, we're adding a #[zerocopy(on_error = skip/fail)] attribute that would allow code to compile even if a type derives a trait which it can't implement, e.g.:
use zerocopy::*;
// Can't be `FromBytes` because `bool: !FromBytes`
#[derive(IntoBytes, FromBytes)]
#[zerocopy(on_error = skip)]
struct Foo(bool);This is especially useful in conjunction with bindgen. Many zerocopy users add zerocopy derives to bindgen-generated types, but need to jump through significant hoops (such as the hoops that Fuchsia jumps through) in order to avoid adding #[derive(Xxx)] on a type that can't support the trait being derived.
Once this attribute is supported, they can unconditionally add all zerocopy traits and add #[zerocopy(on_error = skip)] to ensure everything compiles regardless of which traits are supported.
Currently, bindgen doesn't support a flag to automatically add attributes to derived types, so this would have to be done as a post-processing step. It'd be great if such a flag were supported. Note that this is a soft blocker for the Linux kernel to be able to use zerocopy.