Skip to content

Commit

Permalink
Constify impl Fn* &(mut) Fn*
Browse files Browse the repository at this point in the history
  • Loading branch information
onestacked committed Sep 14, 2022
1 parent c97922d commit 404b60b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions library/core/src/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,32 @@ pub trait FnOnce<Args> {

mod impls {
#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> Fn<A> for &F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "none")]
impl<A, F: ?Sized> const Fn<A> for &F
where
F: Fn<A>,
F: ~const Fn<A>,
{
extern "rust-call" fn call(&self, args: A) -> F::Output {
(**self).call(args)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnMut<A> for &F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "none")]
impl<A, F: ?Sized> const FnMut<A> for &F
where
F: Fn<A>,
F: ~const Fn<A>,
{
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(**self).call(args)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnOnce<A> for &F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "none")]
impl<A, F: ?Sized> const FnOnce<A> for &F
where
F: Fn<A>,
F: ~const Fn<A>,
{
type Output = F::Output;

Expand All @@ -282,19 +285,21 @@ mod impls {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnMut<A> for &mut F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "none")]
impl<A, F: ?Sized> const FnMut<A> for &mut F
where
F: FnMut<A>,
F: ~const FnMut<A>,
{
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(*self).call_mut(args)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, F: ?Sized> FnOnce<A> for &mut F
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "none")]
impl<A, F: ?Sized> const FnOnce<A> for &mut F
where
F: FnMut<A>,
F: ~const FnMut<A>,
{
type Output = F::Output;
extern "rust-call" fn call_once(self, args: A) -> F::Output {
Expand Down

0 comments on commit 404b60b

Please sign in to comment.