summary refs log tree commit diff
path: root/library/std/src/thread
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2024-04-02 11:27:34 +0200
committerjoboet <jonasboettiger@icloud.com>2024-04-02 11:41:31 +0200
commite7b5730d36740035b9cf58b759be87d0d88515a7 (patch)
tree4a5921e2589e30f9b8dd47ab741847e9182d07c3 /library/std/src/thread
parente2cf2cb30388385f0fe6b406a31a3f9841a72a62 (diff)
downloadrust-e7b5730d36740035b9cf58b759be87d0d88515a7.tar.gz
rust-e7b5730d36740035b9cf58b759be87d0d88515a7.zip
std: reduce code size of `set_current`
Diffstat (limited to 'library/std/src/thread')
-rw-r--r--library/std/src/thread/mod.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index f7eb92bc61e..a97122ca120 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| match current.set(thread) {
+        Ok(()) => {}
+        Err(_) => rtabort!("should only be set once"),
+    });
 }
 
 /// Gets a handle to the thread that invokes it.