diff --git a/library/core/src/const_closure.rs b/library/core/src/const_closure.rs index 6ea94c95473..d2e80e8e7e5 100644 --- a/library/core/src/const_closure.rs +++ b/library/core/src/const_closure.rs @@ -1,56 +1,5 @@ use crate::marker::Destruct; -/// Struct representing a closure with owned data. -/// -/// Example: -/// ```no_build -/// use crate::const_closure::ConstFnOnceClosure; -/// const fn imp(state: i32, (arg,): (i32,)) -> i32 { -/// state + arg -/// } -/// let i = 5; -/// let cl = ConstFnOnceClosure::new(i, imp); -/// -/// assert!(7 == cl(2)); -/// ``` -pub(crate) struct ConstFnOnceClosure { - data: CapturedData, - func: Function, -} - -impl ConstFnOnceClosure { - /// Function for creating a new closure. - /// - /// `data` is the owned data that is captured from the environment (this data must be `~const Destruct`). - /// - /// `func` is the function of the closure, it gets the data and a tuple of the arguments closure - /// and return the return value of the closure. - #[allow(dead_code)] - pub(crate) const fn new( - data: CapturedData, - func: Function, - ) -> Self - where - CapturedData: ~const Destruct, - Function: ~const Fn(CapturedData, ClosureArguments) -> ClosureReturnValue + ~const Destruct, - { - Self { data, func } - } -} - -impl const FnOnce - for ConstFnOnceClosure -where - CapturedData: ~const Destruct, - Function: ~const Fn<(CapturedData, ClosureArguments)> + ~const Destruct, -{ - type Output = Function::Output; - - extern "rust-call" fn call_once(self, args: ClosureArguments) -> Self::Output { - (self.func)(self.data, args) - } -} - /// Struct representing a closure with mutably borrowed data. /// /// Example: @@ -112,77 +61,3 @@ where (self.func)(self.data, args) } } - -/// Struct representing a closure with borrowed data. -/// -/// Example: -/// ```no_build -/// use crate::const_closure::ConstFnClosure; -/// -/// const fn imp(state: &i32, (arg,): (i32,)) -> i32 { -/// *state + arg -/// } -/// let i = 5; -/// let cl = ConstFnClosure::new(&i, imp); -/// -/// assert!(7 == cl(2)); -/// assert!(6 == cl(1)); -/// ``` -pub(crate) struct ConstFnClosure<'a, CapturedData: ?Sized, Function> { - data: &'a CapturedData, - func: Function, -} - -impl<'a, CapturedData: ?Sized, Function> ConstFnClosure<'a, CapturedData, Function> { - /// Function for creating a new closure. - /// - /// `data` is the a mutable borrow of data that is captured from the environment. - /// - /// `func` is the function of the closure, it gets the data and a tuple of the arguments closure - /// and return the return value of the closure. - #[allow(dead_code)] - pub(crate) const fn new( - data: &'a CapturedData, - func: Function, - ) -> Self - where - Function: ~const Fn(&CapturedData, ClosureArguments) -> ClosureReturnValue, - { - Self { data, func } - } -} - -impl<'a, CapturedData: ?Sized, Function, ClosureArguments, ClosureReturnValue> const - FnOnce for ConstFnClosure<'a, CapturedData, Function> -where - Function: ~const Fn(&CapturedData, ClosureArguments) -> ClosureReturnValue + ~const Destruct, -{ - type Output = ClosureReturnValue; - - extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output { - self.call_mut(args) - } -} - -impl<'a, CapturedData: ?Sized, Function, ClosureArguments, ClosureReturnValue> const - FnMut for ConstFnClosure<'a, CapturedData, Function> -where - Function: ~const Fn(&CapturedData, ClosureArguments) -> ClosureReturnValue, -{ - extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output { - self.call(args) - } -} - -impl< - 'a, - CapturedData: ?Sized, - Function: ~const Fn(&CapturedData, ClosureArguments) -> ClosureReturnValue, - ClosureArguments, - ClosureReturnValue, -> const Fn for ConstFnClosure<'a, CapturedData, Function> -{ - extern "rust-call" fn call(&self, args: ClosureArguments) -> Self::Output { - (self.func)(self.data, args) - } -}