1 #![allow(unused, clippy::manual_async_fn)]
2 #![warn(clippy::redundant_async_block)]
4 use std::future::Future;
6 async fn func1(n: usize) -> usize {
10 async fn func2() -> String {
11 let s = String::from("some string");
12 let f = async { (*s).to_owned() };
18 let fut1 = async { 17 };
22 let fut1 = async { 25 };
27 let fut = async { 42 };
29 // Do not lint: not a single expression
35 // Do not lint: expression contains `.await`
36 let fut = async { func1(func2().await.len()).await };
39 #[allow(clippy::let_and_return)]
40 fn capture_local() -> impl Future<Output = i32> {
41 let fut = async { 17 };
46 fn capture_local_closure(s: &str) -> impl Future<Output = &str> {
47 let f = move || std::future::ready(s);
48 // Do not lint: `f` would not live long enough
49 async move { f().await }
52 #[allow(clippy::let_and_return)]
53 fn capture_arg(s: &str) -> impl Future<Output = &str> {
54 let fut = async move { s };
59 fn capture_future_arg<T>(f: impl Future<Output = T>) -> impl Future<Output = T> {
64 fn capture_func_result<FN, F, T>(f: FN) -> impl Future<Output = T>
66 F: Future<Output = T>,
69 // Do not lint, as f() would be evaluated prematurely
73 fn double_future(f: impl Future<Output = impl Future<Output = u32>>) -> impl Future<Output = u32> {
74 // Do not lint, we will get a `.await` outside a `.async`
75 async { f.await.await }
78 fn await_in_async<F, R>(f: F) -> impl Future<Output = u32>
81 R: Future<Output = u32>,
84 async { f().await + 1 }
87 #[derive(Debug, Clone)]
91 async fn run(&self) {}
97 // Do not lint: `c` would not live long enough
98 spawn(async move { c.run().await });
102 fn spawn<F: Future + 'static>(_: F) {}
104 async fn work(_: &str) {}
107 let val = "Hello World".to_owned();
108 // Do not lint: `val` would not live long enough
109 spawn(async { work(&{ val }).await });
112 fn await_from_macro() -> impl Future<Output = u32> {
118 // Do not lint: the macro may change in the future
119 // or return different things depending on its argument
120 async { mac!(async { 42 }) }
123 fn async_expr_from_macro() -> impl Future<Output = u32> {
129 // Do not lint: the macro may change in the future
130 async { mac!().await }
133 fn async_expr_from_macro_deep() -> impl Future<Output = u32> {
139 // Do not lint: the macro may change in the future
140 async { ({ mac!() }).await }
143 fn all_from_macro() -> impl Future<Output = u32> {
153 fn parts_from_macro() -> impl Future<Output = u32> {
156 // Do not lint: `$e` might not always be side-effect free
163 fn safe_parts_from_macro() -> impl Future<Output = u32> {
173 fn parts_from_macro_deep() -> impl Future<Output = u32> {
176 // Do not lint: `$e` might not always be side-effect free
177 async { ($e,).0.await }
180 let f = std::future::ready(42);
184 fn await_from_macro_deep() -> impl Future<Output = u32> {
186 ($e:expr) => {{ $e }.await};
188 // Do not lint: the macro may change in the future
189 // or return different things depending on its argument
190 async { mac!(async { 42 }) }