]> git.lizzy.rs Git - rust.git/commitdiff
another test for too big type
authorRalf Jung <post@ralfj.de>
Sat, 26 Mar 2022 14:44:30 +0000 (10:44 -0400)
committerRalf Jung <post@ralfj.de>
Sat, 26 Mar 2022 15:08:11 +0000 (11:08 -0400)
tests/compile-fail/slice-too-big.rs [deleted file]
tests/compile-fail/too-big-slice.rs [new file with mode: 0644]
tests/compile-fail/too-big-unsized.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/slice-too-big.rs b/tests/compile-fail/slice-too-big.rs
deleted file mode 100644 (file)
index 6a4c182..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-use std::mem;
-
-fn main() { unsafe {
-    let ptr = Box::into_raw(Box::new(0u8));
-    let _x: &[u8] = mem::transmute((ptr, usize::MAX)); //~ ERROR: invalid reference metadata: slice is bigger than largest supported object
-} }
diff --git a/tests/compile-fail/too-big-slice.rs b/tests/compile-fail/too-big-slice.rs
new file mode 100644 (file)
index 0000000..6a4c182
--- /dev/null
@@ -0,0 +1,6 @@
+use std::mem;
+
+fn main() { unsafe {
+    let ptr = Box::into_raw(Box::new(0u8));
+    let _x: &[u8] = mem::transmute((ptr, usize::MAX)); //~ ERROR: invalid reference metadata: slice is bigger than largest supported object
+} }
diff --git a/tests/compile-fail/too-big-unsized.rs b/tests/compile-fail/too-big-unsized.rs
new file mode 100644 (file)
index 0000000..ad7bc6e
--- /dev/null
@@ -0,0 +1,18 @@
+use std::mem;
+
+#[allow(unused)]
+struct MySlice {
+    prefix: u64,
+    tail: [u8],
+}
+
+#[cfg(target_pointer_width = "64")]
+const TOO_BIG: usize = 1usize << 47;
+#[cfg(target_pointer_width = "32")]
+const TOO_BIG: usize = 1usize << 31;
+
+fn main() { unsafe {
+    let ptr = Box::into_raw(Box::new(0u8));
+    // The slice part is actually not "too big", but together with the `prefix` field it is.
+    let _x: &MySlice = mem::transmute((ptr, TOO_BIG-1)); //~ ERROR: invalid reference metadata: total size is bigger than largest supported object
+} }