Skip to content

Commit 789118c

Browse files
committed
Auto merge of rust-lang#126829 - RalfJung:main-thread-tls, r=workingjubilee
add test for main thread thread-local destructors Fixes rust-lang#28129
2 parents 2c243d9 + 32c648c commit 789118c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Diff for: tests/ui/thread-local/main-thread-dtor.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Ensure that TLS destructors run on the main thread.
2+
//@ run-pass
3+
//@ check-run-results
4+
// targets without threads tend to implement thread-locals as `static`s so no dtors are running
5+
//@ needs-threads
6+
// some targets do not run dtors on the main thread (issue #126858)
7+
//@ ignore-musl
8+
//@ ignore-android
9+
10+
struct Bar;
11+
12+
impl Drop for Bar {
13+
fn drop(&mut self) {
14+
println!("Bar dtor");
15+
}
16+
}
17+
18+
struct Foo;
19+
20+
impl Drop for Foo {
21+
fn drop(&mut self) {
22+
println!("Foo dtor");
23+
// We initialize another thread-local inside the dtor, which is an interesting corner case.
24+
thread_local!(static BAR: Bar = Bar);
25+
BAR.with(|_| {});
26+
}
27+
}
28+
29+
thread_local!(static FOO: Foo = Foo);
30+
31+
fn main() {
32+
FOO.with(|_| {});
33+
}

Diff for: tests/ui/thread-local/main-thread-dtor.run.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Foo dtor
2+
Bar dtor

0 commit comments

Comments
 (0)