Skip to content

Commit 135327d

Browse files
committed
Auto merge of rust-lang#130992 - matthiaskrgr:rollup-7zufwg5, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#128321 (Update `catch_unwind` doc comments for `c_unwind`) - rust-lang#130416 (resolve rust-lang#130122: reword 'sort-by' edge-conditions documentation) - rust-lang#130743 (Clarifications for set_nonblocking methods) - rust-lang#130983 (Update `browser-ui-test` version and make use of `wait-for*-false` commands) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ed04567 + 72010e5 commit 135327d

File tree

8 files changed

+126
-65
lines changed

8 files changed

+126
-65
lines changed

library/alloc/src/slice.rs

+47-20
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,9 @@ impl<T> [T] {
180180
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*))
181181
/// worst-case.
182182
///
183-
/// If the implementation of [`Ord`] for `T` does not implement a [total order] the resulting
184-
/// order of elements in the slice is unspecified. All original elements will remain in the
185-
/// slice and any possible modifications via interior mutability are observed in the input. Same
186-
/// is true if the implementation of [`Ord`] for `T` panics.
183+
/// If the implementation of [`Ord`] for `T` does not implement a [total order], the function
184+
/// may panic; even if the function exits normally, the resulting order of elements in the slice
185+
/// is unspecified. See also the note on panicking below.
187186
///
188187
/// When applicable, unstable sorting is preferred because it is generally faster than stable
189188
/// sorting and it doesn't allocate auxiliary memory. See
@@ -212,7 +211,15 @@ impl<T> [T] {
212211
///
213212
/// # Panics
214213
///
215-
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order].
214+
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order], or if
215+
/// the [`Ord`] implementation itself panics.
216+
///
217+
/// All safe functions on slices preserve the invariant that even if the function panics, all
218+
/// original elements will remain in the slice and any possible modifications via interior
219+
/// mutability are observed in the input. This ensures that recovery code (for instance inside
220+
/// of a `Drop` or following a `catch_unwind`) will still have access to all the original
221+
/// elements. For instance, if the slice belongs to a `Vec`, the `Vec::drop` method will be able
222+
/// to dispose of all contained elements.
216223
///
217224
/// # Examples
218225
///
@@ -241,10 +248,9 @@ impl<T> [T] {
241248
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*))
242249
/// worst-case.
243250
///
244-
/// If the comparison function `compare` does not implement a [total order] the resulting order
245-
/// of elements in the slice is unspecified. All original elements will remain in the slice and
246-
/// any possible modifications via interior mutability are observed in the input. Same is true
247-
/// if `compare` panics.
251+
/// If the comparison function `compare` does not implement a [total order], the function may
252+
/// panic; even if the function exits normally, the resulting order of elements in the slice is
253+
/// unspecified. See also the note on panicking below.
248254
///
249255
/// For example `|a, b| (a - b).cmp(a)` is a comparison function that is neither transitive nor
250256
/// reflexive nor total, `a < b < c < a` with `a = 1, b = 2, c = 3`. For more information and
@@ -263,7 +269,14 @@ impl<T> [T] {
263269
///
264270
/// # Panics
265271
///
266-
/// May panic if `compare` does not implement a [total order].
272+
/// May panic if `compare` does not implement a [total order], or if `compare` itself panics.
273+
///
274+
/// All safe functions on slices preserve the invariant that even if the function panics, all
275+
/// original elements will remain in the slice and any possible modifications via interior
276+
/// mutability are observed in the input. This ensures that recovery code (for instance inside
277+
/// of a `Drop` or following a `catch_unwind`) will still have access to all the original
278+
/// elements. For instance, if the slice belongs to a `Vec`, the `Vec::drop` method will be able
279+
/// to dispose of all contained elements.
267280
///
268281
/// # Examples
269282
///
@@ -295,10 +308,9 @@ impl<T> [T] {
295308
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* \* log(*n*))
296309
/// worst-case, where the key function is *O*(*m*).
297310
///
298-
/// If the implementation of [`Ord`] for `K` does not implement a [total order] the resulting
299-
/// order of elements in the slice is unspecified. All original elements will remain in the
300-
/// slice and any possible modifications via interior mutability are observed in the input. Same
301-
/// is true if the implementation of [`Ord`] for `K` panics.
311+
/// If the implementation of [`Ord`] for `K` does not implement a [total order], the function
312+
/// may panic; even if the function exits normally, the resulting order of elements in the slice
313+
/// is unspecified. See also the note on panicking below.
302314
///
303315
/// # Current implementation
304316
///
@@ -313,7 +325,15 @@ impl<T> [T] {
313325
///
314326
/// # Panics
315327
///
316-
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order].
328+
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order], or if
329+
/// the [`Ord`] implementation or the key-function `f` panics.
330+
///
331+
/// All safe functions on slices preserve the invariant that even if the function panics, all
332+
/// original elements will remain in the slice and any possible modifications via interior
333+
/// mutability are observed in the input. This ensures that recovery code (for instance inside
334+
/// of a `Drop` or following a `catch_unwind`) will still have access to all the original
335+
/// elements. For instance, if the slice belongs to a `Vec`, the `Vec::drop` method will be able
336+
/// to dispose of all contained elements.
317337
///
318338
/// # Examples
319339
///
@@ -347,10 +367,9 @@ impl<T> [T] {
347367
/// storage to remember the results of key evaluation. The order of calls to the key function is
348368
/// unspecified and may change in future versions of the standard library.
349369
///
350-
/// If the implementation of [`Ord`] for `K` does not implement a [total order] the resulting
351-
/// order of elements in the slice is unspecified. All original elements will remain in the
352-
/// slice and any possible modifications via interior mutability are observed in the input. Same
353-
/// is true if the implementation of [`Ord`] for `K` panics.
370+
/// If the implementation of [`Ord`] for `K` does not implement a [total order], the function
371+
/// may panic; even if the function exits normally, the resulting order of elements in the slice
372+
/// is unspecified. See also the note on panicking below.
354373
///
355374
/// For simple key functions (e.g., functions that are property accesses or basic operations),
356375
/// [`sort_by_key`](slice::sort_by_key) is likely to be faster.
@@ -369,7 +388,15 @@ impl<T> [T] {
369388
///
370389
/// # Panics
371390
///
372-
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order].
391+
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order], or if
392+
/// the [`Ord`] implementation panics.
393+
///
394+
/// All safe functions on slices preserve the invariant that even if the function panics, all
395+
/// original elements will remain in the slice and any possible modifications via interior
396+
/// mutability are observed in the input. This ensures that recovery code (for instance inside
397+
/// of a `Drop` or following a `catch_unwind`) will still have access to all the original
398+
/// elements. For instance, if the slice belongs to a `Vec`, the `Vec::drop` method will be able
399+
/// to dispose of all contained elements.
373400
///
374401
/// # Examples
375402
///

