3 use std::future::Future;
6 type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
7 // ^^^^^^^^^ This would come from the `futures` crate in real code.
9 fn foo<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
10 // We could instead use an `async` block, but this way we have no std spans.
11 x //~ ERROR mismatched types
14 // This case is still subpar:
15 // `Pin::new(x)`: store this in the heap by calling `Box::new`: `Box::new(x)`
16 // Should suggest changing the code from `Pin::new` to `Box::pin`.
17 fn bar<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
18 Box::new(x) //~ ERROR mismatched types
21 fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
22 Pin::new(x) //~ ERROR mismatched types
26 fn qux<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
27 Pin::new(Box::new(x)) //~ ERROR E0277
30 fn zap() -> BoxFuture<'static, i32> {
31 async { //~ ERROR mismatched types