diff options
| author | Lukas Bergdoll <lukas.bergdoll@gmail.com> | 2024-07-27 16:48:42 +0200 |
|---|---|---|
| committer | Lukas Bergdoll <lukas.bergdoll@gmail.com> | 2024-07-27 16:48:42 +0200 |
| commit | 00ce238885825e5e987dbcd4fef266e96157303d (patch) | |
| tree | 7e6a08a6baf5833cd1b1d82eab05e8e548c5bfd6 | |
| parent | 644550f3de4805b3dec6ade4a60ecf48c1d2487b (diff) | |
| download | rust-00ce238885825e5e987dbcd4fef266e96157303d.tar.gz rust-00ce238885825e5e987dbcd4fef266e96157303d.zip | |
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
| -rw-r--r-- | library/alloc/src/slice.rs | 16 | ||||
| -rw-r--r-- | 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 c7960b3fb49..9e222c6072f 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -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 /// @@ -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 /// @@ -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 /// @@ -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 /// /// ``` diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 6d3e625bef4..8916d43a8f2 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -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 /// @@ -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 /// @@ -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 /// @@ -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 /// /// ``` @@ -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 /// /// ``` @@ -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 /// /// ``` |
