Skip to content

Commit bfd45e0

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 5daac46 commit bfd45e0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

library/std/src/thread/local.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ macro_rules! __thread_local_inner {
193193
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
194194
{
195195
static mut VAL: $t = INIT_EXPR;
196-
$crate::option::Option::Some(&VAL)
196+
// FIXME: remove the #[allow(...)] marker when macros don't
197+
// raise warning for missing/extraneous unsafe blocks anymore.
198+
// See https://github.com/rust-lang/rust/issues/74838.
199+
#[allow(unused_unsafe)]
200+
unsafe { $crate::option::Option::Some(&VAL) }
197201
}
198202

199203
// If the platform has support for `#[thread_local]`, use it.
@@ -208,8 +212,12 @@ macro_rules! __thread_local_inner {
208212
// If a dtor isn't needed we can do something "very raw" and
209213
// just get going.
210214
if !$crate::mem::needs_drop::<$t>() {
215+
// FIXME: remove the #[allow(...)] marker when macros don't
216+
// raise warning for missing/extraneous unsafe blocks anymore.
217+
// See https://github.com/rust-lang/rust/issues/74838.
218+
#[allow(unused_unsafe)]
211219
unsafe {
212-
return $crate::option::Option::Some(&VAL)
220+
return $crate::option::Option::Some(&VAL);
213221
}
214222
}
215223

0 commit comments

Comments
 (0)