-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest return type for async function without return type
- Loading branch information
Showing
4 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// edition:2018 | ||
|
||
async fn hello() { //~ HELP try adding a return type | ||
0 | ||
//~^ ERROR [E0308] | ||
} | ||
|
||
async fn world() -> () { | ||
0 | ||
//~^ ERROR [E0308] | ||
} | ||
|
||
async fn suggest_await_in_async_fn_return() { | ||
hello() | ||
//~^ ERROR mismatched types [E0308] | ||
//~| HELP consider `await`ing on the `Future` | ||
//~| HELP consider using a semicolon here | ||
//~| SUGGESTION .await | ||
} | ||
|
||
fn main() {} |
36 changes: 36 additions & 0 deletions
36
tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-90027-async-fn-return-suggestion.rs:4:5 | ||
| | ||
LL | async fn hello() { | ||
| - help: try adding a return type: `-> i32` | ||
LL | 0 | ||
| ^ expected `()`, found integer | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-90027-async-fn-return-suggestion.rs:9:5 | ||
| | ||
LL | async fn world() -> () { | ||
| -- expected `()` because of return type | ||
LL | 0 | ||
| ^ expected `()`, found integer | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-90027-async-fn-return-suggestion.rs:14:5 | ||
| | ||
LL | hello() | ||
| ^^^^^^^ expected `()`, found opaque type | ||
| | ||
= note: expected unit type `()` | ||
found opaque type `impl Future<Output = ()>` | ||
help: consider `await`ing on the `Future` | ||
| | ||
LL | hello().await | ||
| ++++++ | ||
help: consider using a semicolon here | ||
| | ||
LL | hello(); | ||
| + | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |