Skip to content

Commit 30973cc

Browse files
committed
std: allow any sort of string to be Added with +.
1 parent ee25cf8 commit 30973cc

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/librusti/rusti.rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
370370
if arg.ends_with(".rs") || arg.ends_with(".rc") {
371371
(arg.slice_to(arg.len() - 3).to_owned(), copy *arg)
372372
} else {
373-
(copy *arg, arg + ".rs")
373+
(copy *arg, *arg + ".rs")
374374
};
375375
match compile_crate(filename, copy repl.binary) {
376376
Some(_) => loaded_crates.push(crate),

src/libstd/str.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,12 @@ pub mod traits {
913913
use cmp::{TotalOrd, Ordering, Less, Equal, Greater, Eq, Ord, Equiv, TotalEq};
914914
use super::{Str, eq_slice};
915915
916-
impl<'self> Add<&'self str,~str> for ~str {
916+
impl<'self> Add<&'self str,~str> for &'self str {
917917
#[inline(always)]
918918
fn add(&self, rhs: & &'self str) -> ~str {
919-
self.append((*rhs))
919+
let mut ret = self.to_owned();
920+
ret.push_str(*rhs);
921+
ret
920922
}
921923
}
922924
@@ -3137,6 +3139,24 @@ mod tests {
31373139
assert_eq!("abc".char_range_at_reverse(0).next, 0);
31383140
}
31393141
3142+
#[test]
3143+
fn test_add() {
3144+
macro_rules! t (
3145+
($s1:expr, $s2:expr, $e:expr) => {
3146+
assert_eq!($s1 + $s2, $e);
3147+
assert_eq!($s1.to_owned() + $s2, $e);
3148+
assert_eq!($s1.to_managed() + $s2, $e);
3149+
}
3150+
);
3151+
3152+
t!("foo", "bar", ~"foobar");
3153+
t!("foo", @"bar", ~"foobar");
3154+
t!("foo", ~"bar", ~"foobar");
3155+
t!("ศไทย中", "华Việt Nam", ~"ศไทย中华Việt Nam");
3156+
t!("ศไทย中", @"华Việt Nam", ~"ศไทย中华Việt Nam");
3157+
t!("ศไทย中", ~"华Việt Nam", ~"ศไทย中华Việt Nam");
3158+
}
3159+
31403160
#[test]
31413161
fn test_iterator() {
31423162
use iterator::*;

0 commit comments

Comments
 (0)