]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/non_send_fields_in_send_ty.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / non_send_fields_in_send_ty.txt
CommitLineData
f2b60f7d
FG
1### What it does
2This lint warns about a `Send` implementation for a type that
3contains fields that are not safe to be sent across threads.
4It tries to detect fields that can cause a soundness issue
5when sent to another thread (e.g., `Rc`) while allowing `!Send` fields
6that are expected to exist in a `Send` type, such as raw pointers.
7
8### Why is this bad?
9Sending the struct to another thread effectively sends all of its fields,
10and the fields that do not implement `Send` can lead to soundness bugs
11such as data races when accessed in a thread
12that is different from the thread that created it.
13
14See:
15* [*The Rustonomicon* about *Send and Sync*](https://doc.rust-lang.org/nomicon/send-and-sync.html)
16* [The documentation of `Send`](https://doc.rust-lang.org/std/marker/trait.Send.html)
17
18### Known Problems
19This lint relies on heuristics to distinguish types that are actually
20unsafe to be sent across threads and `!Send` types that are expected to
21exist in `Send` type. Its rule can filter out basic cases such as
22`Vec<*const T>`, but it's not perfect. Feel free to create an issue if
23you have a suggestion on how this heuristic can be improved.
24
25### Example
26```
27struct ExampleStruct<T> {
28 rc_is_not_send: Rc<String>,
29 unbounded_generic_field: T,
30}
31
32// This impl is unsound because it allows sending `!Send` types through `ExampleStruct`
33unsafe impl<T> Send for ExampleStruct<T> {}
34```
35Use thread-safe types like [`std::sync::Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html)
36or specify correct bounds on generic type parameters (`T: Send`).