rust/tests/ui/consts/fn_trait_refs.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
1.6 KiB
Rust
Raw Normal View History

2023-04-16 11:12:37 +00:00
//@ known-bug: #110395
2022-11-07 20:16:22 +00:00
#![feature(const_fn_trait_ref_impls)]
#![feature(fn_traits)]
#![feature(unboxed_closures)]
#![feature(const_trait_impl)]
#![feature(const_mut_refs)]
2022-11-07 20:16:22 +00:00
#![feature(const_cmp)]
#![feature(const_refs_to_cell)]
use std::marker::Destruct;
2022-11-07 20:16:22 +00:00
const fn tester_fn<T>(f: T) -> T::Output
where
T: ~const Fn<()> + ~const Destruct,
{
f()
}
2022-11-07 20:16:22 +00:00
const fn tester_fn_mut<T>(mut f: T) -> T::Output
where
T: ~const FnMut<()> + ~const Destruct,
{
f()
}
2022-11-07 20:16:22 +00:00
const fn tester_fn_once<T>(f: T) -> T::Output
where
T: ~const FnOnce<()>,
{
f()
}
2022-11-07 20:16:22 +00:00
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),
)
}
2022-11-07 20:16:22 +00:00
const fn test_fn_mut<T>(mut f: T) -> (T::Output, T::Output)
where
2022-11-07 20:16:22 +00:00
T: ~const FnMut<()> + ~const Destruct,
{
2022-11-07 20:16:22 +00:00
(
// 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
}
2022-11-09 10:35:28 +00:00
fn main() {
2022-11-07 20:16:22 +00:00
const fn one() -> i32 {
1
};
const fn two() -> i32 {
2
};
2022-11-09 10:35:28 +00:00
const _: () = {
let test_one = test_fn(one);
assert!(test_one == (1, 1, 1));
2022-11-07 20:16:22 +00:00
2022-11-09 10:35:28 +00:00
let test_two = test_fn_mut(two);
assert!(test_two == (2, 2));
};
}