]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/expected-boxed-future-isnt-pinned.rs
Rollup merge of #106751 - clubby789:const-intrinsic, r=GuillaumeGomez
[rust.git] / tests / ui / suggestions / expected-boxed-future-isnt-pinned.rs
1 // edition:2018
2 #![allow(dead_code)]
3 use std::future::Future;
4 use std::pin::Pin;
5
6 type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
7 //   ^^^^^^^^^ This would come from the `futures` crate in real code.
8
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
12 }
13
14 fn bar<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
15     Box::new(x) //~ ERROR mismatched types
16 }
17
18 fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
19     Pin::new(x) //~ ERROR mismatched types
20     //~^ ERROR E0277
21 }
22
23 fn qux<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
24     Pin::new(Box::new(x)) //~ ERROR E0277
25 }
26
27 fn zap() -> BoxFuture<'static, i32> {
28     async { //~ ERROR mismatched types
29         42
30     }
31 }
32
33 fn main() {}