Auto merge of #1778 - RalfJung:thread-local-const-init, r=RalfJung

test thread_local_const_init

Blocked on https://github.com/rust-lang/rust/pull/84291
This commit is contained in:
bors 2021-04-20 08:01:46 +00:00
commit 36176cde68
6 changed files with 16 additions and 1 deletions

View file

@ -1 +1 @@
3833636446b670ee905fba5f8d18881b1739814e
b2c20b51ed838368d3f2bdccb63f401bcddb7e1c

View file

@ -1,4 +1,5 @@
// ignore-windows: Concurrency on Windows is not supported yet.
#![feature(thread_local_const_init)]
use std::cell::RefCell;
use std::thread;
@ -16,6 +17,7 @@ impl Drop for TestCell {
thread_local! {
static A: TestCell = TestCell { value: RefCell::new(0) };
static A_CONST: TestCell = const { TestCell { value: RefCell::new(10) } };
}
/// Check that destructors of the library thread locals are executed immediately
@ -26,6 +28,10 @@ fn check_destructors() {
assert_eq!(*f.value.borrow(), 0);
*f.value.borrow_mut() = 5;
});
A_CONST.with(|f| {
assert_eq!(*f.value.borrow(), 10);
*f.value.borrow_mut() = 15;
});
})
.join()
.unwrap();

View file

@ -1,4 +1,5 @@
Dropping: 5 (should be before 'Continue main 1').
Dropping: 15 (should be before 'Continue main 1').
Continue main 1.
Joining: 7 (should be before 'Continue main 2').
Continue main 2.

View file

@ -1,4 +1,6 @@
// compile-flags: -Zmiri-track-raw-pointers
//! Check that destructors of the thread locals are executed on all OSes.
#![feature(thread_local_const_init)]
use std::cell::RefCell;
@ -14,6 +16,7 @@ impl Drop for TestCell {
thread_local! {
static A: TestCell = TestCell { value: RefCell::new(0) };
static A_CONST: TestCell = const { TestCell { value: RefCell::new(10) } };
}
fn main() {
@ -21,5 +24,9 @@ fn main() {
assert_eq!(*f.value.borrow(), 0);
*f.value.borrow_mut() = 5;
});
A_CONST.with(|f| {
assert_eq!(*f.value.borrow(), 10);
*f.value.borrow_mut() = 5; // Same value as above since the drop order is different on different platforms
});
eprintln!("Continue main.")
}

View file

@ -1,2 +1,3 @@
Continue main.
Dropping: 5
Dropping: 5