summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/async_yields_async.rs
blob: dd4131b60ab3ae6b697d5257601fd2630edbb30e (plain)
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
// run-rustfix
#![feature(lint_reasons)]
#![feature(async_closure)]
#![warn(clippy::async_yields_async)]

use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll};

struct CustomFutureType;

impl Future for CustomFutureType {
    type Output = u8;

    fn poll(self: Pin<&mut Self>, _: &mut Context) -> Poll<Self::Output> {
        Poll::Ready(3)
    }
}

fn custom_future_type_ctor() -> CustomFutureType {
    CustomFutureType
}

async fn f() -> CustomFutureType {
    // Don't warn for functions since you have to explicitly declare their
    // return types.
    CustomFutureType
}

#[rustfmt::skip]
fn main() {
    let _f = {
        3
    };
    let _g = async {
        3
    };
    let _h = async {
        async {
            3
        }
    };
    let _i = async {
        CustomFutureType
    };
    let _i = async || {
        3
    };
    let _j = async || {
        async {
            3
        }
    };
    let _k = async || {
        CustomFutureType
    };
    let _l = async || CustomFutureType;
    let _m = async || {
        println!("I'm bored");
        // Some more stuff

        // Finally something to await
        CustomFutureType
    };
    let _n = async || custom_future_type_ctor();
    let _o = async || f();
}

#[rustfmt::skip]
#[allow(dead_code)]
fn check_expect_suppression() {
    #[expect(clippy::async_yields_async)]
    let _j = async || {
        async {
            3
        }
    };
}