From e055e1c449c0dbce541d83ac650ff1a99101c73d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 22 Jun 2024 15:25:46 +0200 Subject: [PATCH] add test for main thread thread-local destructors --- tests/ui/thread-local/main-thread-dtor.rs | 31 +++++++++++++++++++ .../thread-local/main-thread-dtor.run.stdout | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 tests/ui/thread-local/main-thread-dtor.rs create mode 100644 tests/ui/thread-local/main-thread-dtor.run.stdout diff --git a/tests/ui/thread-local/main-thread-dtor.rs b/tests/ui/thread-local/main-thread-dtor.rs new file mode 100644 index 0000000000000..5e6748c27bfe0 --- /dev/null +++ b/tests/ui/thread-local/main-thread-dtor.rs @@ -0,0 +1,31 @@ +//@ run-pass +//@ check-run-results +//@ needs-threads (really only needs TLS, not threads, but those seem to usually come together) +//@ ignore-musl musl does not seem to run dtors on the main thread (issue #126858) +//@ ignore-android android does not seem to run dtors on the main thread (issue #126858) +//! Ensure that TLS destructors run on the main thread. + +struct Bar; + +impl Drop for Bar { + fn drop(&mut self) { + println!("Bar dtor"); + } +} + +struct Foo; + +impl Drop for Foo { + fn drop(&mut self) { + println!("Foo dtor"); + // We initialize another thread-local inside the dtor, which is an interesting corner case. + thread_local!(static BAR: Bar = Bar); + BAR.with(|_| {}); + } +} + +thread_local!(static FOO: Foo = Foo); + +fn main() { + FOO.with(|_| {}); +} diff --git a/tests/ui/thread-local/main-thread-dtor.run.stdout b/tests/ui/thread-local/main-thread-dtor.run.stdout new file mode 100644 index 0000000000000..6160f2726492d --- /dev/null +++ b/tests/ui/thread-local/main-thread-dtor.run.stdout @@ -0,0 +1,2 @@ +Foo dtor +Bar dtor