transparent.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. struct DummyStruct;
  2. // Transparent struct tuple wrapping a struct.
  3. #[repr(transparent)]
  4. struct TransparentComplexWrappingStructTuple(DummyStruct);
  5. // Transparent struct tuple wrapping a primitive.
  6. #[repr(transparent)]
  7. struct TransparentPrimitiveWrappingStructTuple(u32);
  8. // Transparent structure wrapping a struct.
  9. #[repr(transparent)]
  10. struct TransparentComplexWrappingStructure { only_field: DummyStruct }
  11. // Transparent structure wrapping a primitive.
  12. #[repr(transparent)]
  13. struct TransparentPrimitiveWrappingStructure { only_field: u32 }
  14. // Transparent struct wrapper with a marker wrapping a struct.
  15. #[repr(transparent)]
  16. struct TransparentComplexWrapper<T> {
  17. only_non_zero_sized_field: DummyStruct,
  18. marker: PhantomData<T>,
  19. }
  20. // Transparent struct wrapper with a marker wrapping a primitive.
  21. #[repr(transparent)]
  22. struct TransparentPrimitiveWrapper<T> {
  23. only_non_zero_sized_field: u32,
  24. marker: PhantomData<T>,
  25. }
  26. // Associated constant declared before struct declaration.
  27. impl TransparentPrimitiveWithAssociatedConstants {
  28. pub const ZERO: TransparentPrimitiveWithAssociatedConstants = TransparentPrimitiveWithAssociatedConstants {
  29. bits: 0
  30. };
  31. }
  32. // Transparent structure wrapping a primitive with associated constants.
  33. #[repr(transparent)]
  34. struct TransparentPrimitiveWithAssociatedConstants { bits: u32 }
  35. // Associated constant declared after struct declaration.
  36. impl TransparentPrimitiveWithAssociatedConstants {
  37. pub const ONE: TransparentPrimitiveWithAssociatedConstants = TransparentPrimitiveWithAssociatedConstants {
  38. bits: 1
  39. };
  40. }
  41. enum EnumWithAssociatedConstantInImpl { A }
  42. impl EnumWithAssociatedConstantInImpl {
  43. pub const TEN: TransparentPrimitiveWrappingStructure = TransparentPrimitiveWrappingStructure { only_field: 10 };
  44. }
  45. #[no_mangle]
  46. pub extern "C" fn root(
  47. a: TransparentComplexWrappingStructTuple,
  48. b: TransparentPrimitiveWrappingStructTuple,
  49. c: TransparentComplexWrappingStructure,
  50. d: TransparentPrimitiveWrappingStructure,
  51. e: TransparentComplexWrapper<i32>,
  52. f: TransparentPrimitiveWrapper<i32>,
  53. g: TransparentPrimitiveWithAssociatedConstants,
  54. h: EnumWithAssociatedConstantInImpl,
  55. ) { }