about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-28 22:25:44 +0100
committerGitHub <noreply@github.com>2019-01-28 22:25:44 +0100
commit42dae3adad69a4e1f0a497555154b27a987802f5 (patch)
treef5adba36b4f88f8f6455f0114c09fd2c8a97698a /src/libstd
parent76dbfdd595894dd113f22188477ff3ad46bb0a13 (diff)
parent2ec0e85305e69d7f6e1bc0c704a6566ad38232a4 (diff)
downloadrust-42dae3adad69a4e1f0a497555154b27a987802f5.tar.gz
rust-42dae3adad69a4e1f0a497555154b27a987802f5.zip
Rollup merge of #57833 - jethrogb:jb/thread-spawn-unwrap, r=alexcrichton
Print a slightly clearer message when failing to launch a thread

As discussed in #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 #46345 though.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/thread/mod.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index a55b32c08a3..eb8e0c1c8ac 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -607,7 +607,7 @@ impl Builder {
 pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
     F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
 {
-    Builder::new().spawn(f).unwrap()
+    Builder::new().spawn(f).expect("failed to spawn thread")
 }
 
 /// Gets a handle to the thread that invokes it.