-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This code fails to compile:
#![feature(async_await)]
use futures::future::join_all;
async fn do_work(n: u32) -> u32 {
n + 1
}
#[runtime::main]
async fn main() {
let data = vec![1, 2, 3];
let futures_to_wait = data
.iter()
.map(|value: &u32| do_work(*value))
.collect();
let results = join_all(futures_to_wait).await;
println!("all work is done, results are {:?}", results);
}Error message:
error[E0698]: type inside `async` object must be known in this context
--> src/main.rs:16:19
|
16 | let results = join_all(futures_to_wait).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
note: the type is part of the `async` object because of this `await`
--> src/main.rs:16:19
|
16 | let results = join_all(futures_to_wait).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0698`.
More details:
rustc --version
rustc 1.37.0-nightly (2fe7b3383 2019-06-19)
edition = "2018"
[dependencies]
runtime = "0.3.0-alpha.5"
futures-preview = "0.3.0-alpha.16"Annotating variable type fixes the error: let futures_to_wait: Vec<_> = ...
@Nemo157 kindly created a playground example with similar error (though a bit different, mentioning generators instead of async objects: type inside generator must be known in this context)
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=deaf09047f91d098705bcf90f894fd72
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.