Skip to content

Commit 0c9896b

Browse files
committed
Fix const_fn_trait_ref_impl, add test for it
1 parent 391ba78 commit 0c9896b

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

library/core/src/ops/function.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -576,29 +576,32 @@ mod impls {
576576
use crate::marker::Tuple;
577577

578578
#[stable(feature = "rust1", since = "1.0.0")]
579-
impl<A: Tuple, F: ?Sized> Fn<A> for &F
579+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
580+
impl<A: Tuple, F: ?Sized> const Fn<A> for &F
580581
where
581-
F: Fn<A>,
582+
F: ~const Fn<A>,
582583
{
583584
extern "rust-call" fn call(&self, args: A) -> F::Output {
584585
(**self).call(args)
585586
}
586587
}
587588

588589
#[stable(feature = "rust1", since = "1.0.0")]
589-
impl<A: Tuple, F: ?Sized> FnMut<A> for &F
590+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
591+
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F
590592
where
591-
F: Fn<A>,
593+
F: ~const Fn<A>,
592594
{
593595
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
594596
(**self).call(args)
595597
}
596598
}
597599

598600
#[stable(feature = "rust1", since = "1.0.0")]
599-
impl<A: Tuple, F: ?Sized> FnOnce<A> for &F
601+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
602+
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F
600603
where
601-
F: Fn<A>,
604+
F: ~const Fn<A>,
602605
{
603606
type Output = F::Output;
604607

@@ -608,19 +611,21 @@ mod impls {
608611
}
609612

610613
#[stable(feature = "rust1", since = "1.0.0")]
611-
impl<A: Tuple, F: ?Sized> FnMut<A> for &mut F
614+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
615+
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
612616
where
613-
F: FnMut<A>,
617+
F: ~const FnMut<A>,
614618
{
615619
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
616620
(*self).call_mut(args)
617621
}
618622
}
619623

620624
#[stable(feature = "rust1", since = "1.0.0")]
621-
impl<A: Tuple, F: ?Sized> FnOnce<A> for &mut F
625+
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
626+
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
622627
where
623-
F: FnMut<A>,
628+
F: ~const FnMut<A>,
624629
{
625630
type Output = F::Output;
626631
extern "rust-call" fn call_once(self, args: A) -> F::Output {

src/test/ui/consts/fn_trait_refs.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// run-pass
2+
#![feature(const_fn_trait_ref_impls)]
3+
#![feature(fn_traits)]
4+
#![feature(unboxed_closures)]
5+
#![feature(const_trait_impl)]
6+
#![feature(const_mut_refs)]
7+
8+
use std::marker::Destruct;
9+
10+
const fn test(i: i32) -> i32 {
11+
i + 1
12+
}
13+
14+
const fn call<F: ~const FnMut(i32) -> i32 + ~const Destruct>(mut f: F) -> F::Output {
15+
f(5)
16+
}
17+
18+
const fn use_fn<F: ~const FnMut(i32) -> i32 + ~const Destruct>(mut f: F) -> F::Output {
19+
call(&mut f)
20+
}
21+
22+
const fn test_fn() {}
23+
24+
const fn tester<T>(_fn: T)
25+
where
26+
T: ~const Fn() + ~const Destruct,
27+
{
28+
}
29+
30+
const fn main() {
31+
tester(test_fn);
32+
let test_ref = &test_fn;
33+
tester(test_ref);
34+
assert!(use_fn(test) == 6);
35+
}

0 commit comments

Comments
 (0)