Skip to content

Commit b014b0d

Browse files
committed
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
1 parent 9bcfe84 commit b014b0d

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

Diff for: alloc/src/slice.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ impl<T> [T] {
199199
/// handled without allocation, medium sized slices allocate `self.len()` and beyond that it
200200
/// clamps at `self.len() / 2`.
201201
///
202-
/// If `T: Ord` does not implement a total order, the implementation may panic.
202+
/// # Panics
203+
///
204+
/// May panic if `T: Ord` does not implement a total order.
203205
///
204206
/// # Examples
205207
///
@@ -258,7 +260,9 @@ impl<T> [T] {
258260
/// handled without allocation, medium sized slices allocate `self.len()` and beyond that it
259261
/// clamps at `self.len() / 2`.
260262
///
261-
/// If `T: Ord` does not implement a total order, the implementation may panic.
263+
/// # Panics
264+
///
265+
/// May panic if `compare` does not implement a total order.
262266
///
263267
/// # Examples
264268
///
@@ -304,7 +308,9 @@ impl<T> [T] {
304308
/// handled without allocation, medium sized slices allocate `self.len()` and beyond that it
305309
/// clamps at `self.len() / 2`.
306310
///
307-
/// If `K: Ord` does not implement a total order, the implementation may panic.
311+
/// # Panics
312+
///
313+
/// May panic if `K: Ord` does not implement a total order.
308314
///
309315
/// # Examples
310316
///
@@ -356,6 +362,10 @@ impl<T> [T] {
356362
/// In the worst case, the algorithm allocates temporary storage in a `Vec<(K, usize)>` the
357363
/// length of the slice.
358364
///
365+
/// # Panics
366+
///
367+
/// May panic if `K: Ord` does not implement a total order.
368+
///
359369
/// # Examples
360370
///
361371
/// ```

Diff for: core/src/slice/mod.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,9 @@ impl<T> [T] {
28982898
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
28992899
/// slice is partially sorted.
29002900
///
2901-
/// If `T: Ord` does not implement a total order, the implementation may panic.
2901+
/// # Panics
2902+
///
2903+
/// May panic if `T: Ord` does not implement a total order.
29022904
///
29032905
/// # Examples
29042906
///
@@ -2955,7 +2957,9 @@ impl<T> [T] {
29552957
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
29562958
/// slice is partially sorted.
29572959
///
2958-
/// If `T: Ord` does not implement a total order, the implementation may panic.
2960+
/// # Panics
2961+
///
2962+
/// May panic if `compare` does not implement a total order.
29592963
///
29602964
/// # Examples
29612965
///
@@ -2999,7 +3003,9 @@ impl<T> [T] {
29993003
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
30003004
/// slice is partially sorted.
30013005
///
3002-
/// If `K: Ord` does not implement a total order, the implementation may panic.
3006+
/// # Panics
3007+
///
3008+
/// May panic if `K: Ord` does not implement a total order.
30033009
///
30043010
/// # Examples
30053011
///
@@ -3042,15 +3048,14 @@ impl<T> [T] {
30423048
/// Median of Medians using Tukey's Ninther for pivot selection, which guarantees linear runtime
30433049
/// for all inputs.
30443050
///
3045-
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
3046-
/// slice is nearly fully sorted, where `slice::sort` may be faster.
3047-
///
30483051
/// [`sort_unstable`]: slice::sort_unstable
30493052
///
30503053
/// # Panics
30513054
///
30523055
/// Panics when `index >= len()`, meaning it always panics on empty slices.
30533056
///
3057+
/// May panic if `T: Ord` does not implement a total order.
3058+
///
30543059
/// # Examples
30553060
///
30563061
/// ```
@@ -3103,15 +3108,14 @@ impl<T> [T] {
31033108
/// Median of Medians using Tukey's Ninther for pivot selection, which guarantees linear runtime
31043109
/// for all inputs.
31053110
///
3106-
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
3107-
/// slice is nearly fully sorted, where `slice::sort` may be faster.
3108-
///
31093111
/// [`sort_unstable`]: slice::sort_unstable
31103112
///
31113113
/// # Panics
31123114
///
31133115
/// Panics when `index >= len()`, meaning it always panics on empty slices.
31143116
///
3117+
/// May panic if `compare` does not implement a total order.
3118+
///
31153119
/// # Examples
31163120
///
31173121
/// ```
@@ -3168,15 +3172,14 @@ impl<T> [T] {
31683172
/// Median of Medians using Tukey's Ninther for pivot selection, which guarantees linear runtime
31693173
/// for all inputs.
31703174
///
3171-
/// It is typically faster than stable sorting, except in a few special cases, e.g., when the
3172-
/// slice is nearly fully sorted, where `slice::sort` may be faster.
3173-
///
31743175
/// [`sort_unstable`]: slice::sort_unstable
31753176
///
31763177
/// # Panics
31773178
///
31783179
/// Panics when `index >= len()`, meaning it always panics on empty slices.
31793180
///
3181+
/// May panic if `K: Ord` does not implement a total order.
3182+
///
31803183
/// # Examples
31813184
///
31823185
/// ```

0 commit comments

Comments
 (0)