Skip to content

Commit

Permalink
Removed a FIXME, added some comments linking to std source
Browse files Browse the repository at this point in the history
  • Loading branch information
onestacked committed Sep 21, 2022
1 parent dbe1eb4 commit c4506df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions const_sort_rs/src/const_slice_sort_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,15 @@ impl<T: ~const Destruct> const ConstSliceSortExt<T> for [T] {
where
T: ~const PartialOrd + Ord,
{
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2539
const_sort::const_quicksort(self, const_pred_lt);
}
#[inline]
fn const_sort_unstable_by<F>(&mut self, mut compare: F)
where
F: ~const FnMut(&T, &T) -> Ordering + ~const Destruct,
{
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2594
// sort::const_quicksort(self, |a, b| compare(a, b) == Ordering::Less);
const fn imp<T, F>(compare: &mut F, (a, b): (&T, &T)) -> bool
where
Expand All @@ -445,6 +447,7 @@ impl<T: ~const Destruct> const ConstSliceSortExt<T> for [T] {
F: ~const FnMut(&T) -> K + ~const Destruct,
K: Ord + ~const PartialOrd + ~const Destruct,
{
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2632
// sort::quicksort(self, |a, b| f(a).lt(&f(b)));
const fn imp<T, F, K: ~const PartialOrd + ~const Destruct>(f: &mut F, (a, b): (&T, &T)) -> bool
where
Expand All @@ -460,6 +463,7 @@ impl<T: ~const Destruct> const ConstSliceSortExt<T> for [T] {
where
T: ~const PartialOrd + Ord,
{
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2678
// let mut f = |a: &T, b: &T| a.lt(b);
// sort::partition_at_index(self, index, &mut f)
const_sort::const_partition_at_index(self, index, const_pred_lt)
Expand All @@ -473,6 +477,7 @@ impl<T: ~const Destruct> const ConstSliceSortExt<T> for [T] {
where
F: ~const FnMut(&T, &T) -> Ordering + ~const Destruct,
{
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2725
// let mut f = |a: &T, b: &T| compare(a, b) == Less;
// sort::partition_at_index(self, index, &mut f)
const fn imp<T, F>(compare: &mut F, (a, b): (&T, &T)) -> bool
Expand All @@ -493,6 +498,7 @@ impl<T: ~const Destruct> const ConstSliceSortExt<T> for [T] {
F: ~const FnMut(&T) -> K + ~const Destruct,
K: Ord + ~const PartialOrd + ~const Destruct,
{
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2776
// let mut g = |a: &T, b: &T| f(a).lt(&f(b));
// sort::partition_at_index(self, index, &mut g)
const fn imp<T, F, K: ~const PartialOrd + ~const Destruct>(f: &mut F, (a, b): (&T, &T)) -> bool
Expand Down Expand Up @@ -522,8 +528,7 @@ impl<T: ~const Destruct> const ConstSliceSortExt<T> for [T] {
let mut i = 1;
while i < self.len() {
let ord_opt = compare(&self[i - 1], &self[i]);
if matches!(ord_opt, None) {
// FIXME: Once the matches can be replaced with `==`.
if ord_opt.is_none() {
return false;
}
if ord_opt.unwrap() == Ordering::Greater {
Expand All @@ -547,6 +552,8 @@ impl<T: ~const Destruct> const ConstSliceSortExt<T> for [T] {
T: ~const Destruct,
for<'r> F: ~const FnMut(&'r T) -> K + ~const Destruct,
{
// https://doc.rust-lang.org/nightly/src/core/iter/traits/iterator.rs.html#3840
// self.map(f).is_sorted()
f(a).partial_cmp(&f(b))
}
self.const_is_sorted_by(ConstFnMutClosure::new(&mut f, imp))
Expand Down
2 changes: 2 additions & 0 deletions const_sort_rs/src/slice_const_split_at_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl<T> const ConstSplitAtMutExtensions<T> for [T] {
#[inline]
#[track_caller]
fn const_split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1583
assert!(mid <= self.len());
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
// fulfils the requirements of `from_raw_parts_mut`.
Expand All @@ -78,6 +79,7 @@ impl<T> const ConstSplitAtMutExtensions<T> for [T] {

#[inline]
unsafe fn const_split_at_mut_unchecked(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
// https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1684
let len = self.len();
let ptr = self.as_mut_ptr();

Expand Down

0 comments on commit c4506df

Please sign in to comment.