rust/tests/ui/traits/enum-negative-sync-impl.rs
2025-06-30 11:50:19 +05:00

23 lines
495 B
Rust

//! Test that enums inherit Sync/!Sync properties from their variants.
//!
//! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync.
#![feature(negative_impls)]
use std::marker::Sync;
struct NoSync;
impl !Sync for NoSync {}
enum Container {
WithNoSync(NoSync),
}
fn requires_sync<T: Sync>(_: T) {}
fn main() {
let container = Container::WithNoSync(NoSync);
requires_sync(container);
//~^ ERROR `NoSync` cannot be shared between threads safely [E0277]
}