aboutsummaryrefslogtreecommitdiff
path: root/vendor/bytemuck/tests/std_tests.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/std_tests.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/std_tests.rs')
-rw-r--r--vendor/bytemuck/tests/std_tests.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/bytemuck/tests/std_tests.rs b/vendor/bytemuck/tests/std_tests.rs
new file mode 100644
index 0000000..e239058
--- /dev/null
+++ b/vendor/bytemuck/tests/std_tests.rs
@@ -0,0 +1,46 @@
+#![allow(clippy::uninlined_format_args)]
+//! The integration tests seem to always have `std` linked, so things that would
+//! depend on that can go here.
+
+use bytemuck::*;
+
+#[test]
+fn test_transparent_vtabled() {
+ use core::fmt::Display;
+
+ #[repr(transparent)]
+ struct DisplayTraitObj(dyn Display);
+
+ unsafe impl TransparentWrapper<dyn Display> for DisplayTraitObj {}
+
+ impl Display for DisplayTraitObj {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ self.0.fmt(f)
+ }
+ }
+
+ let v = DisplayTraitObj::wrap_ref(&5i32);
+ let s = format!("{}", v);
+ assert_eq!(s, "5");
+
+ let mut x = 100i32;
+ let v_mut = DisplayTraitObj::wrap_mut(&mut x);
+ let s = format!("{}", v_mut);
+ assert_eq!(s, "100");
+}
+
+#[test]
+#[cfg(feature = "extern_crate_alloc")]
+fn test_large_box_alloc() {
+ type SuperPage = [[u8; 4096]; 4096];
+ let _: Box<SuperPage> = try_zeroed_box().unwrap();
+}
+
+#[test]
+#[cfg(feature = "extern_crate_alloc")]
+fn test_zero_sized_box_alloc() {
+ #[repr(align(4096))]
+ struct Empty;
+ unsafe impl Zeroable for Empty {}
+ let _: Box<Empty> = try_zeroed_box().unwrap();
+}