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.
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.
12 #![feature(thread_local)]
13 #![feature(cfg_target_thread_local, thread_local_internals)]
15 type Foo = std::cell::RefCell<String>;
17 #[cfg(target_thread_local)]
19 static __KEY: std::thread::__FastLocalKeyInner<Foo> =
20 std::thread::__FastLocalKeyInner::new();
22 #[cfg(not(target_thread_local))]
23 static __KEY: std::thread::__OsLocalKeyInner<Foo> =
24 std::thread::__OsLocalKeyInner::new();
26 fn __getit() -> std::option::Option<
27 &'static std::cell::UnsafeCell<
28 std::option::Option<Foo>>>
30 __KEY.get() //~ ERROR call to unsafe function is unsafe
33 static FOO: std::thread::LocalKey<Foo> =
34 std::thread::LocalKey::new(__getit, Default::default);
35 //~^ ERROR call to unsafe function is unsafe
38 FOO.with(|foo| println!("{}", foo.borrow()));
39 std::thread::spawn(|| {
40 FOO.with(|foo| *foo.borrow_mut() += "foo");
42 FOO.with(|foo| println!("{}", foo.borrow()));