html-to-markdown 2.24.1 → 2.24.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +9 -6
  3. data/ext/html-to-markdown-rb/native/Cargo.lock +13 -13
  4. data/ext/html-to-markdown-rb/native/Cargo.toml +1 -1
  5. data/lib/html_to_markdown/version.rb +1 -1
  6. data/rust-vendor/bytemuck/.cargo-checksum.json +1 -1
  7. data/rust-vendor/bytemuck/.cargo_vcs_info.json +1 -1
  8. data/rust-vendor/bytemuck/.github/workflows/rust.yml +4 -4
  9. data/rust-vendor/bytemuck/Cargo.lock +16 -9
  10. data/rust-vendor/bytemuck/Cargo.toml +6 -2
  11. data/rust-vendor/bytemuck/Cargo.toml.orig +7 -6
  12. data/rust-vendor/bytemuck/changelog.md +5 -0
  13. data/rust-vendor/bytemuck/src/must.rs +1 -1
  14. data/rust-vendor/bytemuck/src/pod.rs +13 -0
  15. data/rust-vendor/bytemuck/src/zeroable.rs +13 -0
  16. data/rust-vendor/bytemuck/src/zeroable_in_option.rs +2 -2
  17. data/rust-vendor/bytemuck/tests/std_tests.rs +1 -1
  18. data/rust-vendor/cc/.cargo-checksum.json +1 -1
  19. data/rust-vendor/cc/.cargo_vcs_info.json +1 -1
  20. data/rust-vendor/cc/CHANGELOG.md +8 -0
  21. data/rust-vendor/cc/Cargo.lock +3 -3
  22. data/rust-vendor/cc/Cargo.toml +2 -2
  23. data/rust-vendor/cc/Cargo.toml.orig +2 -2
  24. data/rust-vendor/cc/src/lib.rs +1 -0
  25. data/rust-vendor/cc/src/target/generated.rs +10 -0
  26. data/rust-vendor/find-msvc-tools/.cargo-checksum.json +1 -1
  27. data/rust-vendor/find-msvc-tools/.cargo_vcs_info.json +1 -1
  28. data/rust-vendor/find-msvc-tools/CHANGELOG.md +6 -0
  29. data/rust-vendor/find-msvc-tools/Cargo.lock +1 -1
  30. data/rust-vendor/find-msvc-tools/Cargo.toml +1 -1
  31. data/rust-vendor/find-msvc-tools/Cargo.toml.orig +1 -1
  32. data/rust-vendor/find-msvc-tools/src/find_tools.rs +55 -20
  33. data/rust-vendor/html-to-markdown-rs/src/converter/handlers/link.rs +1 -9
  34. data/rust-vendor/html-to-markdown-rs/src/converter/inline/link.rs +2 -11
  35. data/rust-vendor/html-to-markdown-rs/src/converter/list/definition.rs +30 -7
  36. data/rust-vendor/html-to-markdown-rs/src/converter/semantic/definition_list.rs +30 -7
  37. data/rust-vendor/html-to-markdown-rs/tests/issue_199_regressions.rs +15 -0
  38. data/rust-vendor/html-to-markdown-rs/tests/issue_200_regressions.rs +36 -0
  39. data/rust-vendor/zerocopy/.cargo-checksum.json +1 -1
  40. data/rust-vendor/zerocopy/.cargo_vcs_info.json +2 -1
  41. data/rust-vendor/zerocopy/Cargo.lock +3 -3
  42. data/rust-vendor/zerocopy/Cargo.toml +4 -4
  43. data/rust-vendor/zerocopy/Cargo.toml.orig +4 -4
  44. data/rust-vendor/zerocopy/src/doctests.rs +27 -0
  45. data/rust-vendor/zerocopy/src/error.rs +30 -0
  46. data/rust-vendor/zerocopy/src/layout.rs +239 -135
  47. data/rust-vendor/zerocopy/src/lib.rs +16 -0
  48. data/rust-vendor/zerocopy/src/macros.rs +255 -125
  49. data/rust-vendor/zerocopy/src/pointer/mod.rs +1 -1
  50. data/rust-vendor/zerocopy/src/pointer/ptr.rs +109 -23
  51. data/rust-vendor/zerocopy/src/util/macro_util.rs +344 -383
  52. data/rust-vendor/zerocopy/src/util/mod.rs +38 -0
  53. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-const.stderr +8 -0
  54. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr +10 -0
  55. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-unsized.stderr +11 -3
  56. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-mutable.stderr +10 -0
  57. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr +10 -0
  58. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr +10 -0
  59. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-unsized.stderr +11 -3
  60. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr +0 -10
  61. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-mutable.stderr +1 -1
  62. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +0 -10
  63. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.stderr +1 -11
  64. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-const.stderr +9 -0
  65. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr +10 -0
  66. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-unsized.stderr +16 -8
  67. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-mutable.stderr +10 -0
  68. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr +10 -0
  69. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr +10 -0
  70. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-unsized.stderr +16 -8
  71. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr +38 -38
  72. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +33 -33
  73. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.stderr +12 -12
  74. data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-const.stderr +9 -0
  75. data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr +10 -0
  76. data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-unsized.stderr +16 -8
  77. data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-mutable.stderr +10 -0
  78. data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr +10 -0
  79. data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-dst-not-references.stderr +10 -0
  80. data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-unsized.stderr +16 -8
  81. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr +38 -38
  82. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +33 -33
  83. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.stderr +12 -12
  84. data/rust-vendor/zerocopy-derive/.cargo-checksum.json +1 -1
  85. data/rust-vendor/zerocopy-derive/.cargo_vcs_info.json +1 -1
  86. data/rust-vendor/zerocopy-derive/Cargo.lock +1 -1
  87. data/rust-vendor/zerocopy-derive/Cargo.toml +1 -1
  88. data/rust-vendor/zerocopy-derive/Cargo.toml.orig +1 -1
  89. data/rust-vendor/zerocopy-derive/tests/ui-nightly/enum.stderr +3 -3
  90. data/rust-vendor/zerocopy-derive/tests/ui-nightly/struct.stderr +5 -5
  91. data/rust-vendor/zerocopy-derive/tests/ui-stable/enum.stderr +3 -3
  92. data/rust-vendor/zerocopy-derive/tests/ui-stable/struct.stderr +5 -5
  93. data/rust-vendor/zmij/.cargo-checksum.json +1 -1
  94. data/rust-vendor/zmij/.cargo_vcs_info.json +1 -1
  95. data/rust-vendor/zmij/Cargo.lock +16 -16
  96. data/rust-vendor/zmij/Cargo.toml +1 -1
  97. data/rust-vendor/zmij/Cargo.toml.orig +1 -1
  98. data/rust-vendor/zmij/README.md +1 -1
  99. data/rust-vendor/zmij/src/lib.rs +54 -93
  100. metadata +4 -50
  101. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-unsized.rs +0 -15
  102. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-unsized.stderr +0 -8
  103. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-unsized.rs +0 -15
  104. data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-unsized.stderr +0 -8
  105. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-alignment-increase.rs +0 -19
  106. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-alignment-increase.stderr +0 -9
  107. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-decrease.rs +0 -19
  108. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-decrease.stderr +0 -9
  109. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-increase.rs +0 -19
  110. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-increase.stderr +0 -17
  111. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-alignment-increase.rs +0 -18
  112. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-alignment-increase.stderr +0 -9
  113. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-decrease.rs +0 -18
  114. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-decrease.stderr +0 -9
  115. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-increase.rs +0 -18
  116. data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-increase.stderr +0 -9
  117. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-unsized.rs +0 -15
  118. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-unsized.stderr +0 -16
  119. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-unsized.rs +0 -15
  120. data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-unsized.stderr +0 -16
  121. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-alignment-increase.rs +0 -19
  122. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-alignment-increase.stderr +0 -9
  123. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-decrease.rs +0 -19
  124. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-decrease.stderr +0 -9
  125. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-increase.rs +0 -19
  126. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-increase.stderr +0 -17
  127. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-alignment-increase.rs +0 -18
  128. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-alignment-increase.stderr +0 -9
  129. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-decrease.rs +0 -18
  130. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-decrease.stderr +0 -9
  131. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-increase.rs +0 -18
  132. data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-increase.stderr +0 -9
  133. data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-unsized.rs +0 -15
  134. data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-unsized.stderr +0 -16
  135. data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-unsized.rs +0 -15
  136. data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-unsized.stderr +0 -16
  137. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-alignment-increase.rs +0 -19
  138. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-alignment-increase.stderr +0 -9
  139. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-decrease.rs +0 -19
  140. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-decrease.stderr +0 -9
  141. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-increase.rs +0 -19
  142. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-increase.stderr +0 -17
  143. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-alignment-increase.rs +0 -18
  144. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-alignment-increase.stderr +0 -9
  145. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-decrease.rs +0 -18
  146. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-decrease.stderr +0 -9
  147. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-increase.rs +0 -18
  148. data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-increase.stderr +0 -9
