]> git.lizzy.rs Git - rust.git/commitdiff
Update align_offset tests
authorChristian Poveda <christianpoveda@protonmail.com>
Tue, 17 Sep 2019 16:47:36 +0000 (11:47 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Tue, 17 Sep 2019 16:47:36 +0000 (11:47 -0500)
tests/run-pass/aligned_utf8_check.rs
tests/run-pass/aligned_utf8_check.stdout
tests/run-pass/integer_align_offset.rs [new file with mode: 0644]

index 202856b3bde9a78d25a9a415b0b43c5b76b2fe1d..6c6ff6b6173cb8b0a2ad98d35f922246feb4712e 100644 (file)
@@ -1,13 +1,6 @@
 fn main() {
     const N: usize = 10;
-
-    let x = vec![0x4141u16; N];
-
-    let mut y: Vec<u8> = unsafe { std::mem::transmute(x) };
-    unsafe { y.set_len(2 * N) };
-
-    println!("{:?}", std::str::from_utf8(&y).unwrap());
-
-    let mut x: Vec<u16> = unsafe { std::mem::transmute(y) };
-    unsafe { x.set_len(N) };
+    let vec = vec![0x4141414141414141u64; N];
+    let content = unsafe { std::slice::from_raw_parts(vec.as_ptr() as *const u8, 8 * N) };
+    println!("{:?}", std::str::from_utf8(content).unwrap());
 }
index 8d08312cac7b5287a8bb12ee6606d78a0856bdae..66d439948159632e13543778e040edd9f3cfca17 100644 (file)
@@ -1 +1 @@
-"AAAAAAAAAAAAAAAAAAAA"
+"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
diff --git a/tests/run-pass/integer_align_offset.rs b/tests/run-pass/integer_align_offset.rs
new file mode 100644 (file)
index 0000000..971c19b
--- /dev/null
@@ -0,0 +1,3 @@
+fn main() {
+    assert_eq!(2, (2 as *const i8).align_offset(4));
+}