Repository navigation
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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
The following works, since foo and bar return (), so the expression is simply returned:
fn foo() {}
fn bar() {
foo()
}The "equivalent" code in the async context yields a compiler error:
async fn foo() {}
async fn bar() {
foo()
}error[E0308]: mismatched types
--> src/main.rs:62:5
|
62 | foo()
| ^^^^^- help: try adding a semicolon: `;`
| |
| expected (), found opaque type
|
= note: expected type `()`
found type `impl core::future::future::Future`
The help message would be correct for non-async-code with mismatched types, but in the async case a .await should be suggested.
Technically the current help message is correct, but leads to another warning (that can be even overlooked):
warning: unused implementer of `core::future::future::Future` that must be used
--> src/main.rs:62:5
|
62 | foo();
| ^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
= note: futures do nothing unless you `.await` or poll them
So you have to do a second compile iteration.
I'd suggest to spawn a help message like that:
error[E0308]: mismatched types
--> src/main.rs:62:5
|
62 | foo()
| ^^^^^- help: try to await the future: `.await`
| |
| expected (), found opaque type
|
= note: expected type `()`
found type `impl core::future::future::Future`
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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
jfrimmel commentedon Nov 30, 2019
Note: this is the message with the current nightly (rustc 1.41.0-nightly (25d8a94 2019-11-29)).
Rust 1.39 does not even spawn the help message
nikomatsakis commentedon Dec 3, 2019
Async await traige: marking as on-deck, as suggesting the use of
.awaitseems pretty useful and generalAaron1011 commentedon Dec 3, 2019
I started working on this, then realized that it already exists: #62067
However, it looks like we don't currently attempt to emit suggestions for certain coercions (including the return type coercion), which is why it doesn't show up here. I'm working on emitting coercion suggestions in more places.
Aaron1011 commentedon Dec 3, 2019
@rustbot claim
Emit coercion suggestions in more places
Rollup merge of rust-lang#67009 - Aaron1011:fix/coerce-suggestion, r=…