@@ -12,31 +12,34 @@ declare_clippy_lint! {
12
12
/// Warns about a field in a `Send` struct that is neither `Send` nor `Copy`.
13
13
///
14
14
/// ### Why is this bad?
15
- /// Sending the struct to another thread and drops it there will also drop
16
- /// the field in the new thread. This effectively changes the ownership of
17
- /// the field type to the new thread and creates a soundness issue by
18
- /// breaking the non-`Send` invariant.
15
+ /// Sending the struct to another thread will transfer the ownership to
16
+ /// the new thread by dropping in the current thread during the transfer.
17
+ /// This causes soundness issues for non-`Send` fields, as they are also
18
+ /// dropped and might not be set up to handle this.
19
+ ///
20
+ /// See:
21
+ /// * [*The Rustonomicon* about *Send and Sync*](https://doc.rust-lang.org/nomicon/send-and-sync.html)
22
+ /// * [The documentation of `Send`](https://doc.rust-lang.org/std/marker/trait.Send.html)
19
23
///
20
24
/// ### Known Problems
21
25
/// Data structures that contain raw pointers may cause false positives.
22
26
/// They are sometimes safe to be sent across threads but do not implement
23
27
/// the `Send` trait. This lint has a heuristic to filter out basic cases
24
- /// such as `Vec<*const T>`, but it's not perfect.
28
+ /// such as `Vec<*const T>`, but it's not perfect. Feel free to create an
29
+ /// issue if you have a suggestion on how this heuristic can be improved.
25
30
///
26
31
/// ### Example
27
- /// ```rust
28
- /// use std::sync::Arc;
29
- ///
30
- /// // There is no `RC: Send` bound here
31
- /// unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
32
- ///
33
- /// #[derive(Debug, Clone)]
34
- /// pub struct ArcGuard<RC, T> {
35
- /// inner: T,
36
- /// // Possibly drops `Arc<RC>` (and in turn `RC`) on a wrong thread
37
- /// head: Arc<RC>
32
+ /// ```rust,ignore
33
+ /// struct ExampleStruct<T> {
34
+ /// rc_is_not_send: Rc<String>,
35
+ /// unbounded_generic_field: T,
38
36
/// }
37
+ ///
38
+ /// // This impl is unsound because it allows sending `!Send` types through `ExampleStruct`
39
+ /// unsafe impl<T> Send for ExampleStruct<T> {}
39
40
/// ```
41
+ /// Use thread-safe types like [`std::sync::Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html)
42
+ /// and specify correct bounds on generic type parameters (`T: Send`).
40
43
pub NON_SEND_FIELD_IN_SEND_TY ,
41
44
nursery,
42
45
"there is field that does not implement `Send` in a `Send` struct"
0 commit comments