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