Skip to content

Commit 957c442

Browse files
committed
std: don't abort in thread::set_current
1 parent 061d873 commit 957c442

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

library/std/src/thread/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,11 @@ thread_local! {
684684

685685
/// Sets the thread handle for the current thread.
686686
///
687-
/// Aborts if the handle has been set already to reduce code size.
687+
/// Does nothing if the thread was already set. This can only happen if some code
688+
/// runs pre-main, but it seems unnecessary to detect that, especially since
689+
/// adding `.unwrap()` here can add ~3kB to the binary size.
688690
pub(crate) fn set_current(thread: Thread) {
689-
// Using `unwrap` here can add ~3kB to the binary size. We have complete
690-
// control over where this is called, so just abort if there is a bug.
691-
CURRENT.with(|current| match current.set(thread) {
692-
Ok(()) => {}
693-
Err(_) => rtabort!("should only be set once"),
694-
});
691+
let _ = CURRENT.with(|current| current.set(thread));
695692
}
696693

697694
/// Gets a handle to the thread that invokes it.

0 commit comments

Comments
 (0)