Revert "std: convert {vec,str}::to_owned to methods."

This fixes the strange random crashes in compile-fail tests.

This reverts commit 96cd61ad03.

Conflicts:
	src/librustc/driver/driver.rs
	src/libstd/str.rs
	src/libsyntax/ext/quote.rs
This commit is contained in:
Brian Anderson
2013-06-13 19:06:47 -07:00
parent b417bc8511
commit 7755018074
30 changed files with 104 additions and 90 deletions

View File

@@ -171,6 +171,11 @@ pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> ~[T] {
}
}
/// Creates a new unique vector with the same contents as the slice
pub fn to_owned<T:Copy>(t: &[T]) -> ~[T] {
from_fn(t.len(), |i| t[i])
}
/// Creates a new vector with a capacity of `capacity`
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
let mut vec = ~[];
@@ -1782,7 +1787,7 @@ pub trait CopyableVector<T> {
/// Extension methods for vectors
impl<'self,T:Copy> CopyableVector<T> for &'self [T] {
/// Creates a new unique vector with the same contents as the slice
/// Returns a copy of `v`.
#[inline]
fn to_owned(&self) -> ~[T] {
let mut result = ~[];
@@ -1791,6 +1796,7 @@ impl<'self,T:Copy> CopyableVector<T> for &'self [T] {
result.push(copy *e);
}
result
}
}
@@ -3355,19 +3361,19 @@ mod tests {
let mut results: ~[~[int]];
results = ~[];
for each_permutation([]) |v| { results.push(v.to_owned()); }
for each_permutation([]) |v| { results.push(to_owned(v)); }
assert_eq!(results, ~[~[]]);
results = ~[];
for each_permutation([7]) |v| { results.push(v.to_owned()); }
for each_permutation([7]) |v| { results.push(to_owned(v)); }
assert_eq!(results, ~[~[7]]);
results = ~[];
for each_permutation([1,1]) |v| { results.push(v.to_owned()); }
for each_permutation([1,1]) |v| { results.push(to_owned(v)); }
assert_eq!(results, ~[~[1,1],~[1,1]]);
results = ~[];
for each_permutation([5,2,0]) |v| { results.push(v.to_owned()); }
for each_permutation([5,2,0]) |v| { results.push(to_owned(v)); }
assert!(results ==
~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]);
}