@@ -22,16 +22,13 @@
22
22
  #[cfg(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)]
23
23
  #[cfg(not(target_pointer_width = "16"))]
24
24
  use core::ptr::{self, NonNull};
25
- use core::{
26
- marker::PhantomData,
27
- mem::{self, ManuallyDrop},
28
- };
25
+ use core::{marker::PhantomData, mem, num::Wrapping};
29
26
 
30
27
  use crate::{
31
28
  pointer::{
32
29
  cast::CastSized,
33
30
  invariant::{Aligned, Initialized, Valid},
34
- BecauseInvariantsEq,
31
+ BecauseImmutable,
35
32
  },
36
33
  FromBytes, Immutable, IntoBytes, KnownLayout, Ptr, ReadOnly, TryFromBytes, ValidityError,
37
34
  };
@@ -82,48 +79,6 @@ impl<T: ?Sized> PaddingFree<T, 0> for () {}
82
79
  pub trait DynamicPaddingFree<T: ?Sized, const HAS_PADDING: bool> {}
83
80
  impl<T: ?Sized> DynamicPaddingFree<T, false> for () {}
84
81
 
85
- /// A type whose size is equal to `align_of::<T>()`.
86
- #[repr(C)]
87
- pub struct AlignOf<T> {
88
- // This field ensures that:
89
- // - The size is always at least 1 (the minimum possible alignment).
90
- // - If the alignment is greater than 1, Rust has to round up to the next
91
- // multiple of it in order to make sure that `Align`'s size is a multiple
92
- // of that alignment. Without this field, its size could be 0, which is a
93
- // valid multiple of any alignment.
94
- _u: u8,
95
- _a: [T; 0],
96
- }
97
-
98
- impl<T> AlignOf<T> {
99
- #[inline(never)] // Make `missing_inline_in_public_items` happy.
100
- #[cfg_attr(
101
- all(coverage_nightly, __ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS),
102
- coverage(off)
103
- )]
104
- pub fn into_t(self) -> T {
105
- unreachable!()
106
- }
107
- }
108
-
109
- /// A type whose size is equal to `max(align_of::<T>(), align_of::<U>())`.
110
- #[repr(C)]
111
- pub union MaxAlignsOf<T, U> {
112
- _t: ManuallyDrop<AlignOf<T>>,
113
- _u: ManuallyDrop<AlignOf<U>>,
114
- }
115
-
116
- impl<T, U> MaxAlignsOf<T, U> {
117
- #[inline(never)] // Make `missing_inline_in_public_items` happy.
118
- #[cfg_attr(
119
- all(coverage_nightly, __ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS),
120
- coverage(off)
121
- )]
122
- pub fn new(_t: T, _u: U) -> MaxAlignsOf<T, U> {
123
- unreachable!()
124
- }
125
- }
126
-
127
82
  #[cfg(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)]
128
83
  #[cfg(not(target_pointer_width = "16"))]
129
84
  const _64K: usize = 1 << 16;
@@ -471,66 +426,6 @@ macro_rules! enum_padding {
471
426
  }};
472
427
  }
473
428
 
474
- /// Does `t` have alignment greater than or equal to `u`? If not, this macro
475
- /// produces a compile error. It must be invoked in a dead codepath. This is
476
- /// used in `transmute_ref!` and `transmute_mut!`.
477
- #[doc(hidden)] // `#[macro_export]` bypasses this module's `#[doc(hidden)]`.
478
- #[macro_export]
479
- macro_rules! assert_align_gt_eq {
480
- ($t:ident, $u: ident) => {{
481
- // The comments here should be read in the context of this macro's
482
- // invocations in `transmute_ref!` and `transmute_mut!`.
483
- if false {
484
- // The type wildcard in this bound is inferred to be `T` because
485
- // `align_of.into_t()` is assigned to `t` (which has type `T`).
486
- let align_of: $crate::util::macro_util::AlignOf<_> = unreachable!();
487
- $t = align_of.into_t();
488
- // `max_aligns` is inferred to have type `MaxAlignsOf<T, U>` because
489
- // of the inferred types of `t` and `u`.
490
- let mut max_aligns = $crate::util::macro_util::MaxAlignsOf::new($t, $u);
491
-
492
- // This transmute will only compile successfully if
493
- // `align_of::<T>() == max(align_of::<T>(), align_of::<U>())` - in
494
- // other words, if `align_of::<T>() >= align_of::<U>()`.
495
- //
496
- // SAFETY: This code is never run.
497
- max_aligns = unsafe {
498
- // Clippy: We can't annotate the types; this macro is designed
499
- // to infer the types from the calling context.
500
- #[allow(clippy::missing_transmute_annotations)]
501
- $crate::util::macro_util::core_reexport::mem::transmute(align_of)
502
- };
503
- } else {
504
- loop {}
505
- }
506
- }};
507
- }
508
-
509
- /// Do `t` and `u` have the same size? If not, this macro produces a compile
510
- /// error. It must be invoked in a dead codepath. This is used in
511
- /// `transmute_ref!` and `transmute_mut!`.
512
- #[doc(hidden)] // `#[macro_export]` bypasses this module's `#[doc(hidden)]`.
513
- #[macro_export]
514
- macro_rules! assert_size_eq {
515
- ($t:ident, $u: ident) => {{
516
- // The comments here should be read in the context of this macro's
517
- // invocations in `transmute_ref!` and `transmute_mut!`.
518
- if false {
519
- // SAFETY: This code is never run.
520
- $u = unsafe {
521
- // Clippy:
522
- // - It's okay to transmute a type to itself.
523
- // - We can't annotate the types; this macro is designed to
524
- // infer the types from the calling context.
525
- #[allow(clippy::useless_transmute, clippy::missing_transmute_annotations)]
526
- $crate::util::macro_util::core_reexport::mem::transmute($t)
527
- };
528
- } else {
529
- loop {}
530
- }
531
- }};
532
- }
533
-
534
429
  /// Unwraps an infallible `Result`.
