From 00ce238885825e5e987dbcd4fef266e96157303d Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Sat, 27 Jul 2024 16:48:42 +0200 Subject: [PATCH] Improve panic sections for sort*, sort_unstable* and select_nth_unstable* - Move panic information into # Panics section - Fix mentions of T: Ord that should be compare - Add missing information --- library/alloc/src/slice.rs | 16 +++++++++++++--- library/core/src/slice/mod.rs | 27 +++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index c7960b3fb49c3..9e222c6072fd7 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -199,7 +199,9 @@ impl [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 /// @@ -258,7 +260,9 @@ impl [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 /// @@ -304,7 +308,9 @@ impl [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 /// @@ -356,6 +362,10 @@ impl [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 /// /// ``` diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 6d3e625bef428..8916d43a8f236 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2898,7 +2898,9 @@ impl [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 /// @@ -2955,7 +2957,9 @@ impl [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 /// @@ -2999,7 +3003,9 @@ impl [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 /// @@ -3042,15 +3048,14 @@ impl [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 /// /// ``` @@ -3103,15 +3108,14 @@ impl [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 /// /// ``` @@ -3168,15 +3172,14 @@ impl [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 /// /// ```