From 061d8731fb0ab1d57d7a289fd0ded173ceef8a64 Mon Sep 17 00:00:00 2001 From: joboet Date: Wed, 3 Apr 2024 14:33:43 +0200 Subject: std: add comment about abort motivation --- library/std/src/thread/mod.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'library/std/src/thread') diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index a97122ca120..ae3dfef4870 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -686,6 +686,8 @@ thread_local! { /// /// Aborts if the handle has been set already to reduce code size. pub(crate) fn set_current(thread: Thread) { + // Using `unwrap` here can add ~3kB to the binary size. We have complete + // control over where this is called, so just abort if there is a bug. CURRENT.with(|current| match current.set(thread) { Ok(()) => {} Err(_) => rtabort!("should only be set once"), -- cgit 1.4.1-3-g733a5