2025-09-12 12:39:31 +03:00
|
|
|
//@ check-pass
|
2022-11-07 21:16:22 +01:00
|
|
|
|
2022-11-07 17:41:58 +01:00
|
|
|
#![feature(fn_traits)]
|
|
|
|
|
#![feature(unboxed_closures)]
|
|
|
|
|
#![feature(const_trait_impl)]
|
2022-11-07 21:16:22 +01:00
|
|
|
#![feature(const_cmp)]
|
2024-11-21 23:20:59 +00:00
|
|
|
#![feature(const_destruct)]
|
2022-11-07 17:41:58 +01:00
|
|
|
|
|
|
|
|
use std::marker::Destruct;
|
|
|
|
|
|
2022-11-07 21:16:22 +01:00
|
|
|
const fn tester_fn<T>(f: T) -> T::Output
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
T: [const] Fn<()> + [const] Destruct,
|
2022-11-07 21:16:22 +01:00
|
|
|
{
|
|
|
|
|
f()
|
2022-11-07 17:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-07 21:16:22 +01:00
|
|
|
const fn tester_fn_mut<T>(mut f: T) -> T::Output
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
T: [const] FnMut<()> + [const] Destruct,
|
2022-11-07 21:16:22 +01:00
|
|
|
{
|
|
|
|
|
f()
|
2022-11-07 17:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-07 21:16:22 +01:00
|
|
|
const fn tester_fn_once<T>(f: T) -> T::Output
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
T: [const] FnOnce<()>,
|
2022-11-07 21:16:22 +01:00
|
|
|
{
|
|
|
|
|
f()
|
2022-11-07 17:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-07 21:16:22 +01:00
|
|
|
const fn test_fn<T>(mut f: T) -> (T::Output, T::Output, T::Output)
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
T: [const] Fn<()> + [const] Destruct,
|
2022-11-07 21:16:22 +01:00
|
|
|
{
|
|
|
|
|
(
|
2025-03-11 12:08:45 +00:00
|
|
|
// impl<A: Tuple, F: [const] Fn + ?Sized> const Fn<A> for &F
|
2022-11-07 21:16:22 +01:00
|
|
|
tester_fn(&f),
|
2025-03-11 12:08:45 +00:00
|
|
|
// impl<A: Tuple, F: [const] Fn + ?Sized> const FnMut<A> for &F
|
2022-11-07 21:16:22 +01:00
|
|
|
tester_fn_mut(&f),
|
2025-03-11 12:08:45 +00:00
|
|
|
// impl<A: Tuple, F: [const] Fn + ?Sized> const FnOnce<A> for &F
|
2022-11-07 21:16:22 +01:00
|
|
|
tester_fn_once(&f),
|
|
|
|
|
)
|
|
|
|
|
}
|
2022-11-07 17:41:58 +01:00
|
|
|
|
2022-11-07 21:16:22 +01:00
|
|
|
const fn test_fn_mut<T>(mut f: T) -> (T::Output, T::Output)
|
2022-11-07 17:41:58 +01:00
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
T: [const] FnMut<()> + [const] Destruct,
|
2022-11-07 17:41:58 +01:00
|
|
|
{
|
2022-11-07 21:16:22 +01:00
|
|
|
(
|
2025-03-11 12:08:45 +00:00
|
|
|
// impl<A: Tuple, F: [const] FnMut + ?Sized> const FnMut<A> for &mut F
|
2022-11-07 21:16:22 +01:00
|
|
|
tester_fn_mut(&mut f),
|
2025-03-11 12:08:45 +00:00
|
|
|
// impl<A: Tuple, F: [const] FnMut + ?Sized> const FnOnce<A> for &mut F
|
2022-11-07 21:16:22 +01:00
|
|
|
tester_fn_once(&mut f),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
const fn test(i: i32) -> i32 {
|
|
|
|
|
i + 1
|
2022-11-07 17:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-09 11:35:28 +01:00
|
|
|
fn main() {
|
2022-11-07 21:16:22 +01:00
|
|
|
const fn one() -> i32 {
|
|
|
|
|
1
|
|
|
|
|
};
|
|
|
|
|
const fn two() -> i32 {
|
|
|
|
|
2
|
|
|
|
|
};
|
2022-11-09 11:35:28 +01:00
|
|
|
const _: () = {
|
|
|
|
|
let test_one = test_fn(one);
|
|
|
|
|
assert!(test_one == (1, 1, 1));
|
2022-11-07 21:16:22 +01:00
|
|
|
|
2022-11-09 11:35:28 +01:00
|
|
|
let test_two = test_fn_mut(two);
|
|
|
|
|
assert!(test_two == (2, 2));
|
|
|
|
|
};
|
2022-11-07 17:41:58 +01:00
|
|
|
}
|