Skip to content

Commit

Permalink
Add a fail test
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Sep 24, 2019
1 parent 03ac54a commit 75d8199
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/ui/consts/const-eval/const_eval-simd_fail.rs
@@ -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);
}
16 changes: 16 additions & 0 deletions src/test/ui/consts/const-eval/const_eval-simd_fail.stderr
@@ -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

0 comments on commit 75d8199

Please sign in to comment.