]> git.lizzy.rs Git - rust.git/commitdiff
Add a fail test
authorgnzlbg <gonzalobg88@gmail.com>
Tue, 24 Sep 2019 14:48:17 +0000 (16:48 +0200)
committergnzlbg <gonzalobg88@gmail.com>
Tue, 24 Sep 2019 14:48:17 +0000 (16:48 +0200)
src/test/ui/consts/const-eval/const_eval-simd_fail.rs [new file with mode: 0644]
src/test/ui/consts/const-eval/const_eval-simd_fail.stderr [new file with mode: 0644]

diff --git a/src/test/ui/consts/const-eval/const_eval-simd_fail.rs b/src/test/ui/consts/const-eval/const_eval-simd_fail.rs
new file mode 100644 (file)
index 0000000..20c839a
--- /dev/null
@@ -0,0 +1,20 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(repr_simd)]
+#![feature(platform_intrinsics)]
+#![allow(non_camel_case_types)]
+
+#[repr(simd)] struct i8x1(i8);
+
+extern "platform-intrinsic" {
+    fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
+}
+
+const fn foo(x: i8x1) -> i8 {
+    // 42 is a i16 that does not fit in a i8
+    unsafe { simd_insert(x, 0_u32, 42_i16) }.0  //~ ERROR
+}
+
+fn main() {
+    const V: i8x1 = i8x1(13);
+    const X: i8 = foo(V);
+}
diff --git a/src/test/ui/consts/const-eval/const_eval-simd_fail.stderr b/src/test/ui/consts/const-eval/const_eval-simd_fail.stderr
new file mode 100644 (file)
index 0000000..9f76287
--- /dev/null
@@ -0,0 +1,16 @@
+error: any use of this value will cause an error
+  --> $DIR/const_eval-simd_fail.rs:14:14
+   |
+LL |     unsafe { simd_insert(x, 0_u32, 42_i16) }.0
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |              |
+   |              Inserting `i16` with size `2` to a vector element place of size `1`
+   |              inside call to `foo` at $DIR/const_eval-simd_fail.rs:19:19
+...
+LL |     const X: i8 = foo(V);
+   |     ---------------------
+   |
+   = note: `#[deny(const_err)]` on by default
+
+error: aborting due to previous error
+