# Lifetimes in smol::Executor

**URL:** <https://users.rust-lang.org/t/lifetimes-in-smol-executor/59157>\
**Category:** help\
**Created:** [April 30, 2021, 5:59pm UTC](https://users.rust-lang.org/t/lifetimes-in-smol-executor/59157 "2021-04-30T17:59:28Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Yandros](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/yandros/32/8136_2.png) [@Yandros](https://users.rust-lang.org/u/Yandros)\
**Post date:** [May 1, 2021, 2:05pm UTC](https://users.rust-lang.org/t/lifetimes-in-smol-executor/59157/8 "2021-05-01T14:05:16Z")

</div>

The following signature works ([Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eb80c43be8143b9b2b04aa90f6522f18)):

```rust
/// The "`Captures<'_>` hack" to work around `impl` _vs._ `dyn` inconsistency
trait Captures<'__> {}
impl<T : ?Sized> Captures<'_> for T {}

fn run_broken<'a, 'ex : 'a> (executor: &'a Executor<'ex>)
  -> impl Future + 'a + Captures<'ex>
{
    async move {
        executor.spawn(async move {
            println!("inner!");
        }).detach();
    }
}

```

### Explanation

1. I've removed the incorrect `'a ≥ 'ex` bound: `&'a Executor<'ex>` implies that `'ex ≥ 'a`, so if we had that extra `'a ≥ 'ex` bound, we'd end up with `'a == 'ex` and the classic horrible "nested borrow with same lifetime" hell. Made the `'ex ≥ 'a` bound explicit, although that is not necessary (I'd even recommend that it be removed to avoid the danger of getting the bound wrong): it is just here to teach the notion better.

2. At that point, the returned `async move { … }` (outer) future is capturing a type that mentions `'a` and `'ex`, thus its area / span / region of owned-usability (the lifetime appearing in the `impl` signature) is the intersection / minimum of `'a` and `'ex`. Since `'ex ≥ 'a`, it is `'a == min('a, 'ex)`.

3. That's when we hit the infamous:

---

_[View the full topic](https://users.rust-lang.org/t/lifetimes-in-smol-executor/59157)._
