2021-09-23 07:51:10 +00:00
|
|
|
#![warn(clippy::non_send_field_in_send_ty)]
|
|
|
|
#![feature(extern_types)]
|
|
|
|
|
|
|
|
use std::cell::UnsafeCell;
|
|
|
|
use std::ptr::NonNull;
|
2021-09-23 10:45:24 +00:00
|
|
|
use std::sync::{Arc, Mutex, MutexGuard};
|
2021-09-23 07:51:10 +00:00
|
|
|
|
|
|
|
// disrustor / RUSTSEC-2020-0150
|
|
|
|
pub struct RingBuffer<T> {
|
|
|
|
data: Vec<UnsafeCell<T>>,
|
|
|
|
capacity: usize,
|
|
|
|
mask: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<T> Send for RingBuffer<T> {}
|
|
|
|
|
|
|
|
// noise_search / RUSTSEC-2020-0141
|
|
|
|
pub struct MvccRwLock<T> {
|
|
|
|
raw: *const T,
|
|
|
|
lock: Mutex<Box<T>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<T> Send for MvccRwLock<T> {}
|
|
|
|
|
|
|
|
// async-coap / RUSTSEC-2020-0124
|
|
|
|
pub struct ArcGuard<RC, T> {
|
|
|
|
inner: T,
|
|
|
|
head: Arc<RC>,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
|
|
|
|
|
|
|
|
// rusb / RUSTSEC-2020-0098
|
|
|
|
extern "C" {
|
|
|
|
type libusb_device_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait UsbContext {
|
|
|
|
// some user trait that does not guarantee `Send`
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DeviceHandle<T: UsbContext> {
|
|
|
|
context: T,
|
|
|
|
handle: NonNull<libusb_device_handle>,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
|
|
|
|
|
2021-09-23 10:45:24 +00:00
|
|
|
// Other basic tests
|
|
|
|
pub struct MultiField<T> {
|
|
|
|
field1: T,
|
|
|
|
field2: T,
|
|
|
|
field3: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<T> Send for MultiField<T> {}
|
|
|
|
|
|
|
|
pub enum MyOption<T> {
|
|
|
|
MySome(T),
|
|
|
|
MyNone,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<T> Send for MyOption<T> {}
|
|
|
|
|
2021-09-23 07:51:10 +00:00
|
|
|
// Raw pointers are allowed
|
|
|
|
extern "C" {
|
|
|
|
type SomeFfiType;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct FpTest {
|
|
|
|
vec: Vec<*const SomeFfiType>,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Send for FpTest {}
|
|
|
|
|
2021-09-23 10:45:24 +00:00
|
|
|
// Test attributes
|
2021-09-23 07:51:10 +00:00
|
|
|
#[allow(clippy::non_send_field_in_send_ty)]
|
|
|
|
pub struct AttrTest1<T>(T);
|
|
|
|
|
|
|
|
pub struct AttrTest2<T> {
|
|
|
|
#[allow(clippy::non_send_field_in_send_ty)]
|
|
|
|
field: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum AttrTest3<T> {
|
|
|
|
#[allow(clippy::non_send_field_in_send_ty)]
|
|
|
|
Enum1(T),
|
|
|
|
Enum2(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<T> Send for AttrTest1<T> {}
|
|
|
|
unsafe impl<T> Send for AttrTest2<T> {}
|
|
|
|
unsafe impl<T> Send for AttrTest3<T> {}
|
|
|
|
|
2021-09-23 10:45:24 +00:00
|
|
|
// Multiple non-overlapping `Send` for a single type
|
|
|
|
pub struct Complex<A, B> {
|
|
|
|
field1: A,
|
|
|
|
field2: B,
|
2021-09-23 07:51:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 10:45:24 +00:00
|
|
|
unsafe impl<P> Send for Complex<P, u32> {}
|
2021-09-23 07:51:10 +00:00
|
|
|
|
2021-09-23 10:45:24 +00:00
|
|
|
// `MutexGuard` is non-Send
|
|
|
|
unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}
|
2021-09-23 07:51:10 +00:00
|
|
|
|
|
|
|
fn main() {}
|