forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#102234 - matthiaskrgr:rollup-5cb20l1, r=matth…
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#100823 (Refactor some `std` code that works with pointer offstes) - rust-lang#102088 (Fix wrongly refactored Lift impl) - rust-lang#102109 (resolve: Set effective visibilities for imports more precisely) - rust-lang#102186 (Add const_closure, Constify Try trait) - rust-lang#102203 (rustdoc: remove no-op CSS `#source-sidebar { z-index }`) - rust-lang#102204 (Make `ManuallyDrop` satisfy `~const Destruct`) - rust-lang#102210 (diagnostics: avoid syntactically invalid suggestion in if conditionals) - rust-lang#102226 (bootstrap/miri: switch to non-deprecated env var for setting the sysroot folder) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
24 changed files
with
310 additions
and
102 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
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
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,63 @@ | ||
use crate::marker::Destruct; | ||
|
||
/// Struct representing a closure with mutably borrowed data. | ||
/// | ||
/// Example: | ||
/// ```no_build | ||
/// #![feature(const_mut_refs)] | ||
/// use crate::const_closure::ConstFnMutClosure; | ||
/// const fn imp(state: &mut i32, (arg,): (i32,)) -> i32 { | ||
/// *state += arg; | ||
/// *state | ||
/// } | ||
/// let mut i = 5; | ||
/// let mut cl = ConstFnMutClosure::new(&mut i, imp); | ||
/// | ||
/// assert!(7 == cl(2)); | ||
/// assert!(8 == cl(1)); | ||
/// ``` | ||
pub(crate) struct ConstFnMutClosure<'a, CapturedData: ?Sized, Function> { | ||
data: &'a mut CapturedData, | ||
func: Function, | ||
} | ||
|
||
impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<'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. | ||
pub(crate) const fn new<ClosureArguments, ClosureReturnValue>( | ||
data: &'a mut CapturedData, | ||
func: Function, | ||
) -> Self | ||
where | ||
Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue, | ||
{ | ||
Self { data, func } | ||
} | ||
} | ||
|
||
impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const | ||
FnOnce<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function> | ||
where | ||
Function: | ||
~const Fn(&mut 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, ClosureArguments, Function, ClosureReturnValue> const | ||
FnMut<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function> | ||
where | ||
Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue, | ||
{ | ||
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output { | ||
(self.func)(self.data, args) | ||
} | ||
} |
Oops, something went wrong.