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 // Test types that contain `NonNull` instead of raw pointers (#8045)
73 pub struct WrappedNonNull(UnsafeCell<NonNull<()>>);
75 unsafe impl Send for WrappedNonNull {}
77 // Multiple type parameters
78 pub struct MultiParam<A, B> {
82 unsafe impl<A, B> Send for MultiParam<A, B> {}
84 // Tests for raw pointer heuristic
89 pub struct HeuristicTest {
90 // raw pointers are allowed
91 field1: Vec<*const NonSend>,
92 field2: [*const NonSend; 3],
93 field3: (*const NonSend, *const NonSend, *const NonSend),
94 // not allowed when it contains concrete `!Send` field
95 field4: (*const NonSend, Rc<u8>),
96 // nested raw pointer is also allowed
97 field5: Vec<Vec<*const NonSend>>,
100 unsafe impl Send for HeuristicTest {}
103 #[allow(clippy::non_send_fields_in_send_ty)]
104 pub struct AttrTest1<T>(T);
106 pub struct AttrTest2<T> {
107 #[allow(clippy::non_send_fields_in_send_ty)]
111 pub enum AttrTest3<T> {
112 #[allow(clippy::non_send_fields_in_send_ty)]
117 unsafe impl<T> Send for AttrTest1<T> {}
118 unsafe impl<T> Send for AttrTest2<T> {}
119 unsafe impl<T> Send for AttrTest3<T> {}
121 // Multiple non-overlapping `Send` for a single type
122 pub struct Complex<A, B> {
127 unsafe impl<P> Send for Complex<P, u32> {}
129 // `MutexGuard` is non-Send
130 unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}