535
430
  #[doc(hidden)]
536
431
  #[macro_export]
@@ -646,92 +541,126 @@ where
646
541
  }
647
542
  }
648
543
 
649
- /// Attempts to transmute `&Src` into `&Dst`.
650
- ///
651
- /// A helper for `try_transmute_ref!`.
652
- ///
653
- /// # Panics
654
- ///
655
- /// `try_transmute_ref` may either produce a post-monomorphization error or a
656
- /// panic if `Dst` is bigger or has a stricter alignment requirement than `Src`.
657
- /// Otherwise, `try_transmute_ref` panics under the same circumstances as
658
- /// [`is_bit_valid`].
659
- ///
660
- /// [`is_bit_valid`]: TryFromBytes::is_bit_valid
661
- #[inline(always)]
662
- pub fn try_transmute_ref<Src, Dst>(src: &Src) -> Result<&Dst, ValidityError<&Src, Dst>>
544
+ /// See `try_transmute_ref!` documentation.
545
+ pub trait TryTransmuteRefDst<'a> {
546
+ type Dst: ?Sized;
547
+
548
+ /// See `try_transmute_ref!` documentation.
549
+ fn try_transmute_ref(self) -> Result<&'a Self::Dst, ValidityError<&'a Self::Src, Self::Dst>>
550
+ where
551
+ Self: TryTransmuteRefSrc<'a>,
552
+ Self::Src: IntoBytes + Immutable + KnownLayout,
553
+ Self::Dst: TryFromBytes + Immutable + KnownLayout;
554
+ }
555
+
556
+ pub trait TryTransmuteRefSrc<'a> {
557
+ type Src: ?Sized;
558
+ }
559
+
560
+ impl<'a, Src, Dst> TryTransmuteRefSrc<'a> for Wrap<&'a Src, &'a Dst>
663
561
  where
664
- Src: IntoBytes + Immutable,
665
- Dst: TryFromBytes + Immutable,
562
+ Src: ?Sized,
563
+ Dst: ?Sized,
666
564
  {
667
- let ptr = Ptr::from_ref(src);
668
- let ptr = ptr.recall_validity::<Initialized, _>();
669
- let ptr = ptr.cast::<_, CastSized, _>();
670
- match ptr.try_into_valid() {
671
- Ok(ptr) => {
672
- static_assert!(Src, Dst => mem::align_of::<Dst>() <= mem::align_of::<Src>());
673
- // SAFETY: We have checked that `Dst` does not have a stricter
674
- // alignment requirement than `Src`.
675
- let ptr = unsafe { ptr.assume_alignment::<Aligned>() };
676
- Ok(ptr.as_ref())
565
+ type Src = Src;
566
+ }
567
+
568
+ impl<'a, Src, Dst> TryTransmuteRefDst<'a> for Wrap<&'a Src, &'a Dst>
569
+ where
570
+ Src: IntoBytes + Immutable + KnownLayout + ?Sized,
571
+ Dst: TryFromBytes + Immutable + KnownLayout + ?Sized,
572
+ {
573
+ type Dst = Dst;
574
+
575
+ #[inline(always)]
576
+ fn try_transmute_ref(
577
+ self,
578
+ ) -> Result<
579
+ &'a Dst,
580
+ ValidityError<&'a <Wrap<&'a Src, &'a Dst> as TryTransmuteRefSrc<'a>>::Src, Dst>,
581
+ > {
582
+ let ptr = Ptr::from_ref(self.0);
583
+ #[rustfmt::skip]
584
+ let res = ptr.try_with(#[inline(always)] |ptr| {
585
+ let ptr = ptr.recall_validity::<Initialized, _>();
586
+ let ptr = ptr.cast::<_, crate::layout::CastFrom<Dst>, _>();
587
+ ptr.try_into_valid()
588
+ });
589
+ match res {
590
+ Ok(ptr) => {
591
+ static_assert!(Src: ?Sized + KnownLayout, Dst: ?Sized + KnownLayout => {
592
+ Src::LAYOUT.align.get() >= Dst::LAYOUT.align.get()
593
+ }, "cannot transmute reference when destination type has higher alignment than source type");
594
+ // SAFETY: We have checked that `Dst` does not have a stricter
595
+ // alignment requirement than `Src`.
596
+ let ptr = unsafe { ptr.assume_alignment::<Aligned>() };
597
+ Ok(ptr.as_ref())
598
+ }
599
+ Err(err) => Err(err.map_src(Ptr::as_ref)),
677
600
  }
678
- Err(err) => Err(err.map_src(|ptr| {
679
- let ptr = ptr.cast::<_, CastSized, _>();
680
- // SAFETY: `ptr` has the same address as `src: &Src`, which is
681
- // aligned by invariant on `&Src`.
682
- let ptr = unsafe { ptr.assume_alignment::<Aligned>() };
683
- // SAFETY: Because `Src: Immutable` and we create a `Ptr` via
684
- // `Ptr::from_ref`, the resulting `Ptr` is a shared-and-`Immutable`
685
- // `Ptr`, which does not permit mutation of its referent. Therefore,
686
- // no mutation could have happened during the call to
687
- // `try_into_valid` (any such mutation would be unsound).
688
- //
689
- // `try_into_valid` promises to return its original argument, and
690
- // so we know that we are getting back the same `ptr` that we
691
- // originally passed, and that `ptr` was a bit-valid `Src`.
692
- let ptr = unsafe { ptr.assume_valid() };
693
- ptr.as_ref()
694
- })),
695
601
  }
696
602
  }
697
603
 
698
- /// Attempts to transmute `&mut Src` into `&mut Dst`.
699
- ///
700
- /// A helper for `try_transmute_mut!`.
701
- ///
702
- /// # Panics
703
- ///
704
- /// `try_transmute_mut` may either produce a post-monomorphization error or a
705
- /// panic if `Dst` is bigger or has a stricter alignment requirement than `Src`.
706
- /// Otherwise, `try_transmute_mut` panics under the same circumstances as
707
- /// [`is_bit_valid`].
708
- ///
709
- /// [`is_bit_valid`]: TryFromBytes::is_bit_valid
710
- #[inline(always)]
711
- pub fn try_transmute_mut<Src, Dst>(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>>
604
+ pub trait TryTransmuteMutDst<'a> {
605
+ type Dst: ?Sized;
606
+
607
+ /// See `try_transmute_mut!` documentation.
608
+ fn try_transmute_mut(
609
+ self,
610
+ ) -> Result<&'a mut Self::Dst, ValidityError<&'a mut Self::Src, Self::Dst>>
611
+ where
612
+ Self: TryTransmuteMutSrc<'a>,
613
+ Self::Src: IntoBytes,
614
+ Self::Dst: TryFromBytes;
615
+ }
616
+
617
+ pub trait TryTransmuteMutSrc<'a> {
618
+ type Src: ?Sized;
619
+ }
620
+
621
+ impl<'a, Src, Dst> TryTransmuteMutSrc<'a> for Wrap<&'a mut Src, &'a mut Dst>
712
622
  where
