-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Async blocks are leaky about wording wrt. ?
in diagnostics
#62570
Comments
I ran into this. It's much more confusing if the outer function actually returns a result. In a more complicated function the error message can be a real head scratcher. #![feature(async_await)]
async fn f() -> Result<bool, ()> {
async {
Err(())?
}.await;
Ok(true)
} |
This can be fixed as a rewording to "cannot use the |
This same error message appears for closures: fn main() {
let _ = || {
Err(5)?;
1
};
}
|
At this point there are enough cases that we would want to disambiguate between that it makes sense to extend |
I think something like: #[rustc_on_unimplemented(
on(all(
any(from_method="from_error", from_method="from_ok"),
from_desugaring="QuestionMark"),
message="the `?` operator can only be used in {ItemCtx} \
that returns `Result` or `Option` \
(or another type that implements `{Try}`)",
label="cannot use the `?` operator in {ItemCtx} that returns `{Self}`"),
on(all(from_method="into_result", from_desugaring="QuestionMark"),
message="the `?` operator can only be applied to values \
that implement `{Try}`",
label="the `?` operator cannot be applied to type `{Self}`")
)] would make sense, which is basically @estebank's idea. |
Almost there. Will have a PR for review soon. |
There's almost no difference between an async closure and an async function call in the hir. For now async functions may also have to be reported as being an async closure... |
E.g.
vs:
All the other cases seem fine, but not sure for this one how to proceed... |
Can't you add a field to the relevant hir element to signal the difference? Edit: Looking at the code, pub enum AsyncGeneratorKind {
/// An explicit `async` block written by the user.
Block,
/// An explicit `async` block written by the user.
Closure,
/// The `async` block generated as the body of an async function.
Fn,
} I'm not sure if that gets propagated to the right place where you'd need it, but we already seem to be differentiating between the three cases, right? |
E.g. consider:
which yields the diagnostic:
Ostensibly the user might think of
fn foo
as "the function" but it is in fact theasync
block that is "the function" here. That seems like something which would confuse users who are not familiar with the lowering and whatnot (most users).The text was updated successfully, but these errors were encountered: