diff --git a/library/std/src/sys_common/thread_info.rs b/library/std/src/sys_common/thread_info.rs index cd570dca0ff5..b8f2e658214b 100644 --- a/library/std/src/sys_common/thread_info.rs +++ b/library/std/src/sys_common/thread_info.rs @@ -34,7 +34,9 @@ impl ThreadInfo { /// /// This can be used as a non-null usize-sized ID. pub fn current_thread_unique_ptr() -> usize { - THREAD_INFO.with(|info| <*const _>::addr(info)) + // Use a non-drop type to make sure it's still available during thread destruction. + thread_local! { static X: u8 = 0 } + X.with(|x| <*const _>::addr(x)) } pub fn current_thread() -> Option {