Skip to content

Commit 62bf84c

Browse files
committed
Auto merge of rust-lang#123356 - joboet:set_current_size, r=workingjubilee
Reduce code size of `thread::set_current` rust-lang#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
2 parents ceab612 + 061d873 commit 62bf84c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

library/std/src/thread/mod.rs

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

685685
/// Sets the thread handle for the current thread.
686686
///
687-
/// Panics if the handle has been set already or when called from a TLS destructor.
687+
/// Aborts if the handle has been set already to reduce code size.
688688
pub(crate) fn set_current(thread: Thread) {
689-
CURRENT.with(|current| current.set(thread).unwrap());
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+
});
690695
}
691696

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

0 commit comments

Comments
 (0)