713
- Src: FromBytes + IntoBytes,
714
- Dst: TryFromBytes + IntoBytes,
623
+ Src: ?Sized,
624
+ Dst: ?Sized,
715
625
  {
716
- let ptr = Ptr::from_mut(src);
717
- let ptr = ptr.recall_validity::<Initialized, (_, (_, _))>();
718
- let ptr = ptr.cast::<_, CastSized, _>();
719
- match ptr.try_into_valid() {
720
- Ok(ptr) => {
721
- static_assert!(Src, Dst => mem::align_of::<Dst>() <= mem::align_of::<Src>());
722
- // SAFETY: We have checked that `Dst` does not have a stricter
723
- // alignment requirement than `Src`.
724
- let ptr = unsafe { ptr.assume_alignment::<Aligned>() };
725
- Ok(ptr.as_mut())
726
- }
727
- Err(err) => {
728
- Err(err.map_src(|ptr| {
729
- let ptr = ptr.cast::<_, CastSized, _>();
730
- // SAFETY: `ptr` has the same address as `src: &mut Src`, which
731
- // is aligned by invariant on `&mut Src`.
626
+ type Src = Src;
627
+ }
628
+
629
+ impl<'a, Src, Dst> TryTransmuteMutDst<'a> for Wrap<&'a mut Src, &'a mut Dst>
630
+ where
631
+ Src: FromBytes + IntoBytes + KnownLayout + ?Sized,
632
+ Dst: TryFromBytes + IntoBytes + KnownLayout + ?Sized,
633
+ {
634
+ type Dst = Dst;
635
+
636
+ #[inline(always)]
637
+ fn try_transmute_mut(
638
+ self,
639
+ ) -> Result<
640
+ &'a mut Dst,
641
+ ValidityError<&'a mut <Wrap<&'a mut Src, &'a mut Dst> as TryTransmuteMutSrc<'a>>::Src, Dst>,
642
+ > {
643
+ let ptr = Ptr::from_mut(self.0);
644
+ // SAFETY: The provided closure returns the only copy of `ptr`.
645
+ #[rustfmt::skip]
646
+ let res = unsafe {
647
+ ptr.try_with_unchecked(#[inline(always)] |ptr| {
648
+ let ptr = ptr.recall_validity::<Initialized, (_, (_, _))>();
649
+ let ptr = ptr.cast::<_, crate::layout::CastFrom<Dst>, _>();
650
+ ptr.try_into_valid()
651
+ })
652
+ };
653
+ match res {
654
+ Ok(ptr) => {
655
+ static_assert!(Src: ?Sized + KnownLayout, Dst: ?Sized + KnownLayout => {
656
+ Src::LAYOUT.align.get() >= Dst::LAYOUT.align.get()
657
+ }, "cannot transmute reference when destination type has higher alignment than source type");
658
+ // SAFETY: We have checked that `Dst` does not have a stricter
659
+ // alignment requirement than `Src`.
732
660
  let ptr = unsafe { ptr.assume_alignment::<Aligned>() };
733
- ptr.recall_validity::<_, (_, BecauseInvariantsEq)>().as_mut()
734
- }))
661
+ Ok(ptr.as_mut())
662
+ }
663
+ Err(err) => Err(err.map_src(Ptr::as_mut)),
735
664
  }
736
665
  }
737
666
  }
@@ -756,6 +685,17 @@ impl<Src, Dst> Wrap<Src, Dst> {
756
685
  }
757
686
  }
758
687
 
688
+ impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst>
689
+ where
690
+ Src: ?Sized,
691
+ Dst: ?Sized,
692
+ {
693
+ #[allow(clippy::must_use_candidate, clippy::missing_inline_in_public_items, clippy::empty_loop)]
694
+ pub const fn transmute_ref_inference_helper(self) -> &'a Dst {
695
+ loop {}
696
+ }
697
+ }
698
+
759
699
  impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst> {
760
700
  /// # Safety
761
701
  /// The caller must guarantee that:
@@ -794,6 +734,46 @@ impl<'a, Src, Dst> Wrap<&'a Src, &'a Dst> {
794
734
  mem::transmute(dst)
795
735
  }
796
736
  }
737
+
738
+ #[inline(always)]
739
+ pub fn try_transmute_ref(self) -> Result<&'a Dst, ValidityError<&'a Src, Dst>>
740
+ where
741
+ Src: IntoBytes + Immutable,
742
+ Dst: TryFromBytes + Immutable,
743
+ {
744
+ static_assert!(Src => mem::align_of::<Src>() == mem::align_of::<Wrapping<Src>>());
745
+ static_assert!(Dst => mem::align_of::<Dst>() == mem::align_of::<Wrapping<Dst>>());
746
+
747
+ // SAFETY: By the preceding assert, `Src` and `Wrapping<Src>` have the
748
+ // same alignment.
749
+ let src: &Wrapping<Src> =
750
+ unsafe { crate::util::transmute_ref::<_, _, BecauseImmutable>(self.0) };
751
+ let src = Wrap::new(src);
752
+ <Wrap<&'a Wrapping<Src>, &'a Wrapping<Dst>> as TryTransmuteRefDst<'a>>::try_transmute_ref(
753
+ src,
754
+ )
755
+ // SAFETY: By the preceding assert, `Dst` and `Wrapping<Dst>` have the
756
+ // same alignment.
757
+ .map(|dst| unsafe { crate::util::transmute_ref::<_, _, BecauseImmutable>(dst) })
758
+ .map_err(|err| {
759
+ // SAFETY: By the preceding assert, `Src` and `Wrapping<Src>` have the
760
+ // same alignment.
761
+ ValidityError::new(unsafe {
762
+ crate::util::transmute_ref::<_, _, BecauseImmutable>(err.into_src())
763
+ })
764
+ })
765
+ }
766
+ }
767
+
768
+ impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst>
769
+ where
770
+ Src: ?Sized,
771
+ Dst: ?Sized,
772
+ {
773
+ #[allow(clippy::must_use_candidate, clippy::missing_inline_in_public_items, clippy::empty_loop)]
774
+ pub fn transmute_mut_inference_helper(self) -> &'a mut Dst {
775
+ loop {}
776
+ }
797
777
  }
798
778
 
799
779
  impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst> {
@@ -828,6 +808,34 @@ impl<'a, Src, Dst> Wrap<&'a mut Src, &'a mut Dst> {
828
808
  // lifetime thanks to the lifetime bounds on this function.
829
809
  unsafe { &mut *dst }
830
810
  }
811
+
812
+ #[inline(always)]
813
+ pub fn try_transmute_mut(self) -> Result<&'a mut Dst, ValidityError<&'a mut Src, Dst>>
814
+ where
815
+ Src: FromBytes + IntoBytes,
816
+ Dst: TryFromBytes + IntoBytes,
817
+ {
818
+ static_assert!(Src => mem::align_of::<Src>() == mem::align_of::<Wrapping<Src>>());
819
+ static_assert!(Dst => mem::align_of::<Dst>() == mem::align_of::<Wrapping<Dst>>());
820
+
821
+ // SAFETY: By the preceding assert, `Src` and `Wrapping<Src>` have the
822
+ // same alignment.
823
+ let src: &mut Wrapping<Src> =
824
+ unsafe { crate::util::transmute_mut::<_, _, (_, (_, _))>(self.0) };
825
+ let src = Wrap::new(src);
826
+ <Wrap<&'a mut Wrapping<Src>, &'a mut Wrapping<Dst>> as TryTransmuteMutDst<'a>>
827
+ ::try_transmute_mut(src)
828
+ // SAFETY: By the preceding assert, `Dst` and `Wrapping<Dst>` have the
829
+ // same alignment.
830
+ .map(|dst| unsafe { crate::util::transmute_mut::<_, _, (_, (_, _))>(dst) })
831
+ .map_err(|err| {
832
+ // SAFETY: By the preceding assert, `Src` and `Wrapping<Src>` have the
833
+ // same alignment.
834
+ ValidityError::new(unsafe {
835
+ crate::util::transmute_mut::<_, _, (_, (_, _))>(err.into_src())
836
+ })
837
+ })
838
+ }
831
839
  }
