Repository navigation
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`Error messages that can be tackled with `#[rustc_on_unimplemented]`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
E.g. consider:
#![feature(async_await)]
fn foo() {
let x = async move {
Err(())?;
1
};
}
which yields the diagnostic:
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
--> src/lib.rs:5:9
|
5 | Err(())?;
| ^^^^^^^^ cannot use the `?` operator in a function that returns `{integer}`
|
= help: the trait `std::ops::Try` is not implemented for `{integer}`
= note: required by `std::ops::Try::from_error`
Ostensibly the user might think of fn foo as "the function" but it is in fact the async 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).
Reacted by Naja Melan and SystemNeo
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`Error messages that can be tackled with `#[rustc_on_unimplemented]`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.
Activity
theduke commentedon Jul 11, 2019
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.
estebank commentedon Aug 26, 2019
This can be fixed as a rewording to "cannot use the
?operator in a function orasyncblock that returns{integer}".cramertj commentedon Aug 28, 2019
This same error message appears for closures:
estebank commentedon Aug 28, 2019
At this point there are enough cases that we would want to disambiguate between that it makes sense to extend
on_unimplementedto have some way of obtaining the enclosing scope's description (closure/function/method/asyncblock, etc.).Centril commentedon Oct 8, 2019
I think something like:
would make sense, which is basically @estebank's idea.
gilescope commentedon Oct 21, 2019
Almost there. Will have a PR for review soon.
gilescope commentedon Oct 26, 2019
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...
gilescope commentedon Oct 27, 2019
E.g.
vs:
All the other cases seem fine, but not sure for this one how to proceed...
estebank commentedon Oct 28, 2019
Can't you add a field to the relevant hir element to signal the difference?
Edit: Looking at the code,
make_async_exprhas an argumentasync_gen_kind: hir::AsyncGeneratorKindwhich isI'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?
Rollup merge of rust-lang#65902 - gilescope:issue62570, r=estebank