1 #![warn(clippy::non_send_fields_in_send_ty)]
2 #![allow(suspicious_auto_trait_impls)]
3 #![feature(extern_types)]
5 use std::cell::UnsafeCell;
8 use std::sync::{Arc, Mutex, MutexGuard};
10 // disrustor / RUSTSEC-2020-0150
11 pub struct RingBuffer<T> {
12 data: Vec<UnsafeCell<T>>,
17 unsafe impl<T> Send for RingBuffer<T> {}
19 // noise_search / RUSTSEC-2020-0141
20 pub struct MvccRwLock<T> {
25 unsafe impl<T> Send for MvccRwLock<T> {}
27 // async-coap / RUSTSEC-2020-0124
28 pub struct ArcGuard<RC, T> {
33 unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
35 // rusb / RUSTSEC-2020-0098
37 type libusb_device_handle;
40 pub trait UsbContext {
41 // some user trait that does not guarantee `Send`
44 pub struct DeviceHandle<T: UsbContext> {
46 handle: NonNull<libusb_device_handle>,
49 unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
52 pub struct NoGeneric {
53 rc_is_not_send: Rc<String>,
56 unsafe impl Send for NoGeneric {}
58 pub struct MultiField<T> {
64 unsafe impl<T> Send for MultiField<T> {}
66 pub enum MyOption<T> {
71 unsafe impl<T> Send for MyOption<T> {}
73 // Test types that contain `NonNull` instead of raw pointers (#8045)
74 pub struct WrappedNonNull(UnsafeCell<NonNull<()>>);
76 unsafe impl Send for WrappedNonNull {}
78 // Multiple type parameters
79 pub struct MultiParam<A, B> {
83 unsafe impl<A, B> Send for MultiParam<A, B> {}
85 // Tests for raw pointer heuristic
90 pub struct HeuristicTest {
91 // raw pointers are allowed
92 field1: Vec<*const NonSend>,
93 field2: [*const NonSend; 3],
94 field3: (*const NonSend, *const NonSend, *const NonSend),
95 // not allowed when it contains concrete `!Send` field
96 field4: (*const NonSend, Rc<u8>),
97 // nested raw pointer is also allowed
98 field5: Vec<Vec<*const NonSend>>,
101 unsafe impl Send for HeuristicTest {}
104 #[allow(clippy::non_send_fields_in_send_ty)]
105 pub struct AttrTest1<T>(T);
107 pub struct AttrTest2<T> {
108 #[allow(clippy::non_send_fields_in_send_ty)]
112 pub enum AttrTest3<T> {
113 #[allow(clippy::non_send_fields_in_send_ty)]
118 unsafe impl<T> Send for AttrTest1<T> {}
119 unsafe impl<T> Send for AttrTest2<T> {}
120 unsafe impl<T> Send for AttrTest3<T> {}
122 // Multiple non-overlapping `Send` for a single type
123 pub struct Complex<A, B> {
128 unsafe impl<P> Send for Complex<P, u32> {}
130 // `MutexGuard` is non-Send
131 unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}