@@ -31,10 +31,14 @@ pub use core::panic::{PanicInfo, Location};
31
31
/// A marker trait which represents "panic safe" types in Rust.
32
32
///
33
33
/// This trait is implemented by default for many types and behaves similarly in
34
- /// terms of inference of implementation to the `Send` and `Sync` traits. The
35
- /// purpose of this trait is to encode what types are safe to cross a `catch_unwind`
34
+ /// terms of inference of implementation to the [ `Send`] and [ `Sync`] traits. The
35
+ /// purpose of this trait is to encode what types are safe to cross a [ `catch_unwind`]
36
36
/// boundary with no fear of unwind safety.
37
37
///
38
+ /// [`Send`]: ../marker/trait.Send.html
39
+ /// [`Sync`]: ../marker/trait.Sync.html
40
+ /// [`catch_unwind`]: ./fn.catch_unwind.html
41
+ ///
38
42
/// ## What is unwind safety?
39
43
///
40
44
/// In Rust a function can "return" early if it either panics or calls a
@@ -95,12 +99,13 @@ pub use core::panic::{PanicInfo, Location};
95
99
///
96
100
/// ## When should `UnwindSafe` be used?
97
101
///
98
- /// Is not intended that most types or functions need to worry about this trait.
99
- /// It is only used as a bound on the `catch_unwind` function and as mentioned above,
100
- /// the lack of `unsafe` means it is mostly an advisory. The `AssertUnwindSafe`
101
- /// wrapper struct in this module can be used to force this trait to be
102
- /// implemented for any closed over variables passed to the `catch_unwind` function
103
- /// (more on this below).
102
+ /// It is not intended that most types or functions need to worry about this trait.
103
+ /// It is only used as a bound on the `catch_unwind` function and as mentioned
104
+ /// above, the lack of `unsafe` means it is mostly an advisory. The
105
+ /// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be
106
+ /// implemented for any closed over variables passed to `catch_unwind`.
107
+ ///
108
+ /// [`AssertUnwindSafe`]: ./struct.AssertUnwindSafe.html
104
109
#[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
105
110
#[ rustc_on_unimplemented = "the type {Self} may not be safely transferred \
106
111
across an unwind boundary"]
@@ -109,11 +114,14 @@ pub auto trait UnwindSafe {}
109
114
/// A marker trait representing types where a shared reference is considered
110
115
/// unwind safe.
111
116
///
112
- /// This trait is namely not implemented by `UnsafeCell`, the root of all
117
+ /// This trait is namely not implemented by [ `UnsafeCell`] , the root of all
113
118
/// interior mutability.
114
119
///
115
120
/// This is a "helper marker trait" used to provide impl blocks for the
116
- /// `UnwindSafe` trait, for more information see that documentation.
121
+ /// [`UnwindSafe`] trait, for more information see that documentation.
122
+ ///
123
+ /// [`UnsafeCell`]: ../cell/struct.UnsafeCell.html
124
+ /// [`UnwindSafe`]: ./trait.UnwindSafe.html
117
125
#[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
118
126
#[ rustc_on_unimplemented = "the type {Self} may contain interior mutability \
119
127
and a reference may not be safely transferrable \
@@ -122,14 +130,15 @@ pub auto trait RefUnwindSafe {}
122
130
123
131
/// A simple wrapper around a type to assert that it is unwind safe.
124
132
///
125
- /// When using `catch_unwind` it may be the case that some of the closed over
133
+ /// When using [ `catch_unwind`] it may be the case that some of the closed over
126
134
/// variables are not unwind safe. For example if `&mut T` is captured the
127
135
/// compiler will generate a warning indicating that it is not unwind safe. It
128
136
/// may not be the case, however, that this is actually a problem due to the
129
- /// specific usage of `catch_unwind` if unwind safety is specifically taken into
137
+ /// specific usage of [ `catch_unwind`] if unwind safety is specifically taken into
130
138
/// account. This wrapper struct is useful for a quick and lightweight
131
139
/// annotation that a variable is indeed unwind safe.
132
140
///
141
+ /// [`catch_unwind`]: ./fn.catch_unwind.html
133
142
/// # Examples
134
143
///
135
144
/// One way to use `AssertUnwindSafe` is to assert that the entire closure
@@ -318,18 +327,22 @@ impl<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> {
318
327
/// panic and allowing a graceful handling of the error.
319
328
///
320
329
/// It is **not** recommended to use this function for a general try/catch
321
- /// mechanism. The `Result` type is more appropriate to use for functions that
330
+ /// mechanism. The [ `Result`] type is more appropriate to use for functions that
322
331
/// can fail on a regular basis. Additionally, this function is not guaranteed
323
332
/// to catch all panics, see the "Notes" section below.
324
333
///
325
- /// The closure provided is required to adhere to the `UnwindSafe` trait to ensure
334
+ /// [`Result`]: ../result/enum.Result.html
335
+ ///
336
+ /// The closure provided is required to adhere to the [`UnwindSafe`] trait to ensure
326
337
/// that all captured variables are safe to cross this boundary. The purpose of
327
338
/// this bound is to encode the concept of [exception safety][rfc] in the type
328
339
/// system. Most usage of this function should not need to worry about this
329
340
/// bound as programs are naturally unwind safe without `unsafe` code. If it
330
- /// becomes a problem the associated `AssertUnwindSafe` wrapper type in this
331
- /// module can be used to quickly assert that the usage here is indeed unwind
332
- /// safe.
341
+ /// becomes a problem the [`AssertUnwindSafe`] wrapper struct can be used to quickly
342
+ /// assert that the usage here is indeed unwind safe.
343
+ ///
344
+ /// [`AssertUnwindSafe`]: ./struct.AssertUnwindSafe.html
345
+ /// [`UnwindSafe`]: ./trait.UnwindSafe.html
333
346
///
334
347
/// [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1236-stabilize-catch-panic.md
335
348
///
@@ -364,9 +377,11 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
364
377
365
378
/// Triggers a panic without invoking the panic hook.
366
379
///
367
- /// This is designed to be used in conjunction with `catch_unwind` to, for
380
+ /// This is designed to be used in conjunction with [ `catch_unwind`] to, for
368
381
/// example, carry a panic across a layer of C code.
369
382
///
383
+ /// [`catch_unwind`]: ./fn.catch_unwind.html
384
+ ///
370
385
/// # Notes
371
386
///
372
387
/// Note that panics in Rust are not always implemented via unwinding, but they
0 commit comments