From b5ccebf76210c3a35870ca72f55f80a2769f4fc8 Mon Sep 17 00:00:00 2001 From: joboet Date: Tue, 2 Apr 2024 11:27:34 +0200 Subject: [PATCH] std: reduce code size of `set_current` --- library/std/src/thread/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index f7eb92bc61e2f..d7136d30fda75 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -684,9 +684,12 @@ thread_local! { /// Sets the thread handle for the current thread. /// -/// Panics if the handle has been set already or when called from a TLS destructor. +/// Aborts if the handle has been set already to reduce code size. pub(crate) fn set_current(thread: Thread) { - CURRENT.with(|current| current.set(thread).unwrap()); + CURRENT.with(|current| { + rtassert!(current.get().is_none()); + current.set(thread).unwrap(); + }); } /// Gets a handle to the thread that invokes it.