Skip to content

Commit fe19861

Browse files
committed
Add missing unsafe {} blocks in const thread_local! impl
These are only necessary when the user of thread_local! uses `#![deny(unsafe_op_in_unsafe_fn)]`
1 parent 6e4c3b1 commit fe19861

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

library/std/src/thread/local.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ macro_rules! __thread_local_inner {
189189
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
190190
{
191191
static mut VAL: $t = INIT_EXPR;
192-
Some(&VAL)
192+
// FIXME: remove the #[allow(...)] marker when macros don't
193+
// raise warning for missing/extraneous unsafe blocks anymore.
194+
// See https://github.com/rust-lang/rust/issues/74838.
195+
#[allow(unused_unsafe)]
196+
unsafe { Some(&VAL) }
193197
}
194198

195199
// If the platform has support for `#[thread_local]`, use it.
@@ -205,7 +209,13 @@ macro_rules! __thread_local_inner {
205209
// just get going.
206210
if !$crate::mem::needs_drop::<$t>() {
207211
unsafe {
208-
return Some(&VAL)
212+
// FIXME: remove the #[allow(...)] marker when macros don't
213+
// raise warning for missing/extraneous unsafe blocks anymore.
214+
// See https://github.com/rust-lang/rust/issues/74838.
215+
#[allow(unused_unsafe)]
216+
unsafe {
217+
return Some(&VAL);
218+
}
209219
}
210220
}
211221

0 commit comments

Comments
 (0)