]> git.lizzy.rs Git - rust.git/blob - src/test/ui/typeck/typeck-unsafe-always-share.rs
Auto merge of #99028 - tmiasko:inline, r=estebank
[rust.git] / src / test / ui / typeck / typeck-unsafe-always-share.rs
1 // Verify that UnsafeCell is *always* !Sync regardless if `T` is sync.
2
3 #![feature(negative_impls)]
4
5 use std::cell::UnsafeCell;
6 use std::marker::Sync;
7
8 struct MySync<T> {
9     u: UnsafeCell<T>
10 }
11
12 struct NoSync;
13 impl !Sync for NoSync {}
14
15 fn test<T: Sync>(s: T) {}
16
17 fn main() {
18     let us = UnsafeCell::new(MySync{u: UnsafeCell::new(0)});
19     test(us);
20     //~^ ERROR `UnsafeCell<MySync<{integer}>>` cannot be shared between threads safely
21
22     let uns = UnsafeCell::new(NoSync);
23     test(uns);
24     //~^ ERROR `UnsafeCell<NoSync>` cannot be shared between threads safely [E0277]
25
26     let ms = MySync{u: uns};
27     test(ms);
28     //~^ ERROR `UnsafeCell<NoSync>` cannot be shared between threads safely [E0277]
29
30     test(NoSync);
31     //~^ ERROR `NoSync` cannot be shared between threads safely [E0277]
32 }