diff options
| author | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2023-07-16 13:20:06 +0200 |
|---|---|---|
| committer | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2023-07-16 13:20:06 +0200 |
| commit | 3e8ce42d42ce6c6fed3f3db7ee77591a87eddc40 (patch) | |
| tree | f79456e7730731cca5a608e6983c06bfefb7a0d4 | |
| parent | b5fde0dae0af1a4a273830e695dc0aaf7c3885ba (diff) | |
| download | rust-3e8ce42d42ce6c6fed3f3db7ee77591a87eddc40.tar.gz rust-3e8ce42d42ce6c6fed3f3db7ee77591a87eddc40.zip | |
Add const-eval test for `#[target_feature(enable = ...)]` function calls
| -rw-r--r-- | tests/ui/consts/const-eval/const_fn_target_feature.rs | 17 | ||||
| -rw-r--r-- | tests/ui/consts/const-eval/const_fn_target_feature.stderr | 9 |
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/ui/consts/const-eval/const_fn_target_feature.rs b/tests/ui/consts/const-eval/const_fn_target_feature.rs new file mode 100644 index 00000000000..5d02ce3f21b --- /dev/null +++ b/tests/ui/consts/const-eval/const_fn_target_feature.rs @@ -0,0 +1,17 @@ +// only-x86_64 +// compile-flags:-C target-feature=+ssse3 + +#![crate_type = "lib"] + +// ok (ssse3 enabled at compile time) +const A: () = unsafe { ssse3_fn() }; + +// error (avx2 not enabled at compile time) +const B: () = unsafe { avx2_fn() }; +//~^ ERROR evaluation of constant value failed + +#[target_feature(enable = "ssse3")] +const unsafe fn ssse3_fn() {} + +#[target_feature(enable = "avx2")] +const unsafe fn avx2_fn() {} diff --git a/tests/ui/consts/const-eval/const_fn_target_feature.stderr b/tests/ui/consts/const-eval/const_fn_target_feature.stderr new file mode 100644 index 00000000000..36918b52cd3 --- /dev/null +++ b/tests/ui/consts/const-eval/const_fn_target_feature.stderr @@ -0,0 +1,9 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const_fn_target_feature.rs:10:24 + | +LL | const B: () = unsafe { avx2_fn() }; + | ^^^^^^^^^ calling a function that requires unavailable target features: avx2 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. |
