-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce type errors in async fns #67025
Comments
@birkenfeld: Can you link to your repository, and re-fry on the latest nightly? I think more recent builds of |
Didn't see a change with latest nightly (7afe6d9 2019-12-03). Unfortunately I can't link to the repo, but if needed I can try to extract a minimal example which produces similar results. |
This looks very similar to an error that I'm getting around async code using mpsc. I can provide a minimal example: use futures::executor::ThreadPool;
use std::sync::mpsc;
use std::time::Duration;
async fn wait(d: Duration) -> f32 {
d.as_secs_f32()
}
async fn add_task(sender: mpsc::Sender<f32>, i: u64) {
// let v = wait(Duration::from_millis(i)).await;
// sender.send(v).unwrap();
sender.send(wait(Duration::from_millis(i)).await).unwrap();
}
fn main() {
let (sender, receiver) = mpsc::channel();
let thread_pool = ThreadPool::new().unwrap();
for i in (0..10).rev() {
thread_pool.spawn_ok(add_task(sender.clone(), i * 100));
}
drop(sender);
for v in receiver {
println!("{}", v);
}
} While using these dependencies: [dependencies]
futures = { version = "0.3", features = [ "thread-pool" ] } results in this error:
It's worth noting the the commented version works. Using |
Minimized: struct NotSync(*const ());
async fn async_not_sync() {
let a = NotSync(0 as *const ());
// Uncomment this line to see a better error
//let b: *const ();
// Force 'a' to be live across a yield point
async fn dummy() {}
dummy().await;
}
fn require_sync<T: Sync>(val: T) {}
fn main() {
require_sync(async_not_sync());
} It seems that the better error message is only being triggered by certain |
Possibly helped by #65345 as well |
Marking as "triaged". Not promoting to "on deck" for now -- it seems likely though that existing PRs cover it. We should land those already! |
#65345 produces the following error for @Aaron1011's minimized example:
|
Close as errors reduced. |
I will admit that this specific
async fn
is a bit long, but I'd like the compiler to tell me in a different way. (Actual reason is addition of one line borrowing the wrong type across an.await
boundary, of course)Like this, we're coming out ahead of C++ 😄
The text was updated successfully, but these errors were encountered: