Skip to content

Commit

Permalink
Improve panic sections for sort*, sort_unstable* and select_nth_unsta…
Browse files Browse the repository at this point in the history
…ble*

- Move panic information into # Panics section
- Fix mentions of T: Ord that should be compare
- Add missing information
  • Loading branch information
Voultapher committed Jul 27, 2024
1 parent 644550f commit 00ce238
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
16 changes: 13 additions & 3 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ impl<T> [T] {
/// handled without allocation, medium sized slices allocate `self.len()` and beyond that it
/// clamps at `self.len() / 2`.
///
/// If `T: Ord` does not implement a total order, the implementation may panic.
/// # Panics
///
/// May panic if `T: Ord` does not implement a total order.
///
/// # Examples
///
Expand Down Expand Up @@ -258,7 +260,9 @@ impl<T> [T] {
/// handled without allocation, medium sized slices allocate `self.len()` and beyond that it
/// clamps at `self.len() / 2`.
///
/// If `T: Ord` does not implement a total order, the implementation may panic.
/// # Panics
///
/// May panic if `compare` does not implement a total order.
///
/// # Examples
///
Expand Down Expand Up @@ -304,7 +308,9 @@ impl<T> [T] {
/// handled without allocation, medium sized slices allocate `self.len()` and beyond that it
/// clamps at `self.len() / 2`.
///
/// If `K: Ord` does not implement a total order, the implementation may panic.
/// # Panics
///
/// May panic if `K: Ord` does not implement a total order.
///
/// # Examples
///
Expand Down Expand Up @@ -356,6 +362,10 @@ impl<T> [T] {
/// In the worst case, the algorithm allocates temporary storage in a `Vec<(K, usize)>` the
/// length of the slice.
///
/// # Panics
///
/// May panic if `K: Ord` does not implement a total order.
///
/// # Examples
///
/// ```
Expand Down
27 changes: 15 additions & 12 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2898,7 +2898,9 @@ impl<T> [T] {
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
/// slice is partially sorted.
///
/// If `T: Ord` does not implement a total order, the implementation may panic.
/// # Panics
///
/// May panic if `T: Ord` does not implement a total order.
///
/// # Examples
///
Expand Down Expand Up @@ -2955,7 +2957,9 @@ impl<T> [T] {
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
/// slice is partially sorted.
///
/// If `T: Ord` does not implement a total order, the implementation may panic.
/// # Panics
///
/// May panic if `compare` does not implement a total order.
///
/// # Examples
///
Expand Down Expand Up @@ -2999,7 +3003,9 @@ impl<T> [T] {
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
/// slice is partially sorted.
///
/// If `K: Ord` does not implement a total order, the implementation may panic.
/// # Panics
///
/// May panic if `K: Ord` does not implement a total order.
///
/// # Examples
///
Expand Down Expand Up @@ -3042,15 +3048,14 @@ impl<T> [T] {
/// Median of Medians using Tukey's Ninther for pivot selection, which guarantees linear runtime
/// for all inputs.
///
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
/// slice is nearly fully sorted, where `slice::sort` may be faster.
///
/// [`sort_unstable`]: slice::sort_unstable
///
/// # Panics
///
/// Panics when `index >= len()`, meaning it always panics on empty slices.
///
/// May panic if `T: Ord` does not implement a total order.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -3103,15 +3108,14 @@ impl<T> [T] {
/// Median of Medians using Tukey's Ninther for pivot selection, which guarantees linear runtime
/// for all inputs.
///
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
/// slice is nearly fully sorted, where `slice::sort` may be faster.
///
/// [`sort_unstable`]: slice::sort_unstable
///
/// # Panics
///
/// Panics when `index >= len()`, meaning it always panics on empty slices.
///
/// May panic if `compare` does not implement a total order.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -3168,15 +3172,14 @@ impl<T> [T] {
/// Median of Medians using Tukey's Ninther for pivot selection, which guarantees linear runtime
/// for all inputs.
///
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
/// slice is nearly fully sorted, where `slice::sort` may be faster.
///
/// [`sort_unstable`]: slice::sort_unstable
///
/// # Panics
///
/// Panics when `index >= len()`, meaning it always panics on empty slices.
///
/// May panic if `K: Ord` does not implement a total order.
///
/// # Examples
///
/// ```
Expand Down

0 comments on commit 00ce238

Please sign in to comment.