2025-06-29 23:13:37 +05:00
|
|
|
//! Test negative Sync implementation on structs.
|
|
|
|
|
//!
|
|
|
|
|
//! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync.
|
|
|
|
|
|
2020-01-09 05:56:38 -05:00
|
|
|
#![feature(negative_impls)]
|
2014-01-22 14:03:02 -05:00
|
|
|
|
2015-01-11 13:14:39 +01:00
|
|
|
use std::marker::Sync;
|
|
|
|
|
|
2025-06-29 23:13:37 +05:00
|
|
|
struct NotSync {
|
|
|
|
|
value: isize,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl !Sync for NotSync {}
|
2013-05-05 15:55:32 -04:00
|
|
|
|
2025-06-29 23:13:37 +05:00
|
|
|
fn requires_sync<T: Sync>(_: T) {}
|
2013-05-05 15:55:32 -04:00
|
|
|
|
|
|
|
|
fn main() {
|
2025-06-29 23:13:37 +05:00
|
|
|
let not_sync = NotSync { value: 5 };
|
|
|
|
|
requires_sync(not_sync);
|
|
|
|
|
//~^ ERROR `NotSync` cannot be shared between threads safely [E0277]
|
2013-05-05 15:55:32 -04:00
|
|
|
}
|