diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/statics/nested_thread_local.rs | 28 | ||||
| -rw-r--r-- | tests/ui/statics/nested_thread_local.stderr | 8 |
2 files changed, 17 insertions, 19 deletions
diff --git a/tests/ui/statics/nested_thread_local.rs b/tests/ui/statics/nested_thread_local.rs index 10e0a3420d9..a512016335a 100644 --- a/tests/ui/statics/nested_thread_local.rs +++ b/tests/ui/statics/nested_thread_local.rs @@ -1,24 +1,14 @@ -// Check that nested statics in thread locals are -// duplicated per thread. +// Check that we forbid nested statics in `thread_local` statics. #![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); - } -} +static mut FOO: &u32 = { + //~^ ERROR: does not support implicit nested statics + // Prevent promotion (that would trigger on `&42` as an expression) + let x = 42; + &{ x } +}; + +fn main() {} diff --git a/tests/ui/statics/nested_thread_local.stderr b/tests/ui/statics/nested_thread_local.stderr new file mode 100644 index 00000000000..30c742626fa --- /dev/null +++ b/tests/ui/statics/nested_thread_local.stderr @@ -0,0 +1,8 @@ +error: #[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead + --> $DIR/nested_thread_local.rs:7:1 + | +LL | static mut FOO: &u32 = { + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + |
