summaryrefslogtreecommitdiffstats
path: root/tests/ui/suggestions/expected-boxed-future-isnt-pinned.rs
blob: 7e9c5492d1a6bc083e119eedace934dc90768b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// edition:2018
#![allow(dead_code)]
use std::future::Future;
use std::pin::Pin;

type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
//   ^^^^^^^^^ This would come from the `futures` crate in real code.

fn foo<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
    // We could instead use an `async` block, but this way we have no std spans.
    x //~ ERROR mismatched types
}

fn bar<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
    Box::new(x) //~ ERROR mismatched types
}

fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
    Pin::new(x) //~ ERROR mismatched types
    //~^ ERROR E0277
}

fn qux<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
    Pin::new(Box::new(x)) //~ ERROR E0277
}

fn zap() -> BoxFuture<'static, i32> {
    async { //~ ERROR mismatched types
        42
    }
}

fn main() {}