File: suggest-missing-await.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (81 lines) | stat: -rw-r--r-- 1,891 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//@ edition:2018

fn take_u32(_x: u32) {}

async fn make_u32() -> u32 {
    22
}

#[allow(unused)]
async fn suggest_await_in_async_fn() {
    let x = make_u32();
    take_u32(x)
    //~^ ERROR mismatched types [E0308]
    //~| HELP consider `await`ing on the `Future`
    //~| SUGGESTION .await
}

async fn dummy() {}

#[allow(unused)]
async fn suggest_await_in_async_fn_return() {
    dummy()
    //~^ ERROR mismatched types [E0308]
    //~| HELP consider `await`ing on the `Future`
    //~| HELP consider using a semicolon here
    //~| SUGGESTION .await
}

#[allow(unused)]
async fn suggest_await_on_if() {
    let _x = if true {
        dummy()
        //~^ HELP consider `await`ing on the `Future`
    } else {
        dummy().await
        //~^ ERROR `if` and `else` have incompatible types [E0308]
    };
}

#[allow(unused)]
async fn suggest_await_on_previous_match_arms() {
    let _x = match 0usize {
        0 => dummy(), //~ HELP consider `await`ing on the `Future`
        1 => dummy(),
        2 => dummy().await,
        //~^ `match` arms have incompatible types [E0308]
    };
}

#[allow(unused)]
async fn suggest_await_on_match_expr() {
    let _x = match dummy() { //~ HELP consider `await`ing on the `Future`
        () => {} //~ ERROR mismatched types [E0308]
    };
}

async fn dummy_result() -> Result<(), ()> {
    Ok(())
}

#[allow(unused)]
async fn suggest_await_in_generic_pattern() {
    match dummy_result() {
        //~^ HELP consider `await`ing on the `Future`
        //~| HELP consider `await`ing on the `Future`
        //~| SUGGESTION .await
        Ok(_) => {}
        //~^ ERROR mismatched types [E0308]
        Err(_) => {}
        //~^ ERROR mismatched types [E0308]
    }
}

// Issue #126903
async fn do_async() {}
fn dont_suggest_awaiting_closure_patterns() {
    Some(do_async()).map(|()| {});
    //~^ ERROR mismatched types [E0308]
}

fn main() {}