about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/std/src/thread/mod.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index d9e28acdcda..3f3ba02361c 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -1739,11 +1739,16 @@ struct JoinInner<'scope, T> {
 impl<'scope, T> JoinInner<'scope, T> {
     fn join(mut self) -> Result<T> {
         self.native.join();
-        if let Some(packet) = Arc::get_mut(&mut self.packet) {
-            packet.result.get_mut().take().unwrap()
-        } else {
-            Err(Box::new("thread terminated unexpectedly"))
-        }
+        Arc::get_mut(&mut self.packet)
+            // FIXME(fuzzypixelz): returning an error instead of panicking here
+            // would require updating the documentation of
+            // `std::thread::Result`; currently we can return `Err` if and only
+            // if the thread had panicked.
+            .expect("threads should not terminate unexpectedly")
+            .result
+            .get_mut()
+            .take()
+            .unwrap()
     }
 }