@@ -12,31 +12,34 @@ declare_clippy_lint! {
1212 /// Warns about a field in a `Send` struct that is neither `Send` nor `Copy`.
1313 ///
1414 /// ### 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)
1923 ///
2024 /// ### Known Problems
2125 /// Data structures that contain raw pointers may cause false positives.
2226 /// They are sometimes safe to be sent across threads but do not implement
2327 /// 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.
2530 ///
2631 /// ### 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,
3836 /// }
37+ ///
38+ /// // This impl is unsound because it allows sending `!Send` types through `ExampleStruct`
39+ /// unsafe impl<T> Send for ExampleStruct<T> {}
3940 /// ```
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`).
4043 pub NON_SEND_FIELD_IN_SEND_TY ,
4144 nursery,
4245 "there is field that does not implement `Send` in a `Send` struct"
0 commit comments