]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/async_yields_async.fixed
Rollup merge of #102412 - joboet:dont_panic, r=m-ou-se
[rust.git] / src / tools / clippy / tests / ui / async_yields_async.fixed
1 // run-rustfix
2 #![feature(lint_reasons)]
3 #![feature(async_closure)]
4 #![warn(clippy::async_yields_async)]
5
6 use core::future::Future;
7 use core::pin::Pin;
8 use core::task::{Context, Poll};
9
10 struct CustomFutureType;
11
12 impl Future for CustomFutureType {
13     type Output = u8;
14
15     fn poll(self: Pin<&mut Self>, _: &mut Context) -> Poll<Self::Output> {
16         Poll::Ready(3)
17     }
18 }
19
20 fn custom_future_type_ctor() -> CustomFutureType {
21     CustomFutureType
22 }
23
24 async fn f() -> CustomFutureType {
25     // Don't warn for functions since you have to explicitly declare their
26     // return types.
27     CustomFutureType
28 }
29
30 #[rustfmt::skip]
31 fn main() {
32     let _f = {
33         3
34     };
35     let _g = async {
36         3
37     };
38     let _h = async {
39         async {
40             3
41         }.await
42     };
43     let _i = async {
44         CustomFutureType.await
45     };
46     let _i = async || {
47         3
48     };
49     let _j = async || {
50         async {
51             3
52         }.await
53     };
54     let _k = async || {
55         CustomFutureType.await
56     };
57     let _l = async || CustomFutureType.await;
58     let _m = async || {
59         println!("I'm bored");
60         // Some more stuff
61
62         // Finally something to await
63         CustomFutureType.await
64     };
65     let _n = async || custom_future_type_ctor();
66     let _o = async || f();
67 }
68
69 #[rustfmt::skip]
70 #[allow(dead_code)]
71 fn check_expect_suppression() {
72     #[expect(clippy::async_yields_async)]
73     let _j = async || {
74         async {
75             3
76         }
77     };
78 }