From 07451f8b94a8b867696ddc1c6b546774fe1e06e4 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 2 Dec 2019 16:43:33 -0800 Subject: [PATCH] task: relax 'static bound in `LocalSet::block_on` (#1882) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Motivation Currently, `tokio::task::LocalSet`'s `block_on` method requires the future to live for the 'static lifetime. However, this bound is not required — the future is wrapped in a `LocalFuture`, and then passed into `Runtime::block_on`, which does _not_ require a `'static` future. This came up while updating `tokio-compat` to work with version 0.2. To mimic the behavior of `tokio` 0.1's `current_thread::Runtime::run`, we want to be able to have a runtime block on the `recv` future from an mpsc channel indicating when the runtime is idle. To support `!Send` futures, as the old `current_thread::Runtime` did, we must do so inside of a `LocalSet`. However, with the current bounds, we cannot await an `mpsc::Receiver`'s `recv` future inside the `LocalSet::block_on` call. ## Solution This branch removes the unnecessary `'static` bound. Signed-off-by: Eliza Weisman --- tokio/src/task/local.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index 7f29e3d15..f81522c9d 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -303,8 +303,7 @@ impl LocalSet { /// [`spawn_blocking`]: ../blocking/fn.spawn_blocking.html pub fn block_on(&self, rt: &mut crate::runtime::Runtime, future: F) -> F::Output where - F: Future + 'static, - F::Output: 'static, + F: Future, { let scheduler = self.scheduler.clone(); self.scheduler