1 #![warn(clippy::non_send_fields_in_send_ty)]
2 #![feature(extern_types)]
4 use std::cell::UnsafeCell;
7 use std::sync::{Arc, Mutex, MutexGuard};
9 // disrustor / RUSTSEC-2020-0150
10 pub struct RingBuffer<T> {
11 data: Vec<UnsafeCell<T>>,
16 unsafe impl<T> Send for RingBuffer<T> {}
18 // noise_search / RUSTSEC-2020-0141
19 pub struct MvccRwLock<T> {
24 unsafe impl<T> Send for MvccRwLock<T> {}
26 // async-coap / RUSTSEC-2020-0124
27 pub struct ArcGuard<RC, T> {
32 unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
34 // rusb / RUSTSEC-2020-0098
36 type libusb_device_handle;
39 pub trait UsbContext {
40 // some user trait that does not guarantee `Send`
43 pub struct DeviceHandle<T: UsbContext> {
45 handle: NonNull<libusb_device_handle>,
48 unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
51 pub struct NoGeneric {
52 rc_is_not_send: Rc<String>,
55 unsafe impl Send for NoGeneric {}
57 pub struct MultiField<T> {
63 unsafe impl<T> Send for MultiField<T> {}
65 pub enum MyOption<T> {
70 unsafe impl<T> Send for MyOption<T> {}
72 // Multiple type parameters
73 pub struct MultiParam<A, B> {
77 unsafe impl<A, B> Send for MultiParam<A, B> {}
79 // Tests for raw pointer heuristic
84 pub struct HeuristicTest {
85 // raw pointers are allowed
86 field1: Vec<*const NonSend>,
87 field2: [*const NonSend; 3],
88 field3: (*const NonSend, *const NonSend, *const NonSend),
89 // not allowed when it contains concrete `!Send` field
90 field4: (*const NonSend, Rc<u8>),
91 // nested raw pointer is also allowed
92 field5: Vec<Vec<*const NonSend>>,
95 unsafe impl Send for HeuristicTest {}
98 #[allow(clippy::non_send_fields_in_send_ty)]
99 pub struct AttrTest1<T>(T);
101 pub struct AttrTest2<T> {
102 #[allow(clippy::non_send_fields_in_send_ty)]
106 pub enum AttrTest3<T> {
107 #[allow(clippy::non_send_fields_in_send_ty)]
112 unsafe impl<T> Send for AttrTest1<T> {}
113 unsafe impl<T> Send for AttrTest2<T> {}
114 unsafe impl<T> Send for AttrTest3<T> {}
116 // Multiple non-overlapping `Send` for a single type
117 pub struct Complex<A, B> {
122 unsafe impl<P> Send for Complex<P, u32> {}
124 // `MutexGuard` is non-Send
125 unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}