diff --git a/tests/ui/statics/nested_thread_local.rs b/tests/ui/statics/nested_thread_local.rs new file mode 100644 index 00000000000..10e0a3420d9 --- /dev/null +++ b/tests/ui/statics/nested_thread_local.rs @@ -0,0 +1,24 @@ +// Check that nested statics in thread locals are +// duplicated per thread. + +#![feature(const_refs_to_cell)] +#![feature(thread_local)] + +//@run-pass + +#[thread_local] +static mut FOO: &mut u32 = &mut 42; + +fn main() { + unsafe { + *FOO = 1; + + let _ = std::thread::spawn(|| { + assert_eq!(*FOO, 42); + *FOO = 99; + }) + .join(); + + assert_eq!(*FOO, 1); + } +}