]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/unused_async.txt
Rollup merge of #100291 - WaffleLapkin:cstr_const_methods, r=oli-obk
[rust.git] / src / tools / clippy / src / docs / unused_async.txt
1 ### What it does
2 Checks for functions that are declared `async` but have no `.await`s inside of them.
3
4 ### Why is this bad?
5 Async functions with no async code create overhead, both mentally and computationally.
6 Callers of async methods either need to be calling from an async function themselves or run it on an executor, both of which
7 causes runtime overhead and hassle for the caller.
8
9 ### Example
10 ```
11 async fn get_random_number() -> i64 {
12     4 // Chosen by fair dice roll. Guaranteed to be random.
13 }
14 let number_future = get_random_number();
15 ```
16
17 Use instead:
18 ```
19 fn get_random_number_improved() -> i64 {
20     4 // Chosen by fair dice roll. Guaranteed to be random.
21 }
22 let number_future = async { get_random_number_improved() };
23 ```