Skip to content

Commit c8fc966

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 d4cc01c + 3aadc26 commit c8fc966

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

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

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)