2020-08-21 01:04:36 +00:00
|
|
|
#![cfg(feature = "derive")]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2022-11-17 20:13:24 +00:00
|
|
|
use bytemuck::{ByteEq, ByteHash, Pod, TransparentWrapper, Zeroable};
|
2023-02-17 19:24:16 +00:00
|
|
|
use std::marker::PhantomData;
|
2020-08-21 01:04:36 +00:00
|
|
|
|
2022-11-17 20:13:24 +00:00
|
|
|
#[derive(Copy, Clone, Pod, Zeroable, ByteEq, ByteHash)]
|
2020-08-21 01:04:36 +00:00
|
|
|
#[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,
|
2021-03-29 05:11:13 +00:00
|
|
|
b: (),
|
|
|
|
}
|
2022-11-20 23:40:20 +00:00
|
|
|
|
|
|
|
#[derive(TransparentWrapper)]
|
|
|
|
#[repr(transparent)]
|
2023-02-17 19:24:16 +00:00
|
|
|
struct TransparentWithGeneric<T: ?Sized> {
|
2022-11-20 23:40:20 +00:00
|
|
|
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)]
|
2023-02-17 19:24:16 +00:00
|
|
|
struct TransparentWithGenericAndZeroSized<T: ?Sized> {
|
|
|
|
a: (),
|
|
|
|
b: T,
|
2022-11-20 23:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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)
|
|
|
|
}
|
2023-02-17 19:24:16 +00:00
|
|
|
|
|
|
|
#[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,
|
|
|
|
}
|