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