2025-06-29 23:13:37 +05:00
|
|
|
//! Test that enums inherit Sync/!Sync properties from their variants.
|
|
|
|
|
//!
|
|
|
|
|
//! 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;
|
|
|
|
|
|
|
|
|
|
struct NoSync;
|
|
|
|
|
impl !Sync for NoSync {}
|
|
|
|
|
|
2025-06-29 23:13:37 +05:00
|
|
|
enum Container {
|
|
|
|
|
WithNoSync(NoSync),
|
|
|
|
|
}
|
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 container = Container::WithNoSync(NoSync);
|
|
|
|
|
requires_sync(container);
|
2018-02-10 21:01:49 -08:00
|
|
|
//~^ ERROR `NoSync` cannot be shared between threads safely [E0277]
|
2013-05-05 15:55:32 -04:00
|
|
|
}
|