1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
//@ known-bug: #110395
#![feature(const_fn_trait_ref_impls)]
#![feature(fn_traits)]
#![feature(unboxed_closures)]
#![feature(const_trait_impl)]
#![feature(const_cmp)]
#![feature(const_destruct)]
use std::marker::Destruct;
const fn tester_fn<T>(f: T) -> T::Output
where
T: ~const Fn<()> + ~const Destruct,
{
f()
}
const fn tester_fn_mut<T>(mut f: T) -> T::Output
where
T: ~const FnMut<()> + ~const Destruct,
{
f()
}
const fn tester_fn_once<T>(f: T) -> T::Output
where
T: ~const FnOnce<()>,
{
f()
}
const fn test_fn<T>(mut f: T) -> (T::Output, T::Output, T::Output)
where
T: ~const Fn<()> + ~const Destruct,
{
(
// impl<A: Tuple, F: ~const Fn + ?Sized> const Fn<A> for &F
tester_fn(&f),
// impl<A: Tuple, F: ~const Fn + ?Sized> const FnMut<A> for &F
tester_fn_mut(&f),
// impl<A: Tuple, F: ~const Fn + ?Sized> const FnOnce<A> for &F
tester_fn_once(&f),
)
}
const fn test_fn_mut<T>(mut f: T) -> (T::Output, T::Output)
where
T: ~const FnMut<()> + ~const Destruct,
{
(
// impl<A: Tuple, F: ~const FnMut + ?Sized> const FnMut<A> for &mut F
tester_fn_mut(&mut f),
// impl<A: Tuple, F: ~const FnMut + ?Sized> const FnOnce<A> for &mut F
tester_fn_once(&mut f),
)
}
const fn test(i: i32) -> i32 {
i + 1
}
fn main() {
const fn one() -> i32 {
1
};
const fn two() -> i32 {
2
};
const _: () = {
let test_one = test_fn(one);
assert!(test_one == (1, 1, 1));
let test_two = test_fn_mut(two);
assert!(test_two == (2, 2));
};
}
|