Skip to content

Commit 3e8ce42

Browse files
committed
Add const-eval test for #[target_feature(enable = ...)] function calls
1 parent b5fde0d commit 3e8ce42

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// only-x86_64
2+
// compile-flags:-C target-feature=+ssse3
3+
4+
#![crate_type = "lib"]
5+
6+
// ok (ssse3 enabled at compile time)
7+
const A: () = unsafe { ssse3_fn() };
8+
9+
// error (avx2 not enabled at compile time)
10+
const B: () = unsafe { avx2_fn() };
11+
//~^ ERROR evaluation of constant value failed
12+
13+
#[target_feature(enable = "ssse3")]
14+
const unsafe fn ssse3_fn() {}
15+
16+
#[target_feature(enable = "avx2")]
17+
const unsafe fn avx2_fn() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0080]: evaluation of constant value failed
2+
--> $DIR/const_fn_target_feature.rs:10:24
3+
|
4+
LL | const B: () = unsafe { avx2_fn() };
5+
| ^^^^^^^^^ calling a function that requires unavailable target features: avx2
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)