summaryrefslogtreecommitdiff
path: root/vendor/bytemuck/tests/derive.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/bytemuck/tests/derive.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/bytemuck/tests/derive.rs')
-rw-r--r--vendor/bytemuck/tests/derive.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/vendor/bytemuck/tests/derive.rs b/vendor/bytemuck/tests/derive.rs
new file mode 100644
index 0000000..1c6b10e
--- /dev/null
+++ b/vendor/bytemuck/tests/derive.rs
@@ -0,0 +1,77 @@
+#![cfg(feature = "derive")]
+#![allow(dead_code)]
+
+use bytemuck::{ByteEq, ByteHash, Pod, TransparentWrapper, Zeroable};
+use std::marker::PhantomData;
+
+#[derive(Copy, Clone, Pod, Zeroable, ByteEq, ByteHash)]
+#[repr(C)]
+struct Test {
+ a: u16,
+ b: u16,
+}
+
+#[derive(TransparentWrapper)]
+#[repr(transparent)]
+struct TransparentSingle {
+ a: u16,
+}
+
+#[derive(TransparentWrapper)]
+#[repr(transparent)]
+#[transparent(u16)]
+struct TransparentWithZeroSized {
+ a: u16,
+ b: (),
+}
+
+#[derive(TransparentWrapper)]
+#[repr(transparent)]
+struct TransparentWithGeneric<T: ?Sized> {
+ a: T,
+}
+
+/// Ensuring that no additional bounds are emitted.
+/// See https://github.com/Lokathor/bytemuck/issues/145
+fn test_generic<T>(x: T) -> TransparentWithGeneric<T> {
+ TransparentWithGeneric::wrap(x)
+}
+
+#[derive(TransparentWrapper)]
+#[repr(transparent)]
+#[transparent(T)]
+struct TransparentWithGenericAndZeroSized<T: ?Sized> {
+ a: (),
+ b: T,
+}
+
+/// Ensuring that no additional bounds are emitted.
+/// See https://github.com/Lokathor/bytemuck/issues/145
+fn test_generic_with_zst<T>(x: T) -> TransparentWithGenericAndZeroSized<T> {
+ TransparentWithGenericAndZeroSized::wrap(x)
+}
+
+#[derive(TransparentWrapper)]
+#[repr(transparent)]
+struct TransparentUnsized {
+ a: dyn std::fmt::Debug,
+}
+
+type DynDebug = dyn std::fmt::Debug;
+
+#[derive(TransparentWrapper)]
+#[repr(transparent)]
+#[transparent(DynDebug)]
+struct TransparentUnsizedWithZeroSized {
+ a: (),
+ b: DynDebug,
+}
+
+#[derive(TransparentWrapper)]
+#[repr(transparent)]
+#[transparent(DynDebug)]
+struct TransparentUnsizedWithGenericZeroSizeds<T: ?Sized, U: ?Sized> {
+ a: PhantomData<T>,
+ b: PhantomData<U>,
+ c: DynDebug,
+}