about summary refs log tree commit diff
path: root/src/test/ui/consts
diff options
context:
space:
mode:
authoronestacked <chrisi.schrefl@gmail.com>2022-11-07 21:16:22 +0100
committeronestacked <chrisi.schrefl@gmail.com>2022-11-07 21:16:22 +0100
commit87c190c4252ce2039400146bbdf6b7245a5499f0 (patch)
tree9783b3b77ceab30f328a17e8b5537968928e461d /src/test/ui/consts
parent0c9896bfaa6c7bfd5d34119b7aecffbcc036b201 (diff)
Reworked const fn ref tests
Diffstat (limited to 'src/test/ui/consts')
-rw-r--r--src/test/ui/consts/fn_trait_refs.rs73
1 files changed, 59 insertions, 14 deletions
diff --git a/src/test/ui/consts/fn_trait_refs.rs b/src/test/ui/consts/fn_trait_refs.rs
index 57465c55925..bc8766c74c6 100644
--- a/src/test/ui/consts/fn_trait_refs.rs
+++ b/src/test/ui/consts/fn_trait_refs.rs
@@ -1,35 +1,80 @@
-// run-pass
+// build-pass
+
 #![feature(const_fn_trait_ref_impls)]
 #![feature(fn_traits)]
 #![feature(unboxed_closures)]
 #![feature(const_trait_impl)]
 #![feature(const_mut_refs)]
+#![feature(const_cmp)]
+#![feature(const_refs_to_cell)]
 
 use std::marker::Destruct;
 
-const fn test(i: i32) -> i32 {
-    i + 1
+const fn tester_fn<T>(f: T) -> T::Output
+where
+    T: ~const Fn<()> + ~const Destruct,
+{
+    f()
 }
 
-const fn call<F: ~const FnMut(i32) -> i32 + ~const Destruct>(mut f: F) -> F::Output {
-    f(5)
+const fn tester_fn_mut<T>(mut f: T) -> T::Output
+where
+    T: ~const FnMut<()> + ~const Destruct,
+{
+    f()
 }
 
-const fn use_fn<F: ~const FnMut(i32) -> i32 + ~const Destruct>(mut f: F) -> F::Output {
-    call(&mut f)
+const fn tester_fn_once<T>(f: T) -> T::Output
+where
+    T: ~const FnOnce<()>,
+{
+    f()
 }
 
-const fn test_fn() {}
+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 tester<T>(_fn: T)
+const fn test_fn_mut<T>(mut f: T) -> (T::Output, T::Output)
 where
-    T: ~const Fn() + ~const Destruct,
+    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
 }
 
 const fn main() {
-    tester(test_fn);
-    let test_ref = &test_fn;
-    tester(test_ref);
-    assert!(use_fn(test) == 6);
+    const fn one() -> i32 {
+        1
+    };
+    const fn two() -> i32 {
+        2
+    };
+
+    // FIXME(const_cmp_tuple)
+    let test_one = test_fn(one);
+    assert!(test_one.0 == 1);
+    assert!(test_one.1 == 1);
+    assert!(test_one.2 == 1);
+
+    let test_two = test_fn_mut(two);
+    assert!(test_two.0 == 1);
+    assert!(test_two.1 == 1);
 }