832
840
 
833
841
  pub trait TransmuteRefDst<'a> {
@@ -839,7 +847,7 @@ pub trait TransmuteRefDst<'a> {
839
847
 
840
848
  impl<'a, Src: ?Sized, Dst: ?Sized> TransmuteRefDst<'a> for Wrap<&'a Src, &'a Dst>
841
849
  where
842
- Src: KnownLayout<PointerMetadata = usize> + IntoBytes + Immutable,
850
+ Src: KnownLayout + IntoBytes + Immutable,
843
851
  Dst: KnownLayout<PointerMetadata = usize> + FromBytes + Immutable,
844
852
  {
845
853
  type Dst = Dst;
@@ -872,7 +880,7 @@ pub trait TransmuteMutDst<'a> {
872
880
 
873
881
  impl<'a, Src: ?Sized, Dst: ?Sized> TransmuteMutDst<'a> for Wrap<&'a mut Src, &'a mut Dst>
874
882
  where
875
- Src: KnownLayout<PointerMetadata = usize> + FromBytes + IntoBytes,
883
+ Src: KnownLayout + FromBytes + IntoBytes,
876
884
  Dst: KnownLayout<PointerMetadata = usize> + FromBytes + IntoBytes,
877
885
  {
878
886
  type Dst = Dst;
@@ -919,210 +927,163 @@ pub mod core_reexport {
919
927
 
920
928
  #[cfg(test)]
921
929
  mod tests {
922
- use super::*;
923
930
  use crate::util::testutil::*;
924
931
 
925
- #[test]
926
- fn test_align_of() {
927
- macro_rules! test {
928
- ($ty:ty) => {
929
- assert_eq!(mem::size_of::<AlignOf<$ty>>(), mem::align_of::<$ty>());
930
- };
931
- }
932
-
933
- test!(());
934
- test!(u8);
935
- test!(AU64);
936
- test!([AU64; 2]);
937
- }
938
-
939
- #[test]
940
- fn test_max_aligns_of() {
941
- macro_rules! test {
942
- ($t:ty, $u:ty) => {
943
- assert_eq!(
944
- mem::size_of::<MaxAlignsOf<$t, $u>>(),
945
- core::cmp::max(mem::align_of::<$t>(), mem::align_of::<$u>())
946
- );
947
- };
948
- }
949
-
950
- test!(u8, u8);
951
- test!(u8, AU64);
952
- test!(AU64, u8);
953
- }
954
-
955
- #[test]
956
- fn test_typed_align_check() {
957
- // Test that the type-based alignment check used in
958
- // `assert_align_gt_eq!` behaves as expected.
959
-
960
- macro_rules! assert_t_align_gteq_u_align {
961
- ($t:ty, $u:ty, $gteq:expr) => {
962
- assert_eq!(
963
- mem::size_of::<MaxAlignsOf<$t, $u>>() == mem::size_of::<AlignOf<$t>>(),
964
- $gteq
965
- );
966
- };
967
- }
968
-
969
- assert_t_align_gteq_u_align!(u8, u8, true);
970
- assert_t_align_gteq_u_align!(AU64, AU64, true);
971
- assert_t_align_gteq_u_align!(AU64, u8, true);
972
- assert_t_align_gteq_u_align!(u8, AU64, false);
973
- }
974
-
975
- // FIXME(#29), FIXME(https://github.com/rust-lang/rust/issues/69835): Remove
976
- // this `cfg` when `size_of_val_raw` is stabilized.
977
- #[allow(clippy::decimal_literal_representation)]
978
932
  #[cfg(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)]
979
- #[test]
980
- fn test_trailing_field_offset() {
981
- assert_eq!(mem::align_of::<Aligned64kAllocation>(), _64K);
933
+ mod nightly {
934
+ use super::super::*;
935
+ use crate::util::testutil::*;
936
+
937
+ // FIXME(#29), FIXME(https://github.com/rust-lang/rust/issues/69835):
938
+ // Remove this `cfg` when `size_of_val_raw` is stabilized.
939
+ #[allow(clippy::decimal_literal_representation)]
940
+ #[test]
941
+ fn test_trailing_field_offset() {
942
+ assert_eq!(mem::align_of::<Aligned64kAllocation>(), _64K);
943
+
944
+ macro_rules! test {
945
+ (#[$cfg:meta] ($($ts:ty),* ; $trailing_field_ty:ty) => $expect:expr) => {{
946
+ #[$cfg]
947
+ struct Test($(#[allow(dead_code)] $ts,)* #[allow(dead_code)] $trailing_field_ty);
948
+ assert_eq!(test!(@offset $($ts),* ; $trailing_field_ty), $expect);
949
+ }};
950
+ (#[$cfg:meta] $(#[$cfgs:meta])* ($($ts:ty),* ; $trailing_field_ty:ty) => $expect:expr) => {
951
+ test!(#[$cfg] ($($ts),* ; $trailing_field_ty) => $expect);
952
+ test!($(#[$cfgs])* ($($ts),* ; $trailing_field_ty) => $expect);
953
+ };
954
+ (@offset ; $_trailing:ty) => { trailing_field_offset!(Test, 0) };
955
+ (@offset $_t:ty ; $_trailing:ty) => { trailing_field_offset!(Test, 1) };
956
+ }
982
957
 
983
- macro_rules! test {
984
- (#[$cfg:meta] ($($ts:ty),* ; $trailing_field_ty:ty) => $expect:expr) => {{
985
- #[$cfg]
986
- struct Test($(#[allow(dead_code)] $ts,)* #[allow(dead_code)] $trailing_field_ty);
987
- assert_eq!(test!(@offset $($ts),* ; $trailing_field_ty), $expect);
988
- }};
989
- (#[$cfg:meta] $(#[$cfgs:meta])* ($($ts:ty),* ; $trailing_field_ty:ty) => $expect:expr) => {
990
- test!(#[$cfg] ($($ts),* ; $trailing_field_ty) => $expect);
991
- test!($(#[$cfgs])* ($($ts),* ; $trailing_field_ty) => $expect);
992
- };
993
- (@offset ; $_trailing:ty) => { trailing_field_offset!(Test, 0) };
994
- (@offset $_t:ty ; $_trailing:ty) => { trailing_field_offset!(Test, 1) };
995
- }
958
+ test!(#[repr(C)] #[repr(transparent)] #[repr(packed)](; u8) => Some(0));
959
+ test!(#[repr(C)] #[repr(transparent)] #[repr(packed)](; [u8]) => Some(0));
960
+ test!(#[repr(C)] #[repr(C, packed)] (u8; u8) => Some(1));
961
+ test!(#[repr(C)] (; AU64) => Some(0));
962
+ test!(#[repr(C)] (; [AU64]) => Some(0));
963
+ test!(#[repr(C)] (u8; AU64) => Some(8));
964
+ test!(#[repr(C)] (u8; [AU64]) => Some(8));
965
+
966
+ #[derive(
967
+ Immutable, FromBytes, Eq, PartialEq, Ord, PartialOrd, Default, Debug, Copy, Clone,
968
+ )]
969
+ #[repr(C)]
970
+ pub(crate) struct Nested<T, U: ?Sized> {
971
+ _t: T,
972
+ _u: U,
973
+ }
996
974
 
997
- test!(#[repr(C)] #[repr(transparent)] #[repr(packed)](; u8) => Some(0));
998
- test!(#[repr(C)] #[repr(transparent)] #[repr(packed)](; [u8]) => Some(0));
999
- test!(#[repr(C)] #[repr(C, packed)] (u8; u8) => Some(1));
1000
- test!(#[repr(C)] (; AU64) => Some(0));
1001
- test!(#[repr(C)] (; [AU64]) => Some(0));
1002
- test!(#[repr(C)] (u8; AU64) => Some(8));
1003
- test!(#[repr(C)] (u8; [AU64]) => Some(8));
1004
-
1005
- #[derive(
1006
- Immutable, FromBytes, Eq, PartialEq, Ord, PartialOrd, Default, Debug, Copy, Clone,
1007
- )]
1008
- #[repr(C)]
1009
- pub(crate) struct Nested<T, U: ?Sized> {
1010
- _t: T,
1011
- _u: U,
975
+ test!(#[repr(C)] (; Nested<u8, AU64>) => Some(0));
976
+ test!(#[repr(C)] (; Nested<u8, [AU64]>) => Some(0));
977
+ test!(#[repr(C)] (u8; Nested<u8, AU64>) => Some(8));
978
+ test!(#[repr(C)] (u8; Nested<u8, [AU64]>) => Some(8));
979
+
980
+ // Test that `packed(N)` limits the offset of the trailing field.
981
+ test!(#[repr(C, packed( 1))] (u8; elain::Align< 2>) => Some( 1));
982
+ test!(#[repr(C, packed( 2))] (u8; elain::Align< 4>) => Some( 2));
983
+ test!(#[repr(C, packed( 4))] (u8; elain::Align< 8>) => Some( 4));
984
+ test!(#[repr(C, packed( 8))] (u8; elain::Align< 16>) => Some( 8));
985
+ test!(#[repr(C, packed( 16))] (u8; elain::Align< 32>) => Some( 16));
986
+ test!(#[repr(C, packed( 32))] (u8; elain::Align< 64>) => Some( 32));
987
+ test!(#[repr(C, packed( 64))] (u8; elain::Align< 128>) => Some( 64));
988
+ test!(#[repr(C, packed( 128))] (u8; elain::Align< 256>) => Some( 128));
989
+ test!(#[repr(C, packed( 256))] (u8; elain::Align< 512>) => Some( 256));
990
+ test!(#[repr(C, packed( 512))] (u8; elain::Align< 1024>) => Some( 512));
991
+ test!(#[repr(C, packed( 1024))] (u8; elain::Align< 2048>) => Some( 1024));
992
+ test!(#[repr(C, packed( 2048))] (u8; elain::Align< 4096>) => Some( 2048));
993
+ test!(#[repr(C, packed( 4096))] (u8; elain::Align< 8192>) => Some( 4096));
994
+ test!(#[repr(C, packed( 8192))] (u8; elain::Align< 16384>) => Some( 8192));
995
+ test!(#[repr(C, packed( 16384))] (u8; elain::Align< 32768>) => Some( 16384));
996
+ test!(#[repr(C, packed( 32768))] (u8; elain::Align< 65536>) => Some( 32768));
997
+ test!(#[repr(C, packed( 65536))] (u8; elain::Align< 131072>) => Some( 65536));
998
+ /* Alignments above 65536 are not yet supported.
999
+ test!(#[repr(C, packed( 131072))] (u8; elain::Align< 262144>) => Some( 131072));
1000
+ test!(#[repr(C, packed( 262144))] (u8; elain::Align< 524288>) => Some( 262144));
1001
+ test!(#[repr(C, packed( 524288))] (u8; elain::Align< 1048576>) => Some( 524288));
1002
+ test!(#[repr(C, packed( 1048576))] (u8; elain::Align< 2097152>) => Some( 1048576));
1003
+ test!(#[repr(C, packed( 2097152))] (u8; elain::Align< 4194304>) => Some( 2097152));
1004
+ test!(#[repr(C, packed( 4194304))] (u8; elain::Align< 8388608>) => Some( 4194304));
1005
+ test!(#[repr(C, packed( 8388608))] (u8; elain::Align< 16777216>) => Some( 8388608));
1006
+ test!(#[repr(C, packed( 16777216))] (u8; elain::Align< 33554432>) => Some( 16777216));
1007
+ test!(#[repr(C, packed( 33554432))] (u8; elain::Align< 67108864>) => Some( 33554432));
1008
+ test!(#[repr(C, packed( 67108864))] (u8; elain::Align< 33554432>) => Some( 67108864));
1009
+ test!(#[repr(C, packed( 33554432))] (u8; elain::Align<134217728>) => Some( 33554432));
1010
+ test!(#[repr(C, packed(134217728))] (u8; elain::Align<268435456>) => Some(134217728));
1011
+ test!(#[repr(C, packed(268435456))] (u8; elain::Align<268435456>) => Some(268435456));
1012
+ */
1013
+
1014
+ // Test that `align(N)` does not limit the offset of the trailing field.
1015
+ test!(#[repr(C, align( 1))] (u8; elain::Align< 2>) => Some( 2));
1016
+ test!(#[repr(C, align( 2))] (u8; elain::Align< 4>) => Some( 4));
1017
+ test!(#[repr(C, align( 4))] (u8; elain::Align< 8>) => Some( 8));
1018
+ test!(#[repr(C, align( 8))] (u8; elain::Align< 16>) => Some( 16));
1019
+ test!(#[repr(C, align( 16))] (u8; elain::Align< 32>) => Some( 32));
1020
+ test!(#[repr(C, align( 32))] (u8; elain::Align< 64>) => Some( 64));
1021
+ test!(#[repr(C, align( 64))] (u8; elain::Align< 128>) => Some( 128));
1022
+ test!(#[repr(C, align( 128))] (u8; elain::Align< 256>) => Some( 256));
1023
+ test!(#[repr(C, align( 256))] (u8; elain::Align< 512>) => Some( 512));
1024
+ test!(#[repr(C, align( 512))] (u8; elain::Align< 1024>) => Some( 1024));
1025
+ test!(#[repr(C, align( 1024))] (u8; elain::Align< 2048>) => Some( 2048));
1026
+ test!(#[repr(C, align( 2048))] (u8; elain::Align< 4096>) => Some( 4096));
1027
+ test!(#[repr(C, align( 4096))] (u8; elain::Align< 8192>) => Some( 8192));
1028
+ test!(#[repr(C, align( 8192))] (u8; elain::Align< 16384>) => Some( 16384));
1029
+ test!(#[repr(C, align( 16384))] (u8; elain::Align< 32768>) => Some( 32768));
1030
+ test!(#[repr(C, align( 32768))] (u8; elain::Align< 65536>) => Some( 65536));
1031
+ /* Alignments above 65536 are not yet supported.
1032
+ test!(#[repr(C, align( 65536))] (u8; elain::Align< 131072>) => Some( 131072));
1033
+ test!(#[repr(C, align( 131072))] (u8; elain::Align< 262144>) => Some( 262144));
1034
+ test!(#[repr(C, align( 262144))] (u8; elain::Align< 524288>) => Some( 524288));
1035
+ test!(#[repr(C, align( 524288))] (u8; elain::Align< 1048576>) => Some( 1048576));
1036
+ test!(#[repr(C, align( 1048576))] (u8; elain::Align< 2097152>) => Some( 2097152));
1037
+ test!(#[repr(C, align( 2097152))] (u8; elain::Align< 4194304>) => Some( 4194304));
1038
+ test!(#[repr(C, align( 4194304))] (u8; elain::Align< 8388608>) => Some( 8388608));
1039
+ test!(#[repr(C, align( 8388608))] (u8; elain::Align< 16777216>) => Some( 16777216));
1040
+ test!(#[repr(C, align( 16777216))] (u8; elain::Align< 33554432>) => Some( 33554432));
1041
+ test!(#[repr(C, align( 33554432))] (u8; elain::Align< 67108864>) => Some( 67108864));
1042
+ test!(#[repr(C, align( 67108864))] (u8; elain::Align< 33554432>) => Some( 33554432));
1043
+ test!(#[repr(C, align( 33554432))] (u8; elain::Align<134217728>) => Some(134217728));
1044
+ test!(#[repr(C, align(134217728))] (u8; elain::Align<268435456>) => Some(268435456));
1045
+ */
1012
1046
  }
1013
1047
 
1014
- test!(#[repr(C)] (; Nested<u8, AU64>) => Some(0));
1015
- test!(#[repr(C)] (; Nested<u8, [AU64]>) => Some(0));
1016
- test!(#[repr(C)] (u8; Nested<u8, AU64>) => Some(8));
1017
- test!(#[repr(C)] (u8; Nested<u8, [AU64]>) => Some(8));
1018
-
1019
- // Test that `packed(N)` limits the offset of the trailing field.
1020
- test!(#[repr(C, packed( 1))] (u8; elain::Align< 2>) => Some( 1));
1021
- test!(#[repr(C, packed( 2))] (u8; elain::Align< 4>) => Some( 2));
1022
- test!(#[repr(C, packed( 4))] (u8; elain::Align< 8>) => Some( 4));
1023
- test!(#[repr(C, packed( 8))] (u8; elain::Align< 16>) => Some( 8));
1024
- test!(#[repr(C, packed( 16))] (u8; elain::Align< 32>) => Some( 16));
1025
- test!(#[repr(C, packed( 32))] (u8; elain::Align< 64>) => Some( 32));
1026
- test!(#[repr(C, packed( 64))] (u8; elain::Align< 128>) => Some( 64));
1027
- test!(#[repr(C, packed( 128))] (u8; elain::Align< 256>) => Some( 128));
1028
- test!(#[repr(C, packed( 256))] (u8; elain::Align< 512>) => Some( 256));
1029
- test!(#[repr(C, packed( 512))] (u8; elain::Align< 1024>) => Some( 512));
1030
- test!(#[repr(C, packed( 1024))] (u8; elain::Align< 2048>) => Some( 1024));
1031
- test!(#[repr(C, packed( 2048))] (u8; elain::Align< 4096>) => Some( 2048));
1032
- test!(#[repr(C, packed( 4096))] (u8; elain::Align< 8192>) => Some( 4096));
1033
- test!(#[repr(C, packed( 8192))] (u8; elain::Align< 16384>) => Some( 8192));
1034
- test!(#[repr(C, packed( 16384))] (u8; elain::Align< 32768>) => Some( 16384));
1035
- test!(#[repr(C, packed( 32768))] (u8; elain::Align< 65536>) => Some( 32768));
1036
- test!(#[repr(C, packed( 65536))] (u8; elain::Align< 131072>) => Some( 65536));
1037
- /* Alignments above 65536 are not yet supported.
1038
- test!(#[repr(C, packed( 131072))] (u8; elain::Align< 262144>) => Some( 131072));
1039
- test!(#[repr(C, packed( 262144))] (u8; elain::Align< 524288>) => Some( 262144));
1040
- test!(#[repr(C, packed( 524288))] (u8; elain::Align< 1048576>) => Some( 524288));
1041
- test!(#[repr(C, packed( 1048576))] (u8; elain::Align< 2097152>) => Some( 1048576));
1042
- test!(#[repr(C, packed( 2097152))] (u8; elain::Align< 4194304>) => Some( 2097152));
1043
- test!(#[repr(C, packed( 4194304))] (u8; elain::Align< 8388608>) => Some( 4194304));
1044
- test!(#[repr(C, packed( 8388608))] (u8; elain::Align< 16777216>) => Some( 8388608));
1045
- test!(#[repr(C, packed( 16777216))] (u8; elain::Align< 33554432>) => Some( 16777216));
1046
- test!(#[repr(C, packed( 33554432))] (u8; elain::Align< 67108864>) => Some( 33554432));
1047
- test!(#[repr(C, packed( 67108864))] (u8; elain::Align< 33554432>) => Some( 67108864));
1048
- test!(#[repr(C, packed( 33554432))] (u8; elain::Align<134217728>) => Some( 33554432));
1049
- test!(#[repr(C, packed(134217728))] (u8; elain::Align<268435456>) => Some(134217728));
1050
- test!(#[repr(C, packed(268435456))] (u8; elain::Align<268435456>) => Some(268435456));
1051
- */
1052
-
1053
- // Test that `align(N)` does not limit the offset of the trailing field.
1054
- test!(#[repr(C, align( 1))] (u8; elain::Align< 2>) => Some( 2));
1055
- test!(#[repr(C, align( 2))] (u8; elain::Align< 4>) => Some( 4));
1056
- test!(#[repr(C, align( 4))] (u8; elain::Align< 8>) => Some( 8));
1057
- test!(#[repr(C, align( 8))] (u8; elain::Align< 16>) => Some( 16));
1058
- test!(#[repr(C, align( 16))] (u8; elain::Align< 32>) => Some( 32));
1059
- test!(#[repr(C, align( 32))] (u8; elain::Align< 64>) => Some( 64));
1060
- test!(#[repr(C, align( 64))] (u8; elain::Align< 128>) => Some( 128));
1061
- test!(#[repr(C, align( 128))] (u8; elain::Align< 256>) => Some( 256));
1062
- test!(#[repr(C, align( 256))] (u8; elain::Align< 512>) => Some( 512));
1063
- test!(#[repr(C, align( 512))] (u8; elain::Align< 1024>) => Some( 1024));
1064
- test!(#[repr(C, align( 1024))] (u8; elain::Align< 2048>) => Some( 2048));
1065
- test!(#[repr(C, align( 2048))] (u8; elain::Align< 4096>) => Some( 4096));
1066
- test!(#[repr(C, align( 4096))] (u8; elain::Align< 8192>) => Some( 8192));
1067
- test!(#[repr(C, align( 8192))] (u8; elain::Align< 16384>) => Some( 16384));
1068
- test!(#[repr(C, align( 16384))] (u8; elain::Align< 32768>) => Some( 32768));
1069
- test!(#[repr(C, align( 32768))] (u8; elain::Align< 65536>) => Some( 65536));
1070
- /* Alignments above 65536 are not yet supported.
1071
- test!(#[repr(C, align( 65536))] (u8; elain::Align< 131072>) => Some( 131072));
1072
- test!(#[repr(C, align( 131072))] (u8; elain::Align< 262144>) => Some( 262144));
1073
- test!(#[repr(C, align( 262144))] (u8; elain::Align< 524288>) => Some( 524288));
1074
- test!(#[repr(C, align( 524288))] (u8; elain::Align< 1048576>) => Some( 1048576));
1075
- test!(#[repr(C, align( 1048576))] (u8; elain::Align< 2097152>) => Some( 2097152));
1076
- test!(#[repr(C, align( 2097152))] (u8; elain::Align< 4194304>) => Some( 4194304));
1077
- test!(#[repr(C, align( 4194304))] (u8; elain::Align< 8388608>) => Some( 8388608));
1078
- test!(#[repr(C, align( 8388608))] (u8; elain::Align< 16777216>) => Some( 16777216));
1079
- test!(#[repr(C, align( 16777216))] (u8; elain::Align< 33554432>) => Some( 33554432));
1080
- test!(#[repr(C, align( 33554432))] (u8; elain::Align< 67108864>) => Some( 67108864));
1081
- test!(#[repr(C, align( 67108864))] (u8; elain::Align< 33554432>) => Some( 33554432));
1082
- test!(#[repr(C, align( 33554432))] (u8; elain::Align<134217728>) => Some(134217728));
1083
- test!(#[repr(C, align(134217728))] (u8; elain::Align<268435456>) => Some(268435456));
1084
- */
1085
- }
1086
-
1087
- // FIXME(#29), FIXME(https://github.com/rust-lang/rust/issues/69835): Remove
1088
- // this `cfg` when `size_of_val_raw` is stabilized.
1089
- #[allow(clippy::decimal_literal_representation)]
1090
- #[cfg(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)]
1091
- #[test]
1092
- fn test_align_of_dst() {
1093
- // Test that `align_of!` correctly computes the alignment of DSTs.
1094
- assert_eq!(align_of!([elain::Align<1>]), Some(1));
1095
- assert_eq!(align_of!([elain::Align<2>]), Some(2));
1096
- assert_eq!(align_of!([elain::Align<4>]), Some(4));
1097
- assert_eq!(align_of!([elain::Align<8>]), Some(8));
1098
- assert_eq!(align_of!([elain::Align<16>]), Some(16));
1099
- assert_eq!(align_of!([elain::Align<32>]), Some(32));
1100
- assert_eq!(align_of!([elain::Align<64>]), Some(64));
1101
- assert_eq!(align_of!([elain::Align<128>]), Some(128));
1102
- assert_eq!(align_of!([elain::Align<256>]), Some(256));
1103
- assert_eq!(align_of!([elain::Align<512>]), Some(512));
1104
- assert_eq!(align_of!([elain::Align<1024>]), Some(1024));
1105
- assert_eq!(align_of!([elain::Align<2048>]), Some(2048));
1106
- assert_eq!(align_of!([elain::Align<4096>]), Some(4096));
1107
- assert_eq!(align_of!([elain::Align<8192>]), Some(8192));
1108
- assert_eq!(align_of!([elain::Align<16384>]), Some(16384));
1109
- assert_eq!(align_of!([elain::Align<32768>]), Some(32768));
1110
- assert_eq!(align_of!([elain::Align<65536>]), Some(65536));
1111
- /* Alignments above 65536 are not yet supported.
1112
- assert_eq!(align_of!([elain::Align<131072>]), Some(131072));
1113
- assert_eq!(align_of!([elain::Align<262144>]), Some(262144));
1114
- assert_eq!(align_of!([elain::Align<524288>]), Some(524288));
1115
- assert_eq!(align_of!([elain::Align<1048576>]), Some(1048576));
1116
- assert_eq!(align_of!([elain::Align<2097152>]), Some(2097152));
1117
- assert_eq!(align_of!([elain::Align<4194304>]), Some(4194304));
1118
- assert_eq!(align_of!([elain::Align<8388608>]), Some(8388608));
1119
- assert_eq!(align_of!([elain::Align<16777216>]), Some(16777216));
1120
- assert_eq!(align_of!([elain::Align<33554432>]), Some(33554432));
1121
- assert_eq!(align_of!([elain::Align<67108864>]), Some(67108864));
1122
- assert_eq!(align_of!([elain::Align<33554432>]), Some(33554432));
1123
- assert_eq!(align_of!([elain::Align<134217728>]), Some(134217728));
1124
- assert_eq!(align_of!([elain::Align<268435456>]), Some(268435456));
1125
- */
1048
+ // FIXME(#29), FIXME(https://github.com/rust-lang/rust/issues/69835):
1049
+ // Remove this `cfg` when `size_of_val_raw` is stabilized.
1050
+ #[allow(clippy::decimal_literal_representation)]
1051
+ #[test]
1052
+ fn test_align_of_dst() {
1053
+ // Test that `align_of!` correctly computes the alignment of DSTs.
1054
+ assert_eq!(align_of!([elain::Align<1>]), Some(1));
1055
+ assert_eq!(align_of!([elain::Align<2>]), Some(2));
1056
+ assert_eq!(align_of!([elain::Align<4>]), Some(4));
1057
+ assert_eq!(align_of!([elain::Align<8>]), Some(8));
1058
+ assert_eq!(align_of!([elain::Align<16>]), Some(16));
1059
+ assert_eq!(align_of!([elain::Align<32>]), Some(32));
1060
+ assert_eq!(align_of!([elain::Align<64>]), Some(64));
1061
+ assert_eq!(align_of!([elain::Align<128>]), Some(128));
1062
+ assert_eq!(align_of!([elain::Align<256>]), Some(256));
1063
+ assert_eq!(align_of!([elain::Align<512>]), Some(512));
1064
+ assert_eq!(align_of!([elain::Align<1024>]), Some(1024));
1065
+ assert_eq!(align_of!([elain::Align<2048>]), Some(2048));
1066
+ assert_eq!(align_of!([elain::Align<4096>]), Some(4096));
1067
+ assert_eq!(align_of!([elain::Align<8192>]), Some(8192));
1068
+ assert_eq!(align_of!([elain::Align<16384>]), Some(16384));
1069
+ assert_eq!(align_of!([elain::Align<32768>]), Some(32768));
1070
+ assert_eq!(align_of!([elain::Align<65536>]), Some(65536));
1071
+ /* Alignments above 65536 are not yet supported.
1072
+ assert_eq!(align_of!([elain::Align<131072>]), Some(131072));
1073
+ assert_eq!(align_of!([elain::Align<262144>]), Some(262144));
1074
+ assert_eq!(align_of!([elain::Align<524288>]), Some(524288));
1075
+ assert_eq!(align_of!([elain::Align<1048576>]), Some(1048576));
1076
+ assert_eq!(align_of!([elain::Align<2097152>]), Some(2097152));
1077
+ assert_eq!(align_of!([elain::Align<4194304>]), Some(4194304));
1078
+ assert_eq!(align_of!([elain::Align<8388608>]), Some(8388608));
1079
+ assert_eq!(align_of!([elain::Align<16777216>]), Some(16777216));
1080
+ assert_eq!(align_of!([elain::Align<33554432>]), Some(33554432));
1081
+ assert_eq!(align_of!([elain::Align<67108864>]), Some(67108864));
1082
+ assert_eq!(align_of!([elain::Align<33554432>]), Some(33554432));
1083
+ assert_eq!(align_of!([elain::Align<134217728>]), Some(134217728));
1084
+ assert_eq!(align_of!([elain::Align<268435456>]), Some(268435456));
1085
+ */
1086
+ }
1126
1087
  }
1127
1088
 
1128
1089
  #[test]