diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-03-16 11:11:31 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-03-18 17:21:16 -0700 |
| commit | e78f2e2ac577f9c47cd58af52d3bcd496254545d (patch) | |
| tree | f05564837fe02f676458ea86b705709715c44017 /src/libstd/sort.rs | |
| parent | c4db4faefaf13ac814f34c2a6cf105b7684de019 (diff) | |
| download | rust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.tar.gz rust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.zip | |
librustc: Make the compiler ignore purity.
For bootstrapping purposes, this commit does not remove all uses of
the keyword "pure" -- doing so would cause the compiler to no longer
bootstrap due to some syntax extensions ("deriving" in particular).
Instead, it makes the compiler ignore "pure". Post-snapshot, we can
remove "pure" from the language.
There are quite a few (~100) borrow check errors that were essentially
all the result of mutable fields or partial borrows of `@mut`. Per
discussions with Niko I think we want to allow partial borrows of
`@mut` but detect obvious footguns. We should also improve the error
message when `@mut` is erroneously reborrowed.
Diffstat (limited to 'src/libstd/sort.rs')
| -rw-r--r-- | src/libstd/sort.rs | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 43c68196eb8..40be303a147 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -68,9 +68,14 @@ fn part<T>(arr: &mut [T], left: uint, let mut storage_index: uint = left; let mut i: uint = left; while i < right { - if compare_func(&arr[i], &arr[right]) { - arr[i] <-> arr[storage_index]; - storage_index += 1; + // XXX: Unsafe because borrow check doesn't handle this right + unsafe { + let a: &T = cast::transmute(&mut arr[i]); + let b: &T = cast::transmute(&mut arr[right]); + if compare_func(a, b) { + arr[i] <-> arr[storage_index]; + storage_index += 1; + } } i += 1; } @@ -451,7 +456,10 @@ impl<T:Copy + Ord> MergeState<T> { base2: uint, len2: uint) { fail_unless!(len1 != 0 && len2 != 0 && base1+len1 == base2); - let mut tmp = vec::slice(array, base1, base1+len1).to_vec(); + let mut tmp = ~[]; + for uint::range(base1, base1+len1) |i| { + tmp.push(array[i]); + } let mut c1 = 0; let mut c2 = base2; @@ -554,7 +562,10 @@ impl<T:Copy + Ord> MergeState<T> { base2: uint, len2: uint) { fail_unless!(len1 != 1 && len2 != 0 && base1 + len1 == base2); - let mut tmp = vec::slice(array, base2, base2+len2).to_vec(); + let mut tmp = ~[]; + for uint::range(base2, base2+len2) |i| { + tmp.push(array[i]); + } let mut c1 = base1 + len1 - 1; let mut c2 = len2 - 1; @@ -702,7 +713,11 @@ fn copy_vec<T:Copy>(dest: &mut [T], s1: uint, from: &[const T], s2: uint, len: uint) { fail_unless!(s1+len <= dest.len() && s2+len <= from.len()); - let slice = vec::slice(from, s2, s2+len).to_vec(); + let mut slice = ~[]; + for uint::range(s2, s2+len) |i| { + slice.push(from[i]); + } + for slice.eachi |i, v| { dest[s1+i] = *v; } @@ -721,7 +736,7 @@ mod test_qsort3 { quick_sort3::<int>(v1); let mut i = 0; while i < len { - debug!(v2[i]); + // debug!(v2[i]); fail_unless!((v2[i] == v1[i])); i += 1; } @@ -768,7 +783,7 @@ mod test_qsort { quick_sort::<int>(v1, leual); let mut i = 0u; while i < len { - debug!(v2[i]); + // debug!(v2[i]); fail_unless!((v2[i] == v1[i])); i += 1; } @@ -919,7 +934,7 @@ mod test_tim_sort { tim_sort::<int>(v1); let mut i = 0u; while i < len { - debug!(v2[i]); + // debug!(v2[i]); fail_unless!((v2[i] == v1[i])); i += 1u; } |
