Skip to content

Fix documentation for unstable sort on slice #137484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2928,10 +2928,17 @@ impl<T> [T] {
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
///
/// If the implementation of [`Ord`] for `T` does not implement a [total order] the resulting
/// order of elements in the slice is unspecified. All original elements will remain in the
/// slice and any possible modifications via interior mutability are observed in the input. Same
/// is true if the implementation of [`Ord`] for `T` panics.
/// If the implementation of [`Ord`] for `T` does not implement a [total order], the function
/// may panic; even if the function exits normally, the resulting order of elements in the slice
/// is unspecified. See also the note on panicking below.
///
/// For example `|a, b| (a - b).cmp(a)` is a comparison function that is neither transitive nor
/// reflexive nor total, `a < b < c < a` with `a = 1, b = 2, c = 3`. For more information and
/// examples see the [`Ord`] documentation.
///
///
/// All original elements will remain in the slice and any possible modifications via interior
/// mutability are observed in the input. Same is true if the implementation of [`Ord`] for `T` panics.
///
/// Sorting types that only implement [`PartialOrd`] such as [`f32`] and [`f64`] require
/// additional precautions. For example, `f32::NAN != f32::NAN`, which doesn't fulfill the
Expand All @@ -2954,7 +2961,8 @@ impl<T> [T] {
///
/// # Panics
///
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order].
/// May panic if the implementation of [`Ord`] for `T` does not implement a [total order], or if
/// the [`Ord`] implementation panics.
///
/// # Examples
///
Expand Down Expand Up @@ -2982,15 +2990,17 @@ impl<T> [T] {
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
///
/// If the comparison function `compare` does not implement a [total order] the resulting order
/// of elements in the slice is unspecified. All original elements will remain in the slice and
/// any possible modifications via interior mutability are observed in the input. Same is true
/// if `compare` panics.
/// If the comparison function `compare` does not implement a [total order], the function
/// may panic; even if the function exits normally, the resulting order of elements in the slice
/// is unspecified. See also the note on panicking below.
///
/// For example `|a, b| (a - b).cmp(a)` is a comparison function that is neither transitive nor
/// reflexive nor total, `a < b < c < a` with `a = 1, b = 2, c = 3`. For more information and
/// examples see the [`Ord`] documentation.
///
/// All original elements will remain in the slice and any possible modifications via interior
/// mutability are observed in the input. Same is true if `compare` panics.
///
/// # Current implementation
///
/// The current implementation is based on [ipnsort] by Lukas Bergdoll and Orson Peters, which
Expand All @@ -3003,7 +3013,8 @@ impl<T> [T] {
///
/// # Panics
///
/// May panic if `compare` does not implement a [total order].
/// May panic if the `compare` does not implement a [total order], or if
/// the `compare` itself panics.
///
/// # Examples
///
Expand Down Expand Up @@ -3034,10 +3045,16 @@ impl<T> [T] {
/// This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not
/// allocate), and *O*(*n* \* log(*n*)) worst-case.
///
/// If the implementation of [`Ord`] for `K` does not implement a [total order] the resulting
/// order of elements in the slice is unspecified. All original elements will remain in the
/// slice and any possible modifications via interior mutability are observed in the input. Same
/// is true if the implementation of [`Ord`] for `K` panics.
/// If the implementation of [`Ord`] for `K` does not implement a [total order], the function
/// may panic; even if the function exits normally, the resulting order of elements in the slice
/// is unspecified. See also the note on panicking below.
///
/// For example `|a, b| (a - b).cmp(a)` is a comparison function that is neither transitive nor
/// reflexive nor total, `a < b < c < a` with `a = 1, b = 2, c = 3`. For more information and
/// examples see the [`Ord`] documentation.
///
/// All original elements will remain in the slice and any possible modifications via interior
/// mutability are observed in the input. Same is true if the implementation of [`Ord`] for `K` panics.
///
/// # Current implementation
///
Expand All @@ -3051,7 +3068,8 @@ impl<T> [T] {
///
/// # Panics
///
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order].
/// May panic if the implementation of [`Ord`] for `K` does not implement a [total order], or if
/// the [`Ord`] implementation panics.
///
/// # Examples
///
Expand Down
Loading