summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/fn_trait_refs.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
commit5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch)
tree35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /src/test/ui/consts/fn_trait_refs.rs
parentAdding debian version 1.66.0+dfsg1-1. (diff)
downloadrustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz
rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/consts/fn_trait_refs.rs')
-rw-r--r--src/test/ui/consts/fn_trait_refs.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/test/ui/consts/fn_trait_refs.rs b/src/test/ui/consts/fn_trait_refs.rs
new file mode 100644
index 000000000..b50749297
--- /dev/null
+++ b/src/test/ui/consts/fn_trait_refs.rs
@@ -0,0 +1,77 @@
+// check-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 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));
+ };
+}