]> git.lizzy.rs Git - rust.git/commitdiff
Add test for u8 align_offset
authorChristian Poveda <christianpoveda@protonmail.com>
Wed, 11 Sep 2019 17:08:42 +0000 (12:08 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Wed, 11 Sep 2019 17:08:42 +0000 (12:08 -0500)
tests/run-pass/aligned_utf8_check.rs [new file with mode: 0644]
tests/run-pass/aligned_utf8_check.stdout [new file with mode: 0644]

diff --git a/tests/run-pass/aligned_utf8_check.rs b/tests/run-pass/aligned_utf8_check.rs
new file mode 100644 (file)
index 0000000..0d2b2bf
--- /dev/null
@@ -0,0 +1,13 @@
+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!("{:?}", String::from_utf8_lossy(&y));
+
+    let mut x: Vec<u16> = unsafe { std::mem::transmute(y) };
+    unsafe { x.set_len(N) };
+}
diff --git a/tests/run-pass/aligned_utf8_check.stdout b/tests/run-pass/aligned_utf8_check.stdout
new file mode 100644 (file)
index 0000000..8d08312
--- /dev/null
@@ -0,0 +1 @@
+"AAAAAAAAAAAAAAAAAAAA"