-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid implicit nested statics in thread local statics
- Loading branch information
Showing
5 changed files
with
30 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|