Skip to content

Commit 75d8199

Browse files
committed
Add a fail test
1 parent 03ac54a commit 75d8199

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
#![feature(repr_simd)]
3+
#![feature(platform_intrinsics)]
4+
#![allow(non_camel_case_types)]
5+
6+
#[repr(simd)] struct i8x1(i8);
7+
8+
extern "platform-intrinsic" {
9+
fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
10+
}
11+
12+
const fn foo(x: i8x1) -> i8 {
13+
// 42 is a i16 that does not fit in a i8
14+
unsafe { simd_insert(x, 0_u32, 42_i16) }.0 //~ ERROR
15+
}
16+
17+
fn main() {
18+
const V: i8x1 = i8x1(13);
19+
const X: i8 = foo(V);
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: any use of this value will cause an error
2+
--> $DIR/const_eval-simd_fail.rs:14:14
3+
|
4+
LL | unsafe { simd_insert(x, 0_u32, 42_i16) }.0
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| Inserting `i16` with size `2` to a vector element place of size `1`
8+
| inside call to `foo` at $DIR/const_eval-simd_fail.rs:19:19
9+
...
10+
LL | const X: i8 = foo(V);
11+
| ---------------------
12+
|
13+
= note: `#[deny(const_err)]` on by default
14+
15+
error: aborting due to previous error
16+

0 commit comments

Comments
 (0)