]> git.lizzy.rs Git - rust.git/commit
lowering: extend temporary lifetimes around await
authorDavid Wood <david@davidtw.co>
Sun, 8 Sep 2019 20:22:51 +0000 (21:22 +0100)
committerDavid Wood <david@davidtw.co>
Tue, 10 Sep 2019 10:27:57 +0000 (11:27 +0100)
commit63fad69a9967a56e33927aa31c50768bc1498588
tree0512384eac07853d0f132ba768ab25a0f896e594
parent43a5ff4222e1f217ac14331afd59f82ec4204d12
lowering: extend temporary lifetimes around await

This commit changes the HIR lowering around `await` so that temporary
lifetimes are extended. Previously, await was lowered as:

```rust
{
    let mut pinned = future;
    loop {
        match ::std::future::poll_with_tls_context(unsafe {
            <::std::pin::Pin>::new_unchecked(&mut pinned)
        }) {
            ::std::task::Poll::Ready(result) => break result,
            ::std::task::Poll::Pending => {}
        }
        yield ();
    }
}
```

With this commit, await is lowered as:

```rust
match future {
    mut pinned => loop {
        match ::std::future::poll_with_tls_context(unsafe {
            <::std::pin::Pin>::new_unchecked(&mut pinned)
        }) {
            ::std::task::Poll::Ready(result) => break result,
            ::std::task::Poll::Pending => {}
        }
        yield ();
    }
}
```

However, this change has the following side-effects:

- All temporaries in future will be considered to live across a
  yield for the purpose of auto-traits.
- Borrowed temporaries in future are likely to be considered to be live
  across the yield for the purpose of the generator transform.

Signed-off-by: David Wood <david@davidtw.co>
src/librustc/hir/lowering/expr.rs
src/test/ui/async-await/async-fn-nonsend.stderr
src/test/ui/async-await/issue-63832-await-short-temporary-lifetime-1.rs [new file with mode: 0644]
src/test/ui/async-await/issue-63832-await-short-temporary-lifetime.rs [new file with mode: 0644]