Skip to content

Commit 2a63b33

Browse files
authored
Rollup merge of rust-lang#57833 - jethrogb:jb/thread-spawn-unwrap, r=alexcrichton
Print a slightly clearer message when failing to launch a thread As discussed in rust-lang#46345, the `io::Error` you get when a thread fails to launch is of type `io::ErrorKind::WouldBlock`. This is super uninformative when an arbitrary `thread::spawn` fails somewhere in your code: ``` thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 11, kind: WouldBlock, message: "operation would block" }', src/libcore/result.rs:997:5 ``` This PR improves the situation a little bit by using `expect` instead of `unwrap`. I don't consider this a complete fix for rust-lang#46345 though.
2 parents d8a0dd7 + 2ec0e85 commit 2a63b33

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libstd/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl Builder {
607607
pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
608608
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
609609
{
610-
Builder::new().spawn(f).unwrap()
610+
Builder::new().spawn(f).expect("failed to spawn thread")
611611
}
612612

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

0 commit comments

Comments
 (0)