Skip to content

Commit 87c190c

Browse files
committed
Reworked const fn ref tests
1 parent 0c9896b commit 87c190c

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

src/test/ui/consts/fn_trait_refs.rs

+59-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,80 @@
1-
// run-pass
1+
// build-pass
2+
23
#![feature(const_fn_trait_ref_impls)]
34
#![feature(fn_traits)]
45
#![feature(unboxed_closures)]
56
#![feature(const_trait_impl)]
67
#![feature(const_mut_refs)]
8+
#![feature(const_cmp)]
9+
#![feature(const_refs_to_cell)]
710

811
use std::marker::Destruct;
912

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()
1218
}
1319

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()
1625
}
1726

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()
2032
}
2133

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+
}
2347

24-
const fn tester<T>(_fn: T)
48+
const fn test_fn_mut<T>(mut f: T) -> (T::Output, T::Output)
2549
where
26-
T: ~const Fn() + ~const Destruct,
50+
T: ~const FnMut<()> + ~const Destruct,
2751
{
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
2861
}
2962

3063
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);
3580
}

0 commit comments

Comments
 (0)