Skip to content

Commit 39db6a0

Browse files
committed
add test ensuring simd codegen checks don't run when a static assertion failed
1 parent 094a620 commit 39db6a0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@build-fail
2+
//! Make sure that monomorphization-time const errors from `static_assert` take priority over the
3+
//! error from simd_extract. Basically this checks that if a const fails to evaluate in some
4+
//! function, we don't bother codegen'ing the function.
5+
#![feature(generic_arg_infer)]
6+
#![feature(core_intrinsics)]
7+
#![feature(repr_simd)]
8+
#![feature(inline_const)]
9+
use std::intrinsics::simd::*;
10+
11+
#[repr(simd)]
12+
#[allow(non_camel_case_types)]
13+
struct int8x4_t(u8,u8,u8,u8);
14+
15+
fn get_elem<const LANE: u32>(a: int8x4_t) -> u8 {
16+
const { assert!(LANE < 4); } // the error should be here...
17+
//~^ ERROR failed
18+
//~| assertion failed
19+
unsafe { simd_extract(a, LANE) } // ...not here
20+
}
21+
22+
fn main() {
23+
get_elem::<4>(int8x4_t(0,0,0,0));
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0080]: evaluation of `get_elem::<4>::{constant#0}` failed
2+
--> $DIR/const-err-trumps-simd-err.rs:16:13
3+
|
4+
LL | const { assert!(LANE < 4); } // the error should be here...
5+
| ^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: LANE < 4', $DIR/const-err-trumps-simd-err.rs:16:13
6+
|
7+
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
note: the above error was encountered while instantiating `fn get_elem::<4>`
10+
--> $DIR/const-err-trumps-simd-err.rs:23:5
11+
|
12+
LL | get_elem::<4>(int8x4_t(0,0,0,0));
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)