From 1d716e821a555772b2e7943b58b6cf4c65fa5625 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Mon, 26 Feb 2024 12:26:26 -0800 Subject: [PATCH] Make TryFromBytes a super-trait of FromZeros Makes progress on #5 --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a1182b3d18..93864c2e14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1427,7 +1427,7 @@ pub unsafe trait TryFromBytes { doc = concat!("[derive]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeros.html"), doc = concat!("[derive-analysis]: https://docs.rs/zerocopy/", env!("CARGO_PKG_VERSION"), "/zerocopy/derive.FromZeros.html#analysis"), )] -pub unsafe trait FromZeros { +pub unsafe trait FromZeros: TryFromBytes { // The `Self: Sized` bound makes it so that `FromZeros` is still object // safe. #[doc(hidden)] @@ -3703,8 +3703,10 @@ safety_comment! { /// /// `UnsafeCell`` has the same in-memory representation as its inner /// type `T`. - unsafe_impl!(T: ?Sized + FromZeros => FromZeros for UnsafeCell); - unsafe_impl!(T: ?Sized + FromBytes => FromBytes for UnsafeCell); + /// + /// TODO(#5): Implement `FromZeros` and `FromBytes` when `T: ?Sized`. + unsafe_impl!(T: FromZeros => FromZeros for UnsafeCell); + unsafe_impl!(T: FromBytes => FromBytes for UnsafeCell); unsafe_impl!(T: ?Sized + IntoBytes => IntoBytes for UnsafeCell); unsafe_impl!(T: ?Sized + Unaligned => Unaligned for UnsafeCell); assert_unaligned!(UnsafeCell<()>, UnsafeCell); @@ -7147,8 +7149,6 @@ mod tests { #[test] fn test_object_safety() { fn _takes_no_cell(_: &dyn NoCell) {} - fn _takes_from_zeros(_: &dyn FromZeros) {} - fn _takes_from_bytes(_: &dyn FromBytes) {} fn _takes_unaligned(_: &dyn Unaligned) {} }