Rollup merge of #52995 - cramertj:smaller-await, r=withoutboats
Remove unnecessary local in await! generator
This makes `async { await!(future::ready(())) }` 4 bytes instead of 16. [Playground example](http://play.rust-lang.org/?gist=54c075599b9ff390fe505c75d6b98feb&version=nightly&mode=debug&edition=2018)
This commit is contained in:
commit
59bfa8a884
2 changed files with 11 additions and 8 deletions
|
|
@ -108,9 +108,9 @@ where
|
|||
|
||||
#[unstable(feature = "gen_future", issue = "50547")]
|
||||
/// Polls a future in the current thread-local task context.
|
||||
pub fn poll_in_task_cx<F>(f: &mut PinMut<F>) -> Poll<F::Output>
|
||||
pub fn poll_in_task_cx<F>(f: PinMut<F>) -> Poll<F::Output>
|
||||
where
|
||||
F: Future
|
||||
{
|
||||
get_task_cx(|cx| f.reborrow().poll(cx))
|
||||
get_task_cx(|cx| f.poll(cx))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,14 +227,17 @@ macro_rules! eprintln {
|
|||
macro_rules! await {
|
||||
($e:expr) => { {
|
||||
let mut pinned = $e;
|
||||
let mut pinned = unsafe { $crate::mem::PinMut::new_unchecked(&mut pinned) };
|
||||
loop {
|
||||
match $crate::future::poll_in_task_cx(&mut pinned) {
|
||||
// FIXME(cramertj) prior to stabilizing await, we have to ensure that this
|
||||
// can't be used to create a generator on stable via `|| await!()`.
|
||||
$crate::task::Poll::Pending => yield,
|
||||
$crate::task::Poll::Ready(x) => break x,
|
||||
if let $crate::task::Poll::Ready(x) =
|
||||
$crate::future::poll_in_task_cx(unsafe {
|
||||
$crate::mem::PinMut::new_unchecked(&mut pinned)
|
||||
})
|
||||
{
|
||||
break x;
|
||||
}
|
||||
// FIXME(cramertj) prior to stabilizing await, we have to ensure that this
|
||||
// can't be used to create a generator on stable via `|| await!()`.
|
||||
yield
|
||||
}
|
||||
} }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue