Skip to content

Commit 3032233

Browse files
authored
Rollup merge of #66114 - golddranks:improve_thread_docs, r=Centril
Improve std::thread::Result documentation Thanks to @dtolnay for pointing out the different premise of the contents of the `Err` variant in `std::thread::Result` WRT normal error handling.
2 parents b94a2f9 + 8568204 commit 3032233

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/thread/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,18 @@ impl fmt::Debug for Thread {
12711271
///
12721272
/// Indicates the manner in which a thread exited.
12731273
///
1274+
/// The value contained in the `Result::Err` variant
1275+
/// is the value the thread panicked with;
1276+
/// that is, the argument the `panic!` macro was called with.
1277+
/// Unlike with normal errors, this value doesn't implement
1278+
/// the [`Error`](crate::error::Error) trait.
1279+
///
1280+
/// Thus, a sensible way to handle a thread panic is to either:
1281+
/// 1. `unwrap` the `Result<T>`, propagating the panic
1282+
/// 2. or in case the thread is intended to be a subsystem boundary
1283+
/// that is supposed to isolate system-level failures,
1284+
/// match on the `Err` variant and handle the panic in an appropriate way.
1285+
///
12741286
/// A thread that completes without panicking is considered to exit successfully.
12751287
///
12761288
/// # Examples

0 commit comments

Comments
 (0)