]> git.lizzy.rs Git - rust.git/blob - src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr
Exit early if expected type is not an adt
[rust.git] / src / test / ui / suggestions / expected-boxed-future-isnt-pinned.stderr
1 error[E0308]: mismatched types
2   --> $DIR/expected-boxed-future-isnt-pinned.rs:11:5
3    |
4 LL | fn foo<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
5    |        - this type parameter                            ----------------------- expected `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` because of return type
6 LL |     // We could instead use an `async` block, but this way we have no std spans.
7 LL |     x
8    |     ^ expected struct `Pin`, found type parameter `F`
9    |
10    = note:      expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>`
11            found type parameter `F`
12 help: you need to pin and box this expression
13    |
14 LL |     Box::pin(x)
15    |     +++++++++ +
16
17 error[E0308]: mismatched types
18   --> $DIR/expected-boxed-future-isnt-pinned.rs:15:5
19    |
20 LL | fn bar<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
21    |                                                         ----------------------- expected `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` because of return type
22 LL |     Box::new(x)
23    |     ^^^^^^^^^^^ expected struct `Pin`, found struct `Box`
24    |
25    = note: expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>`
26               found struct `Box<F>`
27    = help: use `Box::pin`
28
29 error[E0308]: mismatched types
30   --> $DIR/expected-boxed-future-isnt-pinned.rs:22:14
31    |
32 LL | fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
33    |        - this type parameter
34 LL |     Pin::new(x)
35    |              ^ expected struct `Box`, found type parameter `F`
36    |
37    = note:      expected struct `Box<dyn Future<Output = i32> + Send>`
38            found type parameter `F`
39    = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
40 help: store this in the heap by calling `Box::new`
41    |
42 LL |     Pin::new(Box::new(x))
43    |              +++++++++ +
44
45 error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
46   --> $DIR/expected-boxed-future-isnt-pinned.rs:22:5
47    |
48 LL |     Pin::new(x)
49    |     ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
50    |
51    = note: consider using `Box::pin`
52 note: required by `Pin::<P>::new`
53   --> $SRC_DIR/core/src/pin.rs:LL:COL
54    |
55 LL |     pub const fn new(pointer: P) -> Pin<P> {
56    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57
58 error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
59   --> $DIR/expected-boxed-future-isnt-pinned.rs:27:5
60    |
61 LL |     Pin::new(Box::new(x))
62    |     ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
63    |
64    = note: consider using `Box::pin`
65 note: required by `Pin::<P>::new`
66   --> $SRC_DIR/core/src/pin.rs:LL:COL
67    |
68 LL |     pub const fn new(pointer: P) -> Pin<P> {
69    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70
71 error[E0308]: mismatched types
72   --> $DIR/expected-boxed-future-isnt-pinned.rs:31:5
73    |
74 LL |   fn zap() -> BoxFuture<'static, i32> {
75    |               ----------------------- expected `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` because of return type
76 LL | /     async {
77 LL | |         42
78 LL | |     }
79    | |_____^ expected struct `Pin`, found opaque type
80    |
81   ::: $SRC_DIR/core/src/future/mod.rs:LL:COL
82    |
83 LL |   pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
84    |                                             ------------------------------- the found opaque type
85    |
86    = note:   expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>`
87            found opaque type `impl Future`
88 help: you need to pin and box this expression
89    |
90 LL ~     Box::pin(async {
91 LL |         42
92 LL ~     })
93    |
94
95 error: aborting due to 6 previous errors
96
97 Some errors have detailed explanations: E0277, E0308.
98 For more information about an error, try `rustc --explain E0277`.