]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/suggest-missing-await.rs
Rollup merge of #103766 - lukas-code:error-in-core, r=Dylan-DPC
[rust.git] / src / test / ui / async-await / suggest-missing-await.rs
1 // edition:2018
2
3 fn take_u32(_x: u32) {}
4
5 async fn make_u32() -> u32 {
6     22
7 }
8
9 #[allow(unused)]
10 async fn suggest_await_in_async_fn() {
11     let x = make_u32();
12     take_u32(x)
13     //~^ ERROR mismatched types [E0308]
14     //~| HELP consider `await`ing on the `Future`
15     //~| SUGGESTION .await
16 }
17
18 async fn dummy() {}
19
20 #[allow(unused)]
21 async fn suggest_await_in_async_fn_return() {
22     dummy()
23     //~^ ERROR mismatched types [E0308]
24     //~| HELP consider `await`ing on the `Future`
25     //~| HELP consider using a semicolon here
26     //~| SUGGESTION .await
27 }
28
29 #[allow(unused)]
30 async fn suggest_await_on_if() {
31     let _x = if true {
32         dummy()
33         //~^ HELP consider `await`ing on the `Future`
34     } else {
35         dummy().await
36         //~^ ERROR `if` and `else` have incompatible types [E0308]
37     };
38 }
39
40 #[allow(unused)]
41 async fn suggest_await_on_previous_match_arms() {
42     let _x = match 0usize {
43         0 => dummy(), //~ HELP consider `await`ing on the `Future`
44         1 => dummy(),
45         2 => dummy().await,
46         //~^ `match` arms have incompatible types [E0308]
47     };
48 }
49
50 #[allow(unused)]
51 async fn suggest_await_on_match_expr() {
52     let _x = match dummy() { //~ HELP consider `await`ing on the `Future`
53         () => {} //~ ERROR mismatched types [E0308]
54     };
55 }
56
57 async fn dummy_result() -> Result<(), ()> {
58     Ok(())
59 }
60
61 #[allow(unused)]
62 async fn suggest_await_in_generic_pattern() {
63     match dummy_result() {
64         //~^ HELP consider `await`ing on the `Future`
65         //~| HELP consider `await`ing on the `Future`
66         //~| SUGGESTION .await
67         Ok(_) => {}
68         //~^ ERROR mismatched types [E0308]
69         Err(_) => {}
70         //~^ ERROR mismatched types [E0308]
71     }
72 }
73
74 fn main() {}