]> git.lizzy.rs Git - rust.git/blob - tests/ui/async_yields_async.rs
Add a lint for an async block/closure that yields a type that is itself awaitable.
[rust.git] / tests / ui / async_yields_async.rs
1 // run-rustfix
2 // edition:2018
3
4 #![feature(async_closure)]
5 #![warn(clippy::async_yields_async)]
6
7 use core::future::Future;
8 use core::pin::Pin;
9 use core::task::{Context, Poll};
10
11 struct CustomFutureType;
12
13 impl Future for CustomFutureType {
14     type Output = u8;
15
16     fn poll(self: Pin<&mut Self>, _: &mut Context) -> Poll<Self::Output> {
17         Poll::Ready(3)
18     }
19 }
20
21 fn custom_future_type_ctor() -> CustomFutureType {
22     CustomFutureType
23 }
24
25 #[rustfmt::skip]
26 fn main() {
27     let _f = {
28         3
29     };
30     let _g = async {
31         3
32     };
33     let _h = async {
34         async {
35             3
36         }
37     };
38     let _i = async {
39         CustomFutureType
40     };
41     let _i = async || {
42         3
43     };
44     let _j = async || {
45         async {
46             3
47         }
48     };
49     let _k = async || {
50         CustomFutureType
51     };
52     let _l = async || CustomFutureType;
53     let _m = async || {
54         println!("I'm bored");
55         // Some more stuff
56
57         // Finally something to await
58         CustomFutureType
59     };
60     let _n = async || custom_future_type_ctor();
61 }