2021-10-12 00:06:37 -05:00
|
|
|
#![feature(const_eval_select)]
|
2022-04-11 20:12:26 -05:00
|
|
|
#![feature(core_intrinsics)]
|
2021-10-12 00:06:37 -05:00
|
|
|
|
|
|
|
use std::intrinsics::const_eval_select;
|
|
|
|
|
|
|
|
const fn not_fn_items() {
|
2021-10-14 01:18:53 -05:00
|
|
|
const_eval_select((), || {}, || {});
|
2022-08-22 19:07:26 -05:00
|
|
|
//~^ ERROR this argument must be a function item
|
|
|
|
//~| ERROR this argument must be a function item
|
2021-10-12 00:06:37 -05:00
|
|
|
const_eval_select((), 42, 0xDEADBEEF);
|
2023-10-04 20:50:00 -05:00
|
|
|
//~^ ERROR expected a `FnOnce()` closure
|
|
|
|
//~| ERROR expected a `FnOnce()` closure
|
2022-08-22 19:07:26 -05:00
|
|
|
//~| ERROR this argument must be a function item
|
|
|
|
//~| ERROR this argument must be a function item
|
2021-10-12 00:06:37 -05:00
|
|
|
}
|
|
|
|
|
2021-10-14 01:18:53 -05:00
|
|
|
const fn foo(n: i32) -> i32 {
|
2021-10-12 00:06:37 -05:00
|
|
|
n
|
|
|
|
}
|
|
|
|
|
2021-10-14 01:18:53 -05:00
|
|
|
fn bar(n: i32) -> bool {
|
2021-10-12 00:06:37 -05:00
|
|
|
assert_eq!(n, 0, "{} must be equal to {}", n, 0);
|
|
|
|
n == 0
|
|
|
|
}
|
|
|
|
|
2021-10-14 01:18:53 -05:00
|
|
|
fn baz(n: bool) -> i32 {
|
2021-10-12 00:06:37 -05:00
|
|
|
assert!(n, "{} must be true", n);
|
|
|
|
n as i32
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn return_ty_mismatch() {
|
|
|
|
const_eval_select((1,), foo, bar);
|
2023-01-06 14:28:46 -06:00
|
|
|
//~^ ERROR expected `bar` to be a fn item that returns `i32`, but it returns `bool`
|
2021-10-12 00:06:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const fn args_ty_mismatch() {
|
|
|
|
const_eval_select((true,), foo, baz);
|
|
|
|
//~^ ERROR type mismatch
|
|
|
|
}
|
|
|
|
|
2022-08-22 19:07:26 -05:00
|
|
|
const fn non_const_fn() {
|
|
|
|
const_eval_select((1,), bar, bar);
|
|
|
|
//~^ ERROR this argument must be a `const fn`
|
|
|
|
}
|
|
|
|
|
2021-10-12 00:06:37 -05:00
|
|
|
fn main() {}
|