Skip to content

Commit a45b3ac

Browse files
committed
Simpilfy thread::JoinInner.
1 parent b60e32c commit a45b3ac

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Diff for: library/std/src/thread/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,12 @@ impl Builder {
498498
// exist after the thread has terminated, which is signaled by `Thread::join`
499499
// returning.
500500
native: unsafe {
501-
Some(imp::Thread::new(
501+
imp::Thread::new(
502502
stack_size,
503503
mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(
504504
Box::new(main),
505505
),
506-
)?)
506+
)?
507507
},
508508
thread: my_thread,
509509
packet: Packet(my_packet),
@@ -1258,15 +1258,15 @@ unsafe impl<T: Sync> Sync for Packet<T> {}
12581258

12591259
/// Inner representation for JoinHandle
12601260
struct JoinInner<T> {
1261-
native: Option<imp::Thread>,
1261+
native: imp::Thread,
12621262
thread: Thread,
12631263
packet: Packet<T>,
12641264
}
12651265

12661266
impl<T> JoinInner<T> {
1267-
fn join(&mut self) -> Result<T> {
1268-
self.native.take().unwrap().join();
1269-
unsafe { (*self.packet.0.get()).take().unwrap() }
1267+
fn join(mut self) -> Result<T> {
1268+
self.native.join();
1269+
Arc::get_mut(&mut self.packet.0).unwrap().get_mut().take().unwrap()
12701270
}
12711271
}
12721272

@@ -1397,7 +1397,7 @@ impl<T> JoinHandle<T> {
13971397
/// join_handle.join().expect("Couldn't join on the associated thread");
13981398
/// ```
13991399
#[stable(feature = "rust1", since = "1.0.0")]
1400-
pub fn join(mut self) -> Result<T> {
1400+
pub fn join(self) -> Result<T> {
14011401
self.0.join()
14021402
}
14031403

@@ -1413,13 +1413,13 @@ impl<T> JoinHandle<T> {
14131413

14141414
impl<T> AsInner<imp::Thread> for JoinHandle<T> {
14151415
fn as_inner(&self) -> &imp::Thread {
1416-
self.0.native.as_ref().unwrap()
1416+
&self.0.native
14171417
}
14181418
}
14191419

14201420
impl<T> IntoInner<imp::Thread> for JoinHandle<T> {
14211421
fn into_inner(self) -> imp::Thread {
1422-
self.0.native.unwrap()
1422+
self.0.native
14231423
}
14241424
}
14251425

0 commit comments

Comments
 (0)