Skip to content

Commit 34e8245

Browse files
committed
tls_leak_main_thread_allowed: make test check target_thread_local
1 parent 0058752 commit 34e8245

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//@ignore-target-windows: Windows uses a different mechanism for `thread_local!`
2-
#![feature(thread_local)]
1+
#![feature(thread_local, cfg_target_thread_local)]
32

43
use std::cell::Cell;
54

@@ -8,16 +7,20 @@ use std::cell::Cell;
87
//
98
// The test covers both TLS statics and the TLS macro.
109
pub fn main() {
11-
thread_local! {
12-
static TLS_KEY: Cell<Option<&'static i32>> = Cell::new(None);
13-
}
14-
15-
TLS_KEY.with(|cell| {
16-
cell.set(Some(Box::leak(Box::new(123))));
17-
});
18-
1910
#[thread_local]
2011
static TLS: Cell<Option<&'static i32>> = Cell::new(None);
2112

2213
TLS.set(Some(Box::leak(Box::new(123))));
14+
15+
// We can only ignore leaks on targets that use `#[thread_local]` statics to implement
16+
// `thread_local!`. Ignore the test on targest that don't.
17+
if cfg!(target_thread_local) {
18+
thread_local! {
19+
static TLS_KEY: Cell<Option<&'static i32>> = Cell::new(None);
20+
}
21+
22+
TLS_KEY.with(|cell| {
23+
cell.set(Some(Box::leak(Box::new(123))));
24+
});
25+
}
2326
}

0 commit comments

Comments
 (0)