]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/future_not_send.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / future_not_send.txt
1 ### What it does
2 This lint requires Future implementations returned from
3 functions and methods to implement the `Send` marker trait. It is mostly
4 used by library authors (public and internal) that target an audience where
5 multithreaded executors are likely to be used for running these Futures.
6
7 ### Why is this bad?
8 A Future implementation captures some state that it
9 needs to eventually produce its final value. When targeting a multithreaded
10 executor (which is the norm on non-embedded devices) this means that this
11 state may need to be transported to other threads, in other words the
12 whole Future needs to implement the `Send` marker trait. If it does not,
13 then the resulting Future cannot be submitted to a thread pool in the
14 end user’s code.
15
16 Especially for generic functions it can be confusing to leave the
17 discovery of this problem to the end user: the reported error location
18 will be far from its cause and can in many cases not even be fixed without
19 modifying the library where the offending Future implementation is
20 produced.
21
22 ### Example
23 ```
24 async fn not_send(bytes: std::rc::Rc<[u8]>) {}
25 ```
26 Use instead:
27 ```
28 async fn is_send(bytes: std::sync::Arc<[u8]>) {}
29 ```