Skip to content

async/await: “the requirement for<'r> 'r : 'static is not satisfied” with 'static across await point #53548

Closed
@Ekleog

Description

@Ekleog

(continuation of rust-lang/futures-rs#1199 as it looks like a compiler bug after all, important points repeated here)

Problem

There appear to be an issue in handling traits that have a parent 'static bound boxed through an await point: the following example fails to compile with the requirement for<'r> 'r : 'static is not satisfied (note: I'm using generators for simplicity of reproduction, see below for a futures-only example)

trait Trait: 'static {}
async fn foo(b: Box<Trait + 'static>) -> () {
    let bar = move || { b; () };
    yield
}

(playground link)

However, when removing the 'static bound on Trait, it appears to compile correctly, even though the Box itself still has the + 'static bound.

trait Trait {}
async fn foo(b: Box<Trait + 'static>) -> () {
    let bar = move || { b; () };
    yield
}

(playground link)

Futures-only version

The error originated in code that looked like:

use futures::future;                                  
use std::any::Any;                                    
async fn foo(b: Box<Any + Send + 'static>) -> () { 
    await!(future::lazy(move |_| {                    
        b;                                          
        ()                                            
    }))                                               
}    

The Any being here the trait that has the 'static bound. This was tested with futures-rs at commit rust-lang/futures-rs@c02ec75 and nightly 2018-08-14.

No generator-only version

I couldn't manage to get a generator-only version to fail: this compiles.

use std::any::Any;
use std::ops::Generator;
fn send(msg: Box<Any + 'static>) -> impl Generator + 'static {
    || {
        let mut pinned = move || { msg; () };
        yield
    }
}

(playground link)

Potentially related issue

This is potentially related to #53259, as the same for<'r> appears there?

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-coroutinesArea: CoroutinesAsyncAwait-PolishAsync-await issues that are part of the "polish" areaT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions