Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for main thread thread-local destructors #126829

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/ui/thread-local/main-thread-dtor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! Ensure that TLS destructors run on the main thread.
//@ run-pass
//@ check-run-results
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
// targets without threads tend to implement thread-locals as `static`s so no dtors are running
//@ needs-threads
// some targets do not run dtors on the main thread (issue #126858)
//@ ignore-musl
//@ ignore-android

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(|_| {});
}
2 changes: 2 additions & 0 deletions tests/ui/thread-local/main-thread-dtor.run.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Foo dtor
Bar dtor
Loading