Skip to content

Commit c0b3b02

Browse files
authored
Rollup merge of rust-lang#137484 - chenyukang:yukang-fix-sort-doc, r=Noratrieb
Fix documentation for unstable sort on slice Fixes rust-lang#136665
2 parents 8b8593f + e29396c commit c0b3b02

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

core/src/slice/mod.rs

+33-15
Original file line numberDiff line numberDiff line change
@@ -2928,10 +2928,17 @@ impl<T> [T] {
29282928
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
29292929
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
29302930
///
2931-
/// If the implementation of [`Ord`] for `T` does not implement a [total order] the resulting
2932-
/// order of elements in the slice is unspecified. All original elements will remain in the
2933-
/// slice and any possible modifications via interior mutability are observed in the input. Same
2934-
/// is true if the implementation of [`Ord`] for `T` panics.
2931+
/// If the implementation of [`Ord`] for `T` does not implement a [total order], the function
2932+
/// may panic; even if the function exits normally, the resulting order of elements in the slice
2933+
/// is unspecified. See also the note on panicking below.
2934+
///
2935+
/// For example `|a, b| (a - b).cmp(a)` is a comparison function that is neither transitive nor
2936+
/// reflexive nor total, `a < b < c < a` with `a = 1, b = 2, c = 3`. For more information and
2937+
/// examples see the [`Ord`] documentation.
2938+
///
2939+
///
2940+
/// All original elements will remain in the slice and any possible modifications via interior
2941+
/// mutability are observed in the input. Same is true if the implementation of [`Ord`] for `T` panics.
29352942
///
29362943
/// Sorting types that only implement [`PartialOrd`] such as [`f32`] and [`f64`] require
29372944
/// additional precautions. For example, `f32::NAN != f32::NAN`, which doesn't fulfill the
@@ -2954,7 +2961,8 @@ impl<T> [T] {
29542961
///
29552962
/// # Panics
29562963
///
2957-
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order].
2964+
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order], or if
2965+
/// the [`Ord`] implementation panics.
29582966
///
29592967
/// # Examples
29602968
///
@@ -2982,15 +2990,17 @@ impl<T> [T] {
29822990
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
29832991
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
29842992
///
2985-
/// If the comparison function `compare` does not implement a [total order] the resulting order
2986-
/// of elements in the slice is unspecified. All original elements will remain in the slice and
2987-
/// any possible modifications via interior mutability are observed in the input. Same is true
2988-
/// if `compare` panics.
2993+
/// If the comparison function `compare` does not implement a [total order], the function
2994+
/// may panic; even if the function exits normally, the resulting order of elements in the slice
2995+
/// is unspecified. See also the note on panicking below.
29892996
///
29902997
/// For example `|a, b| (a - b).cmp(a)` is a comparison function that is neither transitive nor
29912998
/// reflexive nor total, `a < b < c < a` with `a = 1, b = 2, c = 3`. For more information and
29922999
/// examples see the [`Ord`] documentation.
29933000
///
3001+
/// All original elements will remain in the slice and any possible modifications via interior
3002+
/// mutability are observed in the input. Same is true if `compare` panics.
3003+
///
29943004
/// # Current implementation
29953005
///
29963006
/// The current implementation is based on [ipnsort] by Lukas Bergdoll and Orson Peters, which
@@ -3003,7 +3013,8 @@ impl<T> [T] {
30033013
///
30043014
/// # Panics
30053015
///
3006-
/// May panic if `compare` does not implement a [total order].
3016+
/// May panic if the `compare` does not implement a [total order], or if
3017+
/// the `compare` itself panics.
30073018
///
30083019
/// # Examples
30093020
///
@@ -3034,10 +3045,16 @@ impl<T> [T] {
30343045
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
30353046
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
30363047
///
3037-
/// If the implementation of [`Ord`] for `K` does not implement a [total order] the resulting
3038-
/// order of elements in the slice is unspecified. All original elements will remain in the
3039-
/// slice and any possible modifications via interior mutability are observed in the input. Same
3040-
/// is true if the implementation of [`Ord`] for `K` panics.
3048+
/// If the implementation of [`Ord`] for `K` does not implement a [total order], the function
3049+
/// may panic; even if the function exits normally, the resulting order of elements in the slice
3050+
/// is unspecified. See also the note on panicking below.
3051+
///
3052+
/// For example `|a, b| (a - b).cmp(a)` is a comparison function that is neither transitive nor
3053+
/// reflexive nor total, `a < b < c < a` with `a = 1, b = 2, c = 3`. For more information and
3054+
/// examples see the [`Ord`] documentation.
3055+
///
3056+
/// All original elements will remain in the slice and any possible modifications via interior
3057+
/// mutability are observed in the input. Same is true if the implementation of [`Ord`] for `K` panics.
30413058
///
30423059
/// # Current implementation
30433060
///
@@ -3051,7 +3068,8 @@ impl<T> [T] {
30513068
///
30523069
/// # Panics
30533070
///
3054-
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order].
3071+
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order], or if
3072+
/// the [`Ord`] implementation panics.
30553073
///
30563074
/// # Examples
30573075
///

0 commit comments

Comments
 (0)