about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-13 15:36:05 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-24 11:36:31 +0100
commitebf03363f2d2385bc2248549cd93fca42779699a (patch)
tree0c14a447bc384ebdd9fa7fabe0c342961d41b3d4 /src
parentcc2f46e55a3fe52affe0dd4aee2ececd75c78031 (diff)
downloadrust-ebf03363f2d2385bc2248549cd93fca42779699a.tar.gz
rust-ebf03363f2d2385bc2248549cd93fca42779699a.zip
Properly test for int pointers in fat pointers to str slices of zero chars
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/consts/int_ptr_for_zst_slices.rs7
-rw-r--r--src/test/ui/consts/int_ptr_for_zst_slices.stderr26
2 files changed, 12 insertions, 21 deletions
diff --git a/src/test/ui/consts/int_ptr_for_zst_slices.rs b/src/test/ui/consts/int_ptr_for_zst_slices.rs
index ece8d3d1505..809cc15be0c 100644
--- a/src/test/ui/consts/int_ptr_for_zst_slices.rs
+++ b/src/test/ui/consts/int_ptr_for_zst_slices.rs
@@ -1,3 +1,6 @@
-const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
+#![feature(const_raw_ptr_deref)]
 
-fn main() {}
\ No newline at end of file
+const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const str) };
+//~^ ERROR it is undefined behaviour to use this value
+
+fn main() {}
diff --git a/src/test/ui/consts/int_ptr_for_zst_slices.stderr b/src/test/ui/consts/int_ptr_for_zst_slices.stderr
index c7b78d98cc8..437e6952e74 100644
--- a/src/test/ui/consts/int_ptr_for_zst_slices.stderr
+++ b/src/test/ui/consts/int_ptr_for_zst_slices.stderr
@@ -1,23 +1,11 @@
-error[E0308]: mismatched types
-  --> $DIR/int_ptr_for_zst_slices.rs:1:28
+error[E0080]: it is undefined behavior to use this value
+  --> $DIR/int_ptr_for_zst_slices.rs:3:1
    |
-LL | const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected str, found slice
+LL | const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const str) };
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized or non-UTF-8 data in str at .<deref>
    |
-   = note: expected type `&'static str`
-              found type `&[str]`
+   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
 
-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
+error: aborting due to previous error
 
-Some errors occurred: E0277, E0308.
-For more information about an error, try `rustc --explain E0277`.
+For more information about this error, try `rustc --explain E0080`.