Closed
Description
Code
async fn async_dummy() {}
async fn async_dummy2() {}
fn main() {
let _ = if true {
async_dummy()
} else {
async_dummy2()
};
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0308]: `if` and `else` have incompatible types
--> src/main.rs:10:9
|
7 | let _ = if true {
| _____________-
8 | | async_dummy()
| | ------------- expected because of this
9 | | } else {
10 | | async_dummy2()
| | ^^^^^^^^^^^^^^ expected opaque type, found a different opaque type
11 | | };
| |_____- `if` and `else` have incompatible types
Desired output
No response
Rationale and extra context
We start a discussion on zulip regarding this that is available here where we noted that this suggestion is not helpful at all, but also we noted that it is difficult make a helpful suggestion in this case because there is the question that a user may ask to himself when reading the error message:
- What is it an opaque type?
Future<Output = ()>
is equal toFuture<Output = ()>
- Why two futures are not equal?a
Other cases
No response
Anything else?
A possible solution for this can be:
- Do not try to be too smart in some corner case like this, and in this case, I would like an error like
You can not return two different futures inside an if-else block. rustc --explain ...
- make a specific explanation on why we can not compare these two types
- In case of the future generate a note that the user may want to call await on each branch
- change the
opaque type
string intofuture
string when applicable
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Messages for errors, warnings, and lintsAsync-await issues that have been triaged during a working group meeting.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done