]> git.lizzy.rs Git - rust.git/commitdiff
Add regression test for integral pointers in zst str slice fat pointers
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 13 Nov 2018 13:54:00 +0000 (14:54 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Sat, 24 Nov 2018 10:36:31 +0000 (11:36 +0100)
src/test/ui/consts/int_ptr_for_zst_slices.rs [new file with mode: 0644]
src/test/ui/consts/int_ptr_for_zst_slices.stderr [new file with mode: 0644]

diff --git a/src/test/ui/consts/int_ptr_for_zst_slices.rs b/src/test/ui/consts/int_ptr_for_zst_slices.rs
new file mode 100644 (file)
index 0000000..ece8d3d
--- /dev/null
@@ -0,0 +1,3 @@
+const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
+
+fn main() {}
\ No newline at end of file
diff --git a/src/test/ui/consts/int_ptr_for_zst_slices.stderr b/src/test/ui/consts/int_ptr_for_zst_slices.stderr
new file mode 100644 (file)
index 0000000..c7b78d9
--- /dev/null
@@ -0,0 +1,23 @@
+error[E0308]: mismatched types
+  --> $DIR/int_ptr_for_zst_slices.rs:1:28
+   |
+LL | const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
+   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected str, found slice
+   |
+   = note: expected type `&'static str`
+              found type `&[str]`
+
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/int_ptr_for_zst_slices.rs:1:75
+   |
+LL | const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
+   |                                                                           ^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: slice and array elements must have `Sized` type
+
+error: aborting due to 2 previous errors
+
+Some errors occurred: E0277, E0308.
+For more information about an error, try `rustc --explain E0277`.