about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-06-13 19:06:47 -0700
committerBrian Anderson <banderson@mozilla.com>2013-06-13 19:06:47 -0700
commit7755018074a7802e47ae61f69f5e2b5364a12eb8 (patch)
tree0cc0d7770c01720c0b3d470935d68e4caabea945 /src/libstd
parentb417bc8511a0a38e73312cee8086ed04eeb21b75 (diff)
downloadrust-7755018074a7802e47ae61f69f5e2b5364a12eb8.tar.gz
rust-7755018074a7802e47ae61f69f5e2b5364a12eb8.zip
Revert "std: convert {vec,str}::to_owned to methods."
This fixes the strange random crashes in compile-fail tests.

This reverts commit 96cd61ad034cc9e88ab6a7845c3480dbc1ea62f3.

Conflicts:
	src/librustc/driver/driver.rs
	src/libstd/str.rs
	src/libsyntax/ext/quote.rs
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io.rs2
-rw-r--r--src/libstd/path.rs12
-rw-r--r--src/libstd/rand.rs2
-rw-r--r--src/libstd/str.rs30
-rw-r--r--src/libstd/vec.rs16
5 files changed, 32 insertions, 30 deletions
diff --git a/src/libstd/io.rs b/src/libstd/io.rs
index 07e129e3c28..6f065d74fa2 100644
--- a/src/libstd/io.rs
+++ b/src/libstd/io.rs
@@ -761,7 +761,7 @@ impl<T:Reader> ReaderUtil for T {
     fn read_lines(&self) -> ~[~str] {
         do vec::build |push| {
             for self.each_line |line| {
-                push(line.to_owned());
+                push(str::to_owned(line));
             }
         }
     }
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 9c4e8f08358..abe902dec0b 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -515,7 +515,7 @@ impl GenericPath for PosixPath {
     fn with_filestem(&self, s: &str) -> PosixPath {
         match self.filetype() {
             None => self.with_filename(s),
-            Some(ref t) => self.with_filename(s.to_owned() + *t),
+            Some(ref t) => self.with_filename(str::to_owned(s) + *t),
         }
     }
 
@@ -657,7 +657,7 @@ impl GenericPath for WindowsPath {
             (None, None) => {
                 host = None;
                 device = None;
-                rest = s.to_owned();
+                rest = str::to_owned(s);
             }
         }
 
@@ -729,7 +729,7 @@ impl GenericPath for WindowsPath {
     fn with_filestem(&self, s: &str) -> WindowsPath {
         match self.filetype() {
             None => self.with_filename(s),
-            Some(ref t) => self.with_filename(s.to_owned() + *t),
+            Some(ref t) => self.with_filename(str::to_owned(s) + *t),
         }
     }
 
@@ -983,7 +983,7 @@ mod tests {
     fn test_posix_paths() {
         fn t(wp: &PosixPath, s: &str) {
             let ss = wp.to_str();
-            let sss = s.to_owned();
+            let sss = str::to_owned(s);
             if (ss != sss) {
                 debug!("got %s", ss);
                 debug!("expected %s", sss);
@@ -1041,7 +1041,7 @@ mod tests {
     fn test_normalize() {
         fn t(wp: &PosixPath, s: &str) {
             let ss = wp.to_str();
-            let sss = s.to_owned();
+            let sss = str::to_owned(s);
             if (ss != sss) {
                 debug!("got %s", ss);
                 debug!("expected %s", sss);
@@ -1104,7 +1104,7 @@ mod tests {
     fn test_windows_paths() {
         fn t(wp: &WindowsPath, s: &str) {
             let ss = wp.to_str();
-            let sss = s.to_owned();
+            let sss = str::to_owned(s);
             if (ss != sss) {
                 debug!("got %s", ss);
                 debug!("expected %s", sss);
diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs
index f7850205930..7946f7e4f13 100644
--- a/src/libstd/rand.rs
+++ b/src/libstd/rand.rs
@@ -577,7 +577,7 @@ impl<R: Rng> RngUtil for R {
 
     /// Shuffle a vec
     fn shuffle<T:Copy>(&mut self, values: &[T]) -> ~[T] {
-        let mut m = values.to_owned();
+        let mut m = vec::to_owned(values);
         self.shuffle_mut(m);
         m
     }
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 164c57d9645..1086fcaa75c 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -107,17 +107,23 @@ pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
     }
 }
 
+/// Copy a slice into a new unique str
+#[inline(always)]
+pub fn to_owned(s: &str) -> ~str {
+    unsafe { raw::slice_bytes_owned(s, 0, s.len()) }
+}
+
 impl ToStr for ~str {
     #[inline(always)]
-    fn to_str(&self) -> ~str { self.to_owned() }
+    fn to_str(&self) -> ~str { to_owned(*self) }
 }
 impl<'self> ToStr for &'self str {
     #[inline(always)]
-    fn to_str(&self) -> ~str { self.to_owned() }
+    fn to_str(&self) -> ~str { to_owned(*self) }
 }
 impl ToStr for @str {
     #[inline(always)]
-    fn to_str(&self) -> ~str { self.to_owned() }
+    fn to_str(&self) -> ~str { to_owned(*self) }
 }
 
 /**
@@ -950,7 +956,7 @@ impl<'self> StrUtil for &'self str {
             // NB: len includes the trailing null.
             assert!(len > 0);
             if unsafe { *(ptr::offset(buf,len-1)) != 0 } {
-                self.to_owned().as_c_str(f)
+                to_owned(self).as_c_str(f)
             } else {
                 f(buf as *libc::c_char)
             }
@@ -1204,9 +1210,7 @@ pub mod traits {
     impl<'self> Add<&'self str,~str> for ~str {
         #[inline(always)]
         fn add(&self, rhs: & &'self str) -> ~str {
-            let mut s = self.to_owned();
-            s.push_str(*rhs);
-            s
+            self.append((*rhs))
         }
     }
 }
@@ -1665,11 +1669,8 @@ impl<'self> StrSlice<'self> for &'self str {
 
     /// Copy a slice into a new unique str
     #[inline]
-    fn to_owned(&self) -> ~str {
-        unsafe { raw::slice_bytes_owned(*self, 0, self.len()) }
-    }
+    fn to_owned(&self) -> ~str { to_owned(*self) }
 
-    /// Copy a slice into a new @str
     #[inline]
     fn to_managed(&self) -> @str {
         let v = at_vec::from_fn(self.len() + 1, |i| {
@@ -2180,7 +2181,7 @@ impl OwnedStr for ~str {
 impl Clone for ~str {
     #[inline(always)]
     fn clone(&self) -> ~str {
-        self.to_owned()
+        to_owned(*self)
     }
 }
 
@@ -3172,11 +3173,6 @@ mod tests {
         assert_eq!("abc".to_managed(), @"abc");
         assert_eq!("abcdef".slice(1, 5).to_managed(), @"bcde");
     }
-    #[test]
-    fn test_to_owned() {
-        assert_eq!("abc".to_owned(), ~"abc");
-        assert_eq!("abcdef".slice(1, 5).to_owned(), ~"bcde");
-    }
 
     #[test]
     fn test_total_ord() {
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 52cb20458ea..19233c53348 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -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]]);
     }