library/core/src/intrinsics.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -2659,12 +2659,17 @@ extern "rust-intrinsic" {
26592659
///
26602660
/// `catch_fn` must not unwind.
26612661
///
2662-
/// The third argument is a function called if an unwind occurs (both Rust unwinds and foreign
2663-
/// unwinds). This function takes the data pointer and a pointer to the target-specific
2664-
/// exception object that was caught. For more information, see the compiler's source as well as
2665-
/// std's `catch_unwind` implementation.
2662+
/// The third argument is a function called if an unwind occurs (both Rust `panic` and foreign
2663+
/// unwinds). This function takes the data pointer and a pointer to the target- and
2664+
/// runtime-specific exception object that was caught.
26662665
///
2667-
/// The stable version of this intrinsic is `std::panic::catch_unwind`.
2666+
/// Note that in the case of a foreign unwinding operation, the exception object data may not be
2667+
/// safely usable from Rust, and should not be directly exposed via the standard library. To
2668+
/// prevent unsafe access, the library implementation may either abort the process or present an
2669+
/// opaque error type to the user.
2670+
///
2671+
/// For more information, see the compiler's source, as well as the documentation for the stable
2672+
/// version of this intrinsic, `std::panic::catch_unwind`.
26682673
#[rustc_nounwind]
26692674
pub fn catch_unwind(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
26702675

library/std/src/net/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl TcpStream {
561561

562562
/// Moves this TCP stream into or out of nonblocking mode.
563563
///
564-
/// This will result in `read`, `write`, `recv` and `send` operations
564+
/// This will result in `read`, `write`, `recv` and `send` system operations
565565
/// becoming nonblocking, i.e., immediately returning from their calls.
566566
/// If the IO operation is successful, `Ok` is returned and no further
567567
/// action is required. If the IO operation could not be completed and needs

library/std/src/net/udp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ impl UdpSocket {
764764

765765
/// Moves this UDP socket into or out of nonblocking mode.
766766
///
767-
/// This will result in `recv`, `recv_from`, `send`, and `send_to`
767+
/// This will result in `recv`, `recv_from`, `send`, and `send_to` system
768768
/// operations becoming nonblocking, i.e., immediately returning from their
769769
/// calls. If the IO operation is successful, `Ok` is returned and no
770770
/// further action is required. If the IO operation could not be completed

library/std/src/panic.rs

+34-24
Original file line numberDiff line numberDiff line change
@@ -288,45 +288,55 @@ pub use core::panic::abort_unwind;
288288

289289
/// Invokes a closure, capturing the cause of an unwinding panic if one occurs.
290290
///
291-
/// This function will return `Ok` with the closure's result if the closure
292-
/// does not panic, and will return `Err(cause)` if the closure panics. The
293-
/// `cause` returned is the object with which panic was originally invoked.
291+
/// This function will return `Ok` with the closure's result if the closure does
292+
/// not panic, and will return `Err(cause)` if the closure panics. The `cause`
293+
/// returned is the object with which panic was originally invoked.
294294
///
295-
/// It is currently undefined behavior to unwind from Rust code into foreign
296-
/// code, so this function is particularly useful when Rust is called from
297-
/// another language (normally C). This can run arbitrary Rust code, capturing a
298-
/// panic and allowing a graceful handling of the error.
295+
/// Rust functions that are expected to be called from foreign code that does
296+
/// not support unwinding (such as C compiled with `-fno-exceptions`) should be
297+
/// defined using `extern "C"`, which ensures that if the Rust code panics, it
298+
/// is automatically caught and the process is aborted. If this is the desired
299+
/// behavior, it is not necessary to use `catch_unwind` explicitly. This
300+
/// function should instead be used when more graceful error-handling is needed.
299301
///
300302
/// It is **not** recommended to use this function for a general try/catch
301303
/// mechanism. The [`Result`] type is more appropriate to use for functions that
302304
/// can fail on a regular basis. Additionally, this function is not guaranteed
303305
/// to catch all panics, see the "Notes" section below.
304306
///
305-
/// The closure provided is required to adhere to the [`UnwindSafe`] trait to ensure
306-
/// that all captured variables are safe to cross this boundary. The purpose of
307-
/// this bound is to encode the concept of [exception safety][rfc] in the type
308-
/// system. Most usage of this function should not need to worry about this
309-
/// bound as programs are naturally unwind safe without `unsafe` code. If it
310-
/// becomes a problem the [`AssertUnwindSafe`] wrapper struct can be used to quickly
311-
/// assert that the usage here is indeed unwind safe.
307+
/// The closure provided is required to adhere to the [`UnwindSafe`] trait to
308+
/// ensure that all captured variables are safe to cross this boundary. The
309+
/// purpose of this bound is to encode the concept of [exception safety][rfc] in
310+
/// the type system. Most usage of this function should not need to worry about
311+
/// this bound as programs are naturally unwind safe without `unsafe` code. If
312+
/// it becomes a problem the [`AssertUnwindSafe`] wrapper struct can be used to
313+
/// quickly assert that the usage here is indeed unwind safe.
312314
///
313315
/// [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1236-stabilize-catch-panic.md
314316
///
315317
/// # Notes
316318
///
317-
/// Note that this function **might not catch all panics** in Rust. A panic in
318-
/// Rust is not always implemented via unwinding, but can be implemented by
319-
/// aborting the process as well. This function *only* catches unwinding panics,
320-
/// not those that abort the process.
319+
/// This function **might not catch all Rust panics**. A Rust panic is not
320+
/// always implemented via unwinding, but can be implemented by aborting the
321+
/// process as well. This function *only* catches unwinding panics, not those
322+
/// that abort the process.
321323
///
322-
/// Note that if a custom panic hook has been set, it will be invoked before
323-
/// the panic is caught, before unwinding.
324+
/// If a custom panic hook has been set, it will be invoked before the panic is
325+
/// caught, before unwinding.
324326
///
325-
/// Also note that unwinding into Rust code with a foreign exception (e.g.
326-
/// an exception thrown from C++ code) is undefined behavior.
327+
/// Although unwinding into Rust code with a foreign exception (e.g. an
328+
/// exception thrown from C++ code, or a `panic!` in Rust code compiled or
329+
/// linked with a different runtime) via an appropriate ABI (e.g. `"C-unwind"`)
330+
/// is permitted, catching such an exception using this function will have one
331+
/// of two behaviors, and it is unspecified which will occur:
327332
///
328-
/// Finally, be **careful in how you drop the result of this function**.
329-
/// If it is `Err`, it contains the panic payload, and dropping that may in turn panic!
333+
/// * The process aborts, after executing all destructors of `f` and the
334+
/// functions it called.
335+
/// * The function returns a `Result::Err` containing an opaque type.
336+
///
337+
/// Finally, be **careful in how you drop the result of this function**. If it
338+
/// is `Err`, it contains the panic payload, and dropping that may in turn
339+
/// panic!
330340
///
331341
/// # Examples
332342
///

library/std/src/thread/mod.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,19 @@ impl Builder {
664664
/// println!("{result}");
665665
/// ```
666666
///
667+
/// # Notes
668+
///
669+
/// This function has the same minimal guarantee regarding "foreign" unwinding operations (e.g.
670+
/// an exception thrown from C++ code, or a `panic!` in Rust code compiled or linked with a
671+
/// different runtime) as [`catch_unwind`]; namely, if the thread created with `thread::spawn`
672+
/// unwinds all the way to the root with such an exception, one of two behaviors are possible,
673+
/// and it is unspecified which will occur:
674+
///
675+
/// * The process aborts.
676+
/// * The process does not abort, and [`join`] will return a `Result::Err`
677+
/// containing an opaque type.
678+
///
679+
/// [`catch_unwind`]: ../../std/panic/fn.catch_unwind.html
667680
/// [`channels`]: crate::sync::mpsc
668681
/// [`join`]: JoinHandle::join
669682
/// [`Err`]: crate::result::Result::Err
@@ -1784,7 +1797,7 @@ impl<T> JoinHandle<T> {
17841797
/// operations that happen after `join` returns.
17851798
///
17861799
/// If the associated thread panics, [`Err`] is returned with the parameter given
1787-
/// to [`panic!`].
1800+
/// to [`panic!`] (though see the Notes below).
17881801
///
17891802
/// [`Err`]: crate::result::Result::Err
17901803
/// [atomic memory orderings]: crate::sync::atomic
@@ -1806,6 +1819,18 @@ impl<T> JoinHandle<T> {
18061819
/// }).unwrap();
18071820
/// join_handle.join().expect("Couldn't join on the associated thread");
18081821
/// ```
1822+
///
1823+
/// # Notes
1824+
///
1825+
/// If a "foreign" unwinding operation (e.g. an exception thrown from C++
1826+
/// code, or a `panic!` in Rust code compiled or linked with a different
1827+
/// runtime) unwinds all the way to the thread root, the process may be
1828+
/// aborted; see the Notes on [`thread::spawn`]. If the process is not
1829+
/// aborted, this function will return a `Result::Err` containing an opaque
1830+
/// type.
1831+
///
1832+
/// [`catch_unwind`]: ../../std/panic/fn.catch_unwind.html
1833+
/// [`thread::spawn`]: spawn
18091834
#[stable(feature = "rust1", since = "1.0.0")]
18101835
pub fn join(self) -> Result<T> {
18111836
self.0.join()
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.18.0
1+
0.18.1

tests/rustdoc-gui/docblock-code-block-line-number.goml

+6-12
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ assert-css: ("#settings", {"display": "block"})
8787

8888
// Then, click the toggle button.
8989
click: "input#line-numbers"
90-
wait-for: 100 // FIXME: `wait-for-false` does not exist
91-
assert-false: "pre.example-line-numbers"
90+
wait-for-false: "pre.example-line-numbers"
9291
assert-local-storage: {"rustdoc-line-numbers": "false" }
9392

9493
// Check that the rounded corners are back.
@@ -107,8 +106,7 @@ assert-css: (
107106
click: "input#line-numbers"
108107
wait-for: "pre.example-line-numbers"
109108
assert-local-storage: {"rustdoc-line-numbers": "true" }
110-
wait-for: 100 // FIXME: `wait-for-false` does not exist
111-
assert: "pre.example-line-numbers"
109+
wait-for: "pre.example-line-numbers"
112110

113111
// Same check with scraped examples line numbers.
114112
go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
@@ -195,15 +193,13 @@ define-function: ("check-line-numbers-existence", [], block {
195193

196194
// Then, click the toggle button.
197195
click: "input#line-numbers"
198-
wait-for: 100 // FIXME: `wait-for-false` does not exist
199-
assert-local-storage-false: {"rustdoc-line-numbers": "true" }
196+
wait-for-local-storage-false: {"rustdoc-line-numbers": "true" }
200197
assert-false: ".example-line-numbers"
201198
// Line numbers should still be there.
202199
assert: ".src-line-numbers"
203200
// Now disabling the setting.
204201
click: "input#line-numbers"
205-
wait-for: 100 // FIXME: `wait-for-false` does not exist
206-
assert-local-storage: {"rustdoc-line-numbers": "true" }
202+
wait-for-local-storage: {"rustdoc-line-numbers": "true" }
207203
assert-false: ".example-line-numbers"
208204
// Line numbers should still be there.
209205
assert: ".src-line-numbers"
@@ -246,12 +242,10 @@ wait-for: "#settings"
246242

247243
// Then, click the toggle button.
248244
click: "input#line-numbers"
249-
wait-for: 100 // FIXME: `wait-for-false` does not exist
245+
wait-for-count: (".example-wrap > pre.example-line-numbers", 0)
250246
assert-local-storage-false: {"rustdoc-line-numbers": "true" }
251-
assert-count: (".example-wrap > pre.example-line-numbers", 0)
252247

253248
// Now turning off the setting.
254249
click: "input#line-numbers"
255-
wait-for: 100 // FIXME: `wait-for-false` does not exist
250+
wait-for-count: (".example-wrap > pre.example-line-numbers", 2)
256251
assert-local-storage: {"rustdoc-line-numbers": "true" }
257-
assert-count: (".example-wrap > pre.example-line-numbers", 2)

0 commit comments

Comments
 (0)