-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
note_obligation_cause reporting for non-async/await not optimal #70818
Comments
Hmm, so the error message for the second example is the following:
I think it would be helpful to try and enumerate what the "ideal" error in these two cases would look like. I see a few problems:
|
@nikomatsakis Also, I think what happened in the past is that #64895 + #65345 improved the errors when a value is kept across an So this might be a strawman example we've stumbled over? |
We could fix this by outputting the nicer error messages, which does seem to happen anytime there exists an The reason we don't output the nice error messages is that this code doesn't create a async fn noop() {}
async fn foo<T>(x: T) -> T {
noop().await;
x
}
fn assert_send(_: impl Send) {}
fn test<T>(x: T) {
assert_send(foo(x));
}
However, this logic can still lead to bad diagnostics for captured vars. For example, when we drop async fn noop() {}
async fn foo<T>(x: T) {
std::mem::drop(x);
noop().await;
}
fn assert_send(_: impl Send) {}
fn test<T>(x: T) {
assert_send(foo(x));
}
So what we need is a way to express a cause for captured vars which doesn't include an await/yield point, and for the diagnostics code to handle these causes. |
Check non-Send/Sync upvars captured by generator Closes rust-lang#70818 r? @tmandry
Consider the following code:
This produces the following error message in
cargo build
:and the following tooltip in VS Code:
@eddyb asked me to open this issue because the notes are mostly confusing (at least they won’t help mere mortals) and said that the message should not mention GenFuture nor
[static generator ...]
. He used the following code for a larger error message (playground):/cc @davidtwco @nikomatsakis
The text was updated successfully, but these errors were encountered: