]> git.lizzy.rs Git - rust.git/blob - src/test/ui/intrinsics/const-eval-select-bad.rs
Rollup merge of #101391 - matthiaskrgr:perf0309, r=oli-obk
[rust.git] / src / test / ui / intrinsics / const-eval-select-bad.rs
1 #![feature(const_eval_select)]
2 #![feature(core_intrinsics)]
3
4 use std::intrinsics::const_eval_select;
5
6 const fn not_fn_items() {
7     const_eval_select((), || {}, || {});
8     //~^ ERROR this argument must be a function item
9     //~| ERROR this argument must be a function item
10     const_eval_select((), 42, 0xDEADBEEF);
11     //~^ ERROR expected a `FnOnce<()>` closure
12     //~| ERROR expected a `FnOnce<()>` closure
13     //~| ERROR this argument must be a function item
14     //~| ERROR this argument must be a function item
15 }
16
17 const fn foo(n: i32) -> i32 {
18     n
19 }
20
21 fn bar(n: i32) -> bool {
22     assert_eq!(n, 0, "{} must be equal to {}", n, 0);
23     n == 0
24 }
25
26 fn baz(n: bool) -> i32 {
27     assert!(n, "{} must be true", n);
28     n as i32
29 }
30
31 const fn return_ty_mismatch() {
32     const_eval_select((1,), foo, bar);
33     //~^ ERROR expected `fn(i32) -> bool {bar}` to be a fn item that returns `i32`, but it returns `bool`
34 }
35
36 const fn args_ty_mismatch() {
37     const_eval_select((true,), foo, baz);
38     //~^ ERROR type mismatch
39 }
40
41 const fn non_const_fn() {
42     const_eval_select((1,), bar, bar);
43     //~^ ERROR this argument must be a `const fn`
44 }
45
46 fn main() {}