Description
(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
}
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
}
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
}
}
Potentially related issue
This is potentially related to #53259, as the same for<'r>
appears there?