Skip to content

Commit 36176cd

Browse files
committed
Auto merge of #1778 - RalfJung:thread-local-const-init, r=RalfJung
test thread_local_const_init Blocked on rust-lang/rust#84291
2 parents 74ffda2 + 2ae699c commit 36176cd

6 files changed

+16
-1
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3833636446b670ee905fba5f8d18881b1739814e
1+
b2c20b51ed838368d3f2bdccb63f401bcddb7e1c

tests/run-pass/concurrency/tls_lib_drop.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2+
#![feature(thread_local_const_init)]
23

34
use std::cell::RefCell;
45
use std::thread;
@@ -16,6 +17,7 @@ impl Drop for TestCell {
1617

1718
thread_local! {
1819
static A: TestCell = TestCell { value: RefCell::new(0) };
20+
static A_CONST: TestCell = const { TestCell { value: RefCell::new(10) } };
1921
}
2022

2123
/// Check that destructors of the library thread locals are executed immediately
@@ -26,6 +28,10 @@ fn check_destructors() {
2628
assert_eq!(*f.value.borrow(), 0);
2729
*f.value.borrow_mut() = 5;
2830
});
31+
A_CONST.with(|f| {
32+
assert_eq!(*f.value.borrow(), 10);
33+
*f.value.borrow_mut() = 15;
34+
});
2935
})
3036
.join()
3137
.unwrap();
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Dropping: 5 (should be before 'Continue main 1').
2+
Dropping: 15 (should be before 'Continue main 1').
23
Continue main 1.
34
Joining: 7 (should be before 'Continue main 2').
45
Continue main 2.

tests/run-pass/concurrency/tls_lib_drop_single_thread.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// compile-flags: -Zmiri-track-raw-pointers
12
//! Check that destructors of the thread locals are executed on all OSes.
3+
#![feature(thread_local_const_init)]
24

35
use std::cell::RefCell;
46

@@ -14,12 +16,17 @@ impl Drop for TestCell {
1416

1517
thread_local! {
1618
static A: TestCell = TestCell { value: RefCell::new(0) };
19+
static A_CONST: TestCell = const { TestCell { value: RefCell::new(10) } };
1720
}
1821

1922
fn main() {
2023
A.with(|f| {
2124
assert_eq!(*f.value.borrow(), 0);
2225
*f.value.borrow_mut() = 5;
2326
});
27+
A_CONST.with(|f| {
28+
assert_eq!(*f.value.borrow(), 10);
29+
*f.value.borrow_mut() = 5; // Same value as above since the drop order is different on different platforms
30+
});
2431
eprintln!("Continue main.")
2532
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Continue main.
22
Dropping: 5
3+
Dropping: 5

0 commit comments

Comments
 (0)