]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-43733.rs
7b1364ff41c4023754343aa601bd9c38ccd74cf7
[rust.git] / src / test / compile-fail / issue-43733.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(const_fn)]
12 #![feature(thread_local)]
13 #![feature(cfg_target_thread_local, thread_local_internals)]
14
15 type Foo = std::cell::RefCell<String>;
16
17 #[cfg(target_thread_local)]
18 #[thread_local]
19 static __KEY: std::thread::__FastLocalKeyInner<Foo> =
20     std::thread::__FastLocalKeyInner::new();
21
22 #[cfg(not(target_thread_local))]
23 static __KEY: std::thread::__OsLocalKeyInner<Foo> =
24     std::thread::__OsLocalKeyInner::new();
25
26 fn __getit() -> std::option::Option<
27     &'static std::cell::UnsafeCell<
28         std::option::Option<Foo>>>
29 {
30     __KEY.get() //~ ERROR call to unsafe function is unsafe
31 }
32
33 static FOO: std::thread::LocalKey<Foo> =
34     std::thread::LocalKey::new(__getit, Default::default);
35 //~^ ERROR call to unsafe function is unsafe
36
37 fn main() {
38     FOO.with(|foo| println!("{}", foo.borrow()));
39     std::thread::spawn(|| {
40         FOO.with(|foo| *foo.borrow_mut() += "foo");
41     }).join().unwrap();
42     FOO.with(|foo| println!("{}", foo.borrow()));
43 }