Skip to content

Commit 899bc89

Browse files
committed
Auto merge of #126829 - RalfJung:main-thread-tls, r=workingjubilee
add test for main thread thread-local destructors Fixes #28129
2 parents 3cb521a + d125429 commit 899bc89

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ run-pass
2+
//@ check-run-results
3+
//! Ensure that TLS destructors run on the main thread.
4+
5+
struct Bar;
6+
7+
impl Drop for Bar {
8+
fn drop(&mut self) {
9+
println!("Bar dtor");
10+
}
11+
}
12+
13+
struct Foo;
14+
15+
impl Drop for Foo {
16+
fn drop(&mut self) {
17+
println!("Foo dtor");
18+
// We initialize another thread-local inside the dtor, which is an interesting corner case.
19+
thread_local!(static BAR: Bar = Bar);
20+
BAR.with(|_| {});
21+
}
22+
}
23+
24+
thread_local!(static FOO: Foo = Foo);
25+
26+
fn main() {
27+
FOO.with(|_| {});
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Foo dtor
2+
Bar dtor

0 commit comments

Comments
 (0)