From d512ba2ae244079f0d57f7032db06c12ee3b590c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Apr 2021 10:57:56 +0200 Subject: [PATCH 1/3] test thread_local_const_init --- tests/run-pass/concurrency/tls_lib_drop.rs | 6 ++++++ tests/run-pass/concurrency/tls_lib_drop.stdout | 1 + tests/run-pass/concurrency/tls_lib_drop_single_thread.rs | 7 +++++++ .../run-pass/concurrency/tls_lib_drop_single_thread.stderr | 1 + .../tls_pthread_drop_order.rs} | 0 5 files changed, 15 insertions(+) rename tests/run-pass/{thread-local.rs => concurrency/tls_pthread_drop_order.rs} (100%) diff --git a/tests/run-pass/concurrency/tls_lib_drop.rs b/tests/run-pass/concurrency/tls_lib_drop.rs index 46f59ef620..00a12599ce 100644 --- a/tests/run-pass/concurrency/tls_lib_drop.rs +++ b/tests/run-pass/concurrency/tls_lib_drop.rs @@ -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(); diff --git a/tests/run-pass/concurrency/tls_lib_drop.stdout b/tests/run-pass/concurrency/tls_lib_drop.stdout index 484979b04c..9cd7e049d1 100644 --- a/tests/run-pass/concurrency/tls_lib_drop.stdout +++ b/tests/run-pass/concurrency/tls_lib_drop.stdout @@ -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. diff --git a/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs b/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs index f232cee5bd..7d8e84e33f 100644 --- a/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs +++ b/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs @@ -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() = 15; + }); eprintln!("Continue main.") } diff --git a/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr b/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr index a9d705e5b9..e59dd284bd 100644 --- a/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr +++ b/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr @@ -1,2 +1,3 @@ Continue main. Dropping: 5 +Dropping: 15 diff --git a/tests/run-pass/thread-local.rs b/tests/run-pass/concurrency/tls_pthread_drop_order.rs similarity index 100% rename from tests/run-pass/thread-local.rs rename to tests/run-pass/concurrency/tls_pthread_drop_order.rs From f73cc11f3fcfa7f480297eb82a0fcd072a1d963d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 20 Apr 2021 09:40:18 +0200 Subject: [PATCH 2/3] rustup --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 46567849e0..29fc4efbea 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -3833636446b670ee905fba5f8d18881b1739814e +b2c20b51ed838368d3f2bdccb63f401bcddb7e1c From 2ae699c56db7366a14c5e0d517743084a184ffe1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 20 Apr 2021 09:59:26 +0200 Subject: [PATCH 3/3] make TLS-drop-test more cross-platform --- tests/run-pass/concurrency/tls_lib_drop_single_thread.rs | 2 +- tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs b/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs index 7d8e84e33f..cd1bd6480b 100644 --- a/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs +++ b/tests/run-pass/concurrency/tls_lib_drop_single_thread.rs @@ -26,7 +26,7 @@ fn main() { }); A_CONST.with(|f| { assert_eq!(*f.value.borrow(), 10); - *f.value.borrow_mut() = 15; + *f.value.borrow_mut() = 5; // Same value as above since the drop order is different on different platforms }); eprintln!("Continue main.") } diff --git a/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr b/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr index e59dd284bd..09ec1c3c2c 100644 --- a/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr +++ b/tests/run-pass/concurrency/tls_lib_drop_single_thread.stderr @@ -1,3 +1,3 @@ Continue main. Dropping: 5 -Dropping: 15 +Dropping: 5