From 6c5c48e880ca0668c5c8a8029769636831985137 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 2 Apr 2024 12:06:52 +0000 Subject: [PATCH] Check that nested statics in thread locals are duplicated per thread. --- tests/ui/statics/nested_thread_local.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/ui/statics/nested_thread_local.rs 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); + } +}