diff options
| author | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2023-02-05 14:22:41 +0800 |
|---|---|---|
| committer | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2023-02-06 13:02:04 +0800 |
| commit | 6b05b80690fe6548b49da46f85b9ec7b1ea95e7e (patch) | |
| tree | 69b0a84b7212e8c46dfdc23844306bd3fa14db1d /tests | |
| parent | 50d3ba5bcbf5c7e13d4ce068d3339710701dd603 (diff) | |
| download | rust-6b05b80690fe6548b49da46f85b9ec7b1ea95e7e.tar.gz rust-6b05b80690fe6548b49da46f85b9ec7b1ea95e7e.zip | |
Suggest return type for async function without return type
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/typeck/issue-90027-async-fn-return-suggestion.rs | 21 | ||||
| -rw-r--r-- | tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr | 36 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/ui/typeck/issue-90027-async-fn-return-suggestion.rs b/tests/ui/typeck/issue-90027-async-fn-return-suggestion.rs new file mode 100644 index 00000000000..8ccb15ca48a --- /dev/null +++ b/tests/ui/typeck/issue-90027-async-fn-return-suggestion.rs @@ -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() {} diff --git a/tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr b/tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr new file mode 100644 index 00000000000..6a1a9f45bc6 --- /dev/null +++ b/tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr @@ -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`. |
