]> git.lizzy.rs Git - rust.git/commitdiff
std: allow any sort of string to be Added with +.
authorHuon Wilson <dbau.pp+github@gmail.com>
Sat, 15 Jun 2013 13:17:53 +0000 (23:17 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Sun, 16 Jun 2013 00:50:28 +0000 (10:50 +1000)
src/librusti/rusti.rc
src/libstd/str.rs

index 06ec6769385c267a3f90666a730a7848c6cbb2d3..0af6ed724e1dafeb66edfb3b3ec24244ecfb42a2 100644 (file)
@@ -370,7 +370,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
                     if arg.ends_with(".rs") || arg.ends_with(".rc") {
                     (arg.slice_to(arg.len() - 3).to_owned(), copy *arg)
                 } else {
-                    (copy *arg, arg + ".rs")
+                    (copy *arg, *arg + ".rs")
                 };
                 match compile_crate(filename, copy repl.binary) {
                     Some(_) => loaded_crates.push(crate),
index 1ab07003b6ea440df37a0c63f0997b450d0a904b..21f747317f4a5f1e5ce9a823b5dd24aed31d8a11 100644 (file)
@@ -913,10 +913,12 @@ pub mod traits {
     use cmp::{TotalOrd, Ordering, Less, Equal, Greater, Eq, Ord, Equiv, TotalEq};
     use super::{Str, eq_slice};
 
-    impl<'self> Add<&'self str,~str> for ~str {
+    impl<'self> Add<&'self str,~str> for &'self str {
         #[inline(always)]
         fn add(&self, rhs: & &'self str) -> ~str {
-            self.append((*rhs))
+            let mut ret = self.to_owned();
+            ret.push_str(*rhs);
+            ret
         }
     }
 
@@ -3137,6 +3139,24 @@ fn test_char_range_at_reverse_underflow() {
         assert_eq!("abc".char_range_at_reverse(0).next, 0);
     }
 
+    #[test]
+    fn test_add() {
+        macro_rules! t (
+            ($s1:expr, $s2:expr, $e:expr) => {
+                assert_eq!($s1 + $s2, $e);
+                assert_eq!($s1.to_owned() + $s2, $e);
+                assert_eq!($s1.to_managed() + $s2, $e);
+            }
+        );
+
+        t!("foo",  "bar", ~"foobar");
+        t!("foo", @"bar", ~"foobar");
+        t!("foo", ~"bar", ~"foobar");
+        t!("ศไทย中",  "华Việt Nam", ~"ศไทย中华Việt Nam");
+        t!("ศไทย中", @"华Việt Nam", ~"ศไทย中华Việt Nam");
+        t!("ศไทย中", ~"华Việt Nam", ~"ศไทย中华Việt Nam");
+    }
+
     #[test]
     fn test_iterator() {
         use iterator::*;