diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 9131c07aa55..17a448001bd 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -1499,7 +1499,8 @@ fn print_pkg(s: source, p: package) { fn print_source(s: source) { info(s.name + ~" (" + s.url + ~")"); - let pks = sort::merge_sort(sys::shape_lt, copy s.packages); + let unsorted_pks = s.packages; // to prevent illegal borrow? + let pks = sort::merge_sort(sys::shape_lt, unsorted_pks); let l = vec::len(pks); print(io::with_str_writer(|writer| { diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 33e6feb8427..07552a0a94f 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -1,4 +1,7 @@ //! Sorting methods +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + import vec::{len, push}; import core::cmp::{Eq, Ord}; @@ -15,12 +18,12 @@ type le = pure fn(v1: &T, v2: &T) -> bool; * Has worst case O(n log n) performance, best case O(n), but * is not space efficient. This is a stable sort. */ -fn merge_sort(le: le, v: ~[const T]) -> ~[T] { +fn merge_sort(le: le, v: &[const T]) -> ~[T] { type slice = (uint, uint); return merge_sort_(le, v, (0u, len(v))); - fn merge_sort_(le: le, v: ~[const T], slice: slice) + fn merge_sort_(le: le, v: &[const T], slice: slice) -> ~[T] { let begin = slice.first(); let end = slice.second(); @@ -35,7 +38,7 @@ fn merge_sort(le: le, v: ~[const T]) -> ~[T] { return merge(le, merge_sort_(le, v, a), merge_sort_(le, v, b)); } - fn merge(le: le, a: ~[T], b: ~[T]) -> ~[T] { + fn merge(le: le, a: &[T], b: &[T]) -> ~[T] { let mut rs = ~[]; vec::reserve(rs, len(a) + len(b)); let a_len = len(a); @@ -54,7 +57,7 @@ fn merge_sort(le: le, v: ~[const T]) -> ~[T] { } } -fn part(compare_func: le, arr: ~[mut T], left: uint, +fn part(compare_func: le, arr: &[mut T], left: uint, right: uint, pivot: uint) -> uint { let pivot_value = arr[pivot]; arr[pivot] <-> arr[right]; @@ -71,7 +74,7 @@ fn part(compare_func: le, arr: ~[mut T], left: uint, return storage_index; } -fn qsort(compare_func: le, arr: ~[mut T], left: uint, +fn qsort(compare_func: le, arr: &[mut T], left: uint, right: uint) { if right > left { let pivot = (left + right) / 2u; @@ -90,12 +93,12 @@ fn qsort(compare_func: le, arr: ~[mut T], left: uint, * Has worst case O(n^2) performance, average case O(n log n). * This is an unstable sort. */ -fn quick_sort(compare_func: le, arr: ~[mut T]) { +fn quick_sort(compare_func: le, arr: &[mut T]) { if len::(arr) == 0u { return; } qsort::(compare_func, arr, 0u, len::(arr) - 1u); } -fn qsort3(arr: ~[mut T], left: int, right: int) { +fn qsort3(arr: &[mut T], left: int, right: int) { if right <= left { return; } let v: T = arr[right]; let mut i: int = left - 1; @@ -152,14 +155,14 @@ fn qsort3(arr: ~[mut T], left: int, right: int) { * * This is an unstable sort. */ -fn quick_sort3(arr: ~[mut T]) { +fn quick_sort3(arr: &[mut T]) { if arr.len() <= 1 { return; } qsort3(arr, 0, (arr.len() - 1) as int); } #[cfg(test)] mod test_qsort3 { - fn check_sort(v1: ~[mut int], v2: ~[mut int]) { + fn check_sort(v1: &[mut int], v2: &[mut int]) { let len = vec::len::(v1); quick_sort3::(v1); let mut i = 0u; @@ -198,7 +201,7 @@ mod test_qsort3 { #[cfg(test)] mod test_qsort { - fn check_sort(v1: ~[mut int], v2: ~[mut int]) { + fn check_sort(v1: &[mut int], v2: &[mut int]) { let len = vec::len::(v1); pure fn leual(a: &int, b: &int) -> bool { *a <= *b } quick_sort::(leual, v1); @@ -258,7 +261,7 @@ mod test_qsort { #[cfg(test)] mod tests { - fn check_sort(v1: ~[int], v2: ~[int]) { + fn check_sort(v1: &[int], v2: &[int]) { let len = vec::len::(v1); pure fn le(a: &int, b: &int) -> bool { *a <= *b } let f = le;