1
Fork 0

Remove std lib Span from expected boxed future test

This commit is contained in:
Esteban Küber 2020-02-11 17:35:04 -08:00
parent c39b04ea85
commit a852fb7413
3 changed files with 19 additions and 28 deletions

View file

@ -7,10 +7,9 @@ use std::pin::Pin;
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>; type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
// ^^^^^^^^^ This would come from the `futures` crate in real code. // ^^^^^^^^^ This would come from the `futures` crate in real code.
fn foo() -> BoxFuture<'static, i32> { fn foo<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
Box::pin(async { //~ ERROR mismatched types // We could instead use an `async` block, but this way we have no std spans.
42 Box::pin(x) //~ ERROR mismatched types
})
} }
fn main() {} fn main() {}

View file

@ -7,10 +7,9 @@ use std::pin::Pin;
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>; type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
// ^^^^^^^^^ This would come from the `futures` crate in real code. // ^^^^^^^^^ This would come from the `futures` crate in real code.
fn foo() -> BoxFuture<'static, i32> { fn foo<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
async { //~ ERROR mismatched types // We could instead use an `async` block, but this way we have no std spans.
42 x //~ ERROR mismatched types
}
} }
fn main() {} fn main() {}

View file

@ -1,26 +1,19 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/expected-boxed-future-isnt-pinned.rs:11:5 --> $DIR/expected-boxed-future-isnt-pinned.rs:12:5
| |
LL | fn foo() -> BoxFuture<'static, i32> { LL | fn foo<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
| ----------------------- expected `std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = i32> + std::marker::Send + 'static)>>` because of return type | - this type parameter ----------------------- expected `std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = i32> + std::marker::Send + 'static)>>` because of return type
LL | / async { LL | // We could instead use an `async` block, but this way we have no std spans.
LL | | 42 LL | x
LL | | } | ^
| |_____^ expected struct `std::pin::Pin`, found opaque type | |
| | expected struct `std::pin::Pin`, found type parameter `F`
::: $SRC_DIR/libstd/future.rs:LL:COL | help: you need to pin and box this expression: `Box::pin(x)`
|
LL | pub fn from_generator<T: Generator<Yield = ()>>(x: T) -> impl Future<Output = T::Return> {
| ------------------------------- the found opaque type
|
= note: expected struct `std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = i32> + std::marker::Send + 'static)>>`
found opaque type `impl std::future::Future`
help: you need to pin and box this expression
|
LL | Box::pin(async {
LL | 42
LL | })
| |
= note: expected struct `std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = i32> + std::marker::Send + 'static)>>`
found type parameter `F`
= help: type parameters must be constrained to match other types
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
error: aborting due to previous error error: aborting due to previous error