forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#104113 - ink-feather-org:fix_const_fn_ref_i…
…mpls, r=compiler-errors Fix `const_fn_trait_ref_impl`, add test for it rust-lang#99943 broke `#[feature(const_fn_trait_ref_impl)]`, this PR fixes this and adds a test for it. r? `@fee1-dead`
- Loading branch information
Showing
2 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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 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 | ||
} | ||
|
||
const fn main() { | ||
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); | ||
} |