-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
More friendly error msg when await on NONE ASYNC fn/block or return a obj that implements deprecated Future #66731
Comments
After #66651 is merged, adding a |
@estebank I don't think it will, |
Handling the second case (a future from some older version of the futures crate) doesn't seem worth the effort. I think those will vanish over time. Handling the case like |
Marking as "on-deck", I think that helping people identify cases where they put |
One note: I'm not sure if "on unimplemented" is the right implementation approach. Ideally, we would suggest that the user make |
CC #61076 |
So @nellshamrell and I did a bit of a deep-dive. We added the "on unimplemented" annotation to at least give an error message like "
I was looking into how we can do this but it's tricky. Currently, the message we get has the rust/src/librustc_ast_lowering/expr.rs Lines 578 to 581 in f315c35
but what we really want is the expression here: rust/src/librustc_ast_lowering/expr.rs Line 576 in f315c35
However, I did have an interesting idea -- or maybe an evil one? I realized that if we reorder these lines that are part of lowering rust/src/librustc_ast_lowering/expr.rs Lines 606 to 612 in f315c35
In other words, this might look something like: let expr = self.lower_expr(expr);
let span = self.mark_span_with_reason(
DesugaringKind::Await(expr.hir_id), await_span, None);
let gen_future_span = self.mark_span_with_reason(
DesugaringKind::Await(expr.hir_id),
await_span,
self.allow_gen_future.clone(),
); This would then allow us to inspect the "desugaring kind" from within the trait code and uncover the hir-id we are interested in. I imagine a similar technique might be useful for things like the desugaring of I'm curious @estebank what you think of that idea. At first, it surprised me, because it seemed strange to have |
That seems like a potentially quite useful pattern for |
OK, do you think it merits an MCP? I was debating about it. =) |
@petrochenkov I'm curious to get your reaction to this idea |
I was talking to @henryboisdequin a bit on Zulip and wanted to leave a few notes for detailed reference: Roughly the code we want to be editing is rust/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs Lines 225 to 231 in ec487bf
and the general idea is something like
|
Doing triage cleanup. @rustbot release-assignment @henryboisdequin if you're still working on this, feel free to re-claim |
Here is my memory of how far we got: @henryboisdequin was investigating and discovered that adding the It occurs to me that we we could also split out the definition of the various "ids" from I think at this point I would be ok with either solution, but it's probably worth trying to split out the types first. |
Desired output:
|
@rustbot claim |
Opened #90939. Identifying that the Edit: fully addressed:
|
Keep track of the origin of a `T: Future` obligation when caused by an `.await` expression. Address rust-lang#66731.
Tweak errors coming from `for`-loop, `?` and `.await` desugaring * Suggest removal of `.await` on non-`Future` expression * Keep track of obligations introduced by desugaring * Remove span pointing at method for obligation errors coming from desugaring * Point at called local sync `fn` and suggest making it `async` ``` error[E0277]: `()` is not a future --> $DIR/unnecessary-await.rs:9:10 | LL | boo().await; | -----^^^^^^ `()` is not a future | | | this call returns `()` | = help: the trait `Future` is not implemented for `()` help: do not `.await` the expression | LL - boo().await; LL + boo(); | help: alternatively, consider making `fn boo` asynchronous | LL | async fn boo () {} | +++++ ``` Fix rust-lang#66731.
Keep track of the origin of a `T: Future` obligation when caused by an `.await` expression. Address rust-lang#66731.
Tweak errors coming from `for`-loop, `?` and `.await` desugaring * Suggest removal of `.await` on non-`Future` expression * Keep track of obligations introduced by desugaring * Remove span pointing at method for obligation errors coming from desugaring * Point at called local sync `fn` and suggest making it `async` ``` error[E0277]: `()` is not a future --> $DIR/unnecessary-await.rs:9:10 | LL | boo().await; | -----^^^^^^ `()` is not a future | | | this call returns `()` | = help: the trait `Future` is not implemented for `()` help: do not `.await` the expression | LL - boo().await; LL + boo(); | help: alternatively, consider making `fn boo` asynchronous | LL | async fn boo () {} | +++++ ``` Fix rust-lang#66731.
Tweak errors coming from `for`-loop, `?` and `.await` desugaring * Suggest removal of `.await` on non-`Future` expression * Keep track of obligations introduced by desugaring * Remove span pointing at method for obligation errors coming from desugaring * Point at called local sync `fn` and suggest making it `async` ``` error[E0277]: `()` is not a future --> $DIR/unnecessary-await.rs:9:10 | LL | boo().await; | -----^^^^^^ `()` is not a future | | | this call returns `()` | = help: the trait `Future` is not implemented for `()` help: do not `.await` the expression | LL - boo().await; LL + boo(); | help: alternatively, consider making `fn boo` asynchronous | LL | async fn boo () {} | +++++ ``` Fix rust-lang#66731.
await need a async function, async block or return a type that impl std::future::Future, did you forget add async before fn boo() ?
You are return a Future that has been droped support or deprecated, maybe try to upgrade to latest version of futures crate?
I think more friendly error message like these will help new comers from javascript -> front end devs to more quickly solve problem, because they don't have multiple
Promise
implements, current error messages will make them very confusing and frustratingThe text was updated successfully, but these errors were encountered: