1
Fork 0

librustc: Remove the broken overloaded assign-ops from the language.

They evaluated the receiver twice. They should be added back with
`AddAssign`, `SubAssign`, etc., traits.
This commit is contained in:
Patrick Walton 2013-06-11 19:13:42 -07:00 committed by Corey Richardson
parent 3fcd4dca30
commit a1531ed946
57 changed files with 316 additions and 209 deletions

View file

@ -1281,9 +1281,9 @@ let your_crayons = ~[BananaMania, Beaver, Bittersweet];
// Add two vectors to create a new one // Add two vectors to create a new one
let our_crayons = my_crayons + your_crayons; let our_crayons = my_crayons + your_crayons;
// += will append to a vector, provided it lives in a mutable slot // .push_all() will append to a vector, provided it lives in a mutable slot
let mut my_crayons = my_crayons; let mut my_crayons = my_crayons;
my_crayons += your_crayons; my_crayons.push_all(your_crayons);
~~~~ ~~~~
> ***Note:*** The above examples of vector addition use owned > ***Note:*** The above examples of vector addition use owned

View file

@ -21,7 +21,7 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
let mut line_num = 1u; let mut line_num = 1u;
while !rdr.eof() { while !rdr.eof() {
let ln = rdr.read_line(); let ln = rdr.read_line();
error_patterns += parse_expected(line_num, ln); error_patterns.push_all_move(parse_expected(line_num, ln));
line_num += 1u; line_num += 1u;
} }
return error_patterns; return error_patterns;

View file

@ -226,8 +226,8 @@ actual:\n\
~"-L", config.build_base.to_str(), ~"-L", config.build_base.to_str(),
~"-L", ~"-L",
aux_output_dir_name(config, testfile).to_str()]; aux_output_dir_name(config, testfile).to_str()];
args += split_maybe_args(&config.rustcflags); args.push_all_move(split_maybe_args(&config.rustcflags));
args += split_maybe_args(&props.compile_flags); args.push_all_move(split_maybe_args(&props.compile_flags));
return ProcArgs {prog: config.rustc_path.to_str(), args: args}; return ProcArgs {prog: config.rustc_path.to_str(), args: args};
} }
} }
@ -581,8 +581,8 @@ fn make_compile_args(config: &config, props: &TestProps, extras: ~[~str],
~"-o", xform(config, testfile).to_str(), ~"-o", xform(config, testfile).to_str(),
~"-L", config.build_base.to_str()] ~"-L", config.build_base.to_str()]
+ extras; + extras;
args += split_maybe_args(&config.rustcflags); args.push_all_move(split_maybe_args(&config.rustcflags));
args += split_maybe_args(&props.compile_flags); args.push_all_move(split_maybe_args(&props.compile_flags));
return ProcArgs {prog: config.rustc_path.to_str(), args: args}; return ProcArgs {prog: config.rustc_path.to_str(), args: args};
} }

View file

@ -186,20 +186,18 @@ impl Arena {
#[inline] #[inline]
fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 { fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
unsafe { unsafe {
// XXX: Borrow check let this = transmute_mut_region(self);
let head = transmute_mut_region(&mut self.pod_head); let start = round_up_to(this.pod_head.fill, align);
let start = round_up_to(head.fill, align);
let end = start + n_bytes; let end = start + n_bytes;
if end > at_vec::capacity(head.data) { if end > at_vec::capacity(this.pod_head.data) {
return self.alloc_pod_grow(n_bytes, align); return this.alloc_pod_grow(n_bytes, align);
} }
head.fill = end; this.pod_head.fill = end;
//debug!("idx = %u, size = %u, align = %u, fill = %u", //debug!("idx = %u, size = %u, align = %u, fill = %u",
// start, n_bytes, align, head.fill); // start, n_bytes, align, head.fill);
ptr::offset(vec::raw::to_ptr(head.data), start) ptr::offset(vec::raw::to_ptr(this.pod_head.data), start)
} }
} }
@ -237,7 +235,7 @@ impl Arena {
let after_tydesc = head.fill + sys::size_of::<*TyDesc>(); let after_tydesc = head.fill + sys::size_of::<*TyDesc>();
let start = round_up_to(after_tydesc, align); let start = round_up_to(after_tydesc, align);
let end = start + n_bytes; let end = start + n_bytes;
if end > at_vec::capacity(head.data) { if end > at_vec::capacity(self.head.data) {
return self.alloc_nonpod_grow(n_bytes, align); return self.alloc_nonpod_grow(n_bytes, align);
} }
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>()); head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>());
@ -245,7 +243,7 @@ impl Arena {
//debug!("idx = %u, size = %u, align = %u, fill = %u", //debug!("idx = %u, size = %u, align = %u, fill = %u",
// start, n_bytes, align, head.fill); // start, n_bytes, align, head.fill);
let buf = vec::raw::to_ptr(head.data); let buf = vec::raw::to_ptr(self.head.data);
return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start)); return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
} }
} }

View file

@ -476,9 +476,15 @@ impl Bitv {
* character is either '0' or '1'. * character is either '0' or '1'.
*/ */
pub fn to_str(&self) -> ~str { pub fn to_str(&self) -> ~str {
let mut rs = ~""; let mut rs = ~"";
for self.each() |i| { if i { rs += "1"; } else { rs += "0"; } }; for self.each() |i| {
rs if i {
rs.push_char('1');
} else {
rs.push_char('0');
}
};
rs
} }

View file

@ -606,33 +606,47 @@ pub mod groups {
let mut row = " ".repeat(4); let mut row = " ".repeat(4);
// short option // short option
row += match short_name.len() { match short_name.len() {
0 => ~"", 0 => {}
1 => ~"-" + short_name + " ", 1 => {
row.push_char('-');
row.push_str(short_name);
row.push_char(' ');
}
_ => fail!("the short name should only be 1 ascii char long"), _ => fail!("the short name should only be 1 ascii char long"),
}; }
// long option // long option
row += match long_name.len() { match long_name.len() {
0 => ~"", 0 => {}
_ => ~"--" + long_name + " ", _ => {
}; row.push_str("--");
row.push_str(long_name);
row.push_char(' ');
}
}
// arg // arg
row += match hasarg { match hasarg {
No => ~"", No => {}
Yes => hint, Yes => row.push_str(hint),
Maybe => ~"[" + hint + "]", Maybe => {
}; row.push_char('[');
row.push_str(hint);
row.push_char(']');
}
}
// FIXME: #5516 // FIXME: #5516
// here we just need to indent the start of the description // here we just need to indent the start of the description
let rowlen = row.len(); let rowlen = row.len();
row += if rowlen < 24 { if rowlen < 24 {
" ".repeat(24 - rowlen) for (24 - rowlen).times {
row.push_char(' ')
}
} else { } else {
copy desc_sep row.push_str(desc_sep)
}; }
// Normalize desc to contain words separated by one space character // Normalize desc to contain words separated by one space character
let mut desc_normalized_whitespace = ~""; let mut desc_normalized_whitespace = ~"";
@ -649,7 +663,7 @@ pub mod groups {
// FIXME: #5516 // FIXME: #5516
// wrapped description // wrapped description
row += desc_rows.connect(desc_sep); row.push_str(desc_rows.connect(desc_sep));
row row
}); });

View file

@ -60,25 +60,27 @@ fn escape_str(s: &str) -> ~str {
let mut escaped = ~"\""; let mut escaped = ~"\"";
for s.iter().advance |c| { for s.iter().advance |c| {
match c { match c {
'"' => escaped += "\\\"", '"' => escaped.push_str("\\\""),
'\\' => escaped += "\\\\", '\\' => escaped.push_str("\\\\"),
'\x08' => escaped += "\\b", '\x08' => escaped.push_str("\\b"),
'\x0c' => escaped += "\\f", '\x0c' => escaped.push_str("\\f"),
'\n' => escaped += "\\n", '\n' => escaped.push_str("\\n"),
'\r' => escaped += "\\r", '\r' => escaped.push_str("\\r"),
'\t' => escaped += "\\t", '\t' => escaped.push_str("\\t"),
_ => escaped += str::from_char(c) _ => escaped.push_char(c),
} }
}; };
escaped += "\""; escaped.push_char('"');
escaped escaped
} }
fn spaces(n: uint) -> ~str { fn spaces(n: uint) -> ~str {
let mut ss = ~""; let mut ss = ~"";
for n.times { ss.push_str(" "); } for n.times {
ss.push_str(" ");
}
return ss; return ss;
} }

View file

@ -119,8 +119,10 @@ pub fn md4_str(msg: &[u8]) -> ~str {
let mut i = 0u32; let mut i = 0u32;
while i < 4u32 { while i < 4u32 {
let byte = (u >> (i * 8u32)) as u8; let byte = (u >> (i * 8u32)) as u8;
if byte <= 16u8 { result += "0"; } if byte <= 16u8 {
result += uint::to_str_radix(byte as uint, 16u); result.push_char('0')
}
result.push_str(uint::to_str_radix(byte as uint, 16u));
i += 1u32; i += 1u32;
} }
} }

View file

@ -93,10 +93,10 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
out.push_char(ch); out.push_char(ch);
} }
_ => out += fmt!("%%%X", ch as uint) _ => out.push_str(fmt!("%%%X", ch as uint))
} }
} else { } else {
out += fmt!("%%%X", ch as uint); out.push_str(fmt!("%%%X", ch as uint));
} }
} }
} }
@ -192,7 +192,7 @@ fn encode_plus(s: &str) -> ~str {
out.push_char(ch); out.push_char(ch);
} }
' ' => out.push_char('+'), ' ' => out.push_char('+'),
_ => out += fmt!("%%%X", ch as uint) _ => out.push_str(fmt!("%%%X", ch as uint))
} }
} }
@ -218,7 +218,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
first = false; first = false;
} }
out += fmt!("%s=%s", key, encode_plus(*value)); out.push_str(fmt!("%s=%s", key, encode_plus(*value)));
} }
} }

View file

@ -510,11 +510,11 @@ impl ToStrRadix for BigUint {
let mut m = n; let mut m = n;
while m > divider { while m > divider {
let (d, m0) = m.div_mod_floor(&divider); let (d, m0) = m.div_mod_floor(&divider);
result += [m0.to_uint() as BigDigit]; result.push(m0.to_uint() as BigDigit);
m = d; m = d;
} }
if !m.is_zero() { if !m.is_zero() {
result += [m.to_uint() as BigDigit]; result.push(m.to_uint() as BigDigit);
} }
return result; return result;
} }

View file

@ -849,7 +849,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
do io::with_str_reader(format) |rdr| { do io::with_str_reader(format) |rdr| {
while !rdr.eof() { while !rdr.eof() {
match rdr.read_char() { match rdr.read_char() {
'%' => buf += parse_type(rdr.read_char(), tm), '%' => buf.push_str(parse_type(rdr.read_char(), tm)),
ch => buf.push_char(ch) ch => buf.push_char(ch)
} }
} }

View file

@ -642,15 +642,15 @@ pub fn sanitize(s: &str) -> ~str {
for s.iter().advance |c| { for s.iter().advance |c| {
match c { match c {
// Escape these with $ sequences // Escape these with $ sequences
'@' => result += "$SP$", '@' => result.push_str("$SP$"),
'~' => result += "$UP$", '~' => result.push_str("$UP$"),
'*' => result += "$RP$", '*' => result.push_str("$RP$"),
'&' => result += "$BP$", '&' => result.push_str("$BP$"),
'<' => result += "$LT$", '<' => result.push_str("$LT$"),
'>' => result += "$GT$", '>' => result.push_str("$GT$"),
'(' => result += "$LP$", '(' => result.push_str("$LP$"),
')' => result += "$RP$", ')' => result.push_str("$RP$"),
',' => result += "$C$", ',' => result.push_str("$C$"),
// '.' doesn't occur in types and functions, so reuse it // '.' doesn't occur in types and functions, so reuse it
// for ':' // for ':'
@ -686,12 +686,14 @@ pub fn mangle(sess: Session, ss: path) -> ~str {
let mut n = ~"_ZN"; // Begin name-sequence. let mut n = ~"_ZN"; // Begin name-sequence.
for ss.iter().advance |s| { for ss.iter().advance |s| {
match *s { path_name(s) | path_mod(s) => { match *s {
let sani = sanitize(sess.str_of(s)); path_name(s) | path_mod(s) => {
n += fmt!("%u%s", sani.len(), sani); let sani = sanitize(sess.str_of(s));
} } n.push_str(fmt!("%u%s", sani.len(), sani));
}
}
} }
n += "E"; // End name-sequence. n.push_char('E'); // End name-sequence.
n n
} }

View file

@ -979,7 +979,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// >:-< // >:-<
let mut impl_path = vec::append(~[], path); let mut impl_path = vec::append(~[], path);
impl_path += [ast_map::path_name(item.ident)]; impl_path.push(ast_map::path_name(item.ident));
for methods.iter().advance |m| { for methods.iter().advance |m| {
index.push(entry {val: m.id, pos: ebml_w.writer.tell()}); index.push(entry {val: m.id, pos: ebml_w.writer.tell()});

View file

@ -261,7 +261,9 @@ fn parse_opt<T>(st: &mut PState, f: &fn(&mut PState) -> T) -> Option<T> {
fn parse_str(st: &mut PState, term: char) -> ~str { fn parse_str(st: &mut PState, term: char) -> ~str {
let mut result = ~""; let mut result = ~"";
while peek(st) != term { while peek(st) != term {
result += str::from_byte(next_byte(st)); unsafe {
str::raw::push_byte(&mut result, next_byte(st));
}
} }
next(st); next(st);
return result; return result;

View file

@ -2091,8 +2091,12 @@ impl Resolver {
let mut first = true; let mut first = true;
let mut result = ~""; let mut result = ~"";
for idents.iter().advance |ident| { for idents.iter().advance |ident| {
if first { first = false; } else { result += "::" }; if first {
result += self.session.str_of(*ident); first = false
} else {
result.push_str("::")
}
result.push_str(*self.session.str_of(*ident));
}; };
return result; return result;
} }

View file

@ -98,15 +98,15 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
if !ia.clobbers.is_empty() && !clobbers.is_empty() { if !ia.clobbers.is_empty() && !clobbers.is_empty() {
clobbers = fmt!("%s,%s", ia.clobbers, clobbers); clobbers = fmt!("%s,%s", ia.clobbers, clobbers);
} else { } else {
clobbers += ia.clobbers; clobbers.push_str(*ia.clobbers);
}; };
// Add the clobbers to our constraints list // Add the clobbers to our constraints list
if !clobbers.is_empty() && !constraints.is_empty() { if clobbers.len() != 0 && constraints.len() != 0 {
constraints += ","; constraints.push_char(',');
constraints += clobbers; constraints.push_str(clobbers);
} else { } else {
constraints += clobbers; constraints.push_str(clobbers);
} }
debug!("Asm Constraints: %?", constraints); debug!("Asm Constraints: %?", constraints);

View file

@ -68,13 +68,13 @@ pub fn count_insn(cx: block, category: &str) {
i = 0u; i = 0u;
while i < len { while i < len {
i = *mm.get(&v[i]); i = *mm.get(&v[i]);
s += "/"; s.push_char('/');
s += v[i]; s.push_str(v[i]);
i += 1u; i += 1u;
} }
s += "/"; s.push_char('/');
s += category; s.push_str(category);
let n = match h.find(&s) { let n = match h.find(&s) {
Some(&n) => n, Some(&n) => n,

View file

@ -964,9 +964,12 @@ pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str {
for p.iter().advance |e| { for p.iter().advance |e| {
match *e { match *e {
ast_map::path_name(s) | ast_map::path_mod(s) => { ast_map::path_name(s) | ast_map::path_mod(s) => {
if first { first = false; } if first {
else { r += "::"; } first = false
r += sess.str_of(s); } else {
r.push_str("::")
}
r.push_str(*sess.str_of(s));
} }
} }
} }

View file

@ -2120,7 +2120,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
TC_NONE, TC_NONE,
|tc, f| tc + tc_mt(cx, f.mt, cache)); |tc, f| tc + tc_mt(cx, f.mt, cache));
if ty::has_dtor(cx, did) { if ty::has_dtor(cx, did) {
res += TC_DTOR; res = res + TC_DTOR;
} }
apply_tc_attr(cx, did, res) apply_tc_attr(cx, did, res)
} }
@ -2205,10 +2205,10 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
fn apply_tc_attr(cx: ctxt, did: def_id, mut tc: TypeContents) -> TypeContents { fn apply_tc_attr(cx: ctxt, did: def_id, mut tc: TypeContents) -> TypeContents {
if has_attr(cx, did, "mutable") { if has_attr(cx, did, "mutable") {
tc += TC_MUTABLE; tc = tc + TC_MUTABLE;
} }
if has_attr(cx, did, "non_sendable") { if has_attr(cx, did, "non_sendable") {
tc += TC_NON_SENDABLE; tc = tc + TC_NON_SENDABLE;
} }
tc tc
} }

View file

@ -213,6 +213,13 @@ impl PurityState {
} }
} }
/// Whether `check_binop` allows overloaded operators to be invoked.
#[deriving(Eq)]
enum AllowOverloadedOperatorsFlag {
AllowOverloadedOperators,
DontAllowOverloadedOperators,
}
pub struct FnCtxt { pub struct FnCtxt {
// Number of errors that had been reported when we started // Number of errors that had been reported when we started
// checking this function. On exit, if we find that *more* errors // checking this function. On exit, if we find that *more* errors
@ -1487,7 +1494,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
lhs: @ast::expr, lhs: @ast::expr,
rhs: @ast::expr, rhs: @ast::expr,
// Used only in the error case // Used only in the error case
expected_result: Option<ty::t> expected_result: Option<ty::t>,
allow_overloaded_operators: AllowOverloadedOperatorsFlag
) { ) {
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
@ -1537,8 +1545,30 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
} }
let result_t = check_user_binop(fcx, callee_id, expr, lhs, lhs_t, op, rhs, // Check for overloaded operators if allowed.
expected_result); let result_t;
if allow_overloaded_operators == AllowOverloadedOperators {
result_t = check_user_binop(fcx,
callee_id,
expr,
lhs,
lhs_t,
op,
rhs,
expected_result);
} else {
fcx.type_error_message(expr.span,
|actual| {
fmt!("binary operation %s cannot be \
applied to type `%s`",
ast_util::binop_to_str(op),
actual)
},
lhs_t,
None);
result_t = ty::mk_err();
}
fcx.write_ty(expr.id, result_t); fcx.write_ty(expr.id, result_t);
if ty::type_is_error(result_t) { if ty::type_is_error(result_t) {
fcx.write_ty(rhs.id, result_t); fcx.write_ty(rhs.id, result_t);
@ -2229,7 +2259,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
fcx.write_ty(id, typ); fcx.write_ty(id, typ);
} }
ast::expr_binary(callee_id, op, lhs, rhs) => { ast::expr_binary(callee_id, op, lhs, rhs) => {
check_binop(fcx, callee_id, expr, op, lhs, rhs, expected); check_binop(fcx,
callee_id,
expr,
op,
lhs,
rhs,
expected,
AllowOverloadedOperators);
let lhs_ty = fcx.expr_ty(lhs); let lhs_ty = fcx.expr_ty(lhs);
let rhs_ty = fcx.expr_ty(rhs); let rhs_ty = fcx.expr_ty(rhs);
if ty::type_is_error(lhs_ty) || if ty::type_is_error(lhs_ty) ||
@ -2242,7 +2280,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
} }
} }
ast::expr_assign_op(callee_id, op, lhs, rhs) => { ast::expr_assign_op(callee_id, op, lhs, rhs) => {
check_binop(fcx, callee_id, expr, op, lhs, rhs, expected); check_binop(fcx,
callee_id,
expr,
op,
lhs,
rhs,
expected,
DontAllowOverloadedOperators);
let lhs_t = fcx.expr_ty(lhs); let lhs_t = fcx.expr_ty(lhs);
let result_t = fcx.expr_ty(expr); let result_t = fcx.expr_ty(expr);
demand::suptype(fcx, expr.span, result_t, lhs_t); demand::suptype(fcx, expr.span, result_t, lhs_t);

View file

@ -192,11 +192,11 @@ pub fn header_name(doc: doc::ItemTag) -> ~str {
let mut trait_part = ~""; let mut trait_part = ~"";
for doc.trait_types.iter().enumerate().advance |(i, trait_type)| { for doc.trait_types.iter().enumerate().advance |(i, trait_type)| {
if i == 0 { if i == 0 {
trait_part += " of "; trait_part.push_str(" of ");
} else { } else {
trait_part += ", "; trait_part.push_str(", ");
} }
trait_part += *trait_type; trait_part.push_str(*trait_type);
} }
fmt!("%s for %s%s", trait_part, *self_ty, bounds) fmt!("%s for %s%s", trait_part, *self_ty, bounds)
} }

View file

@ -130,7 +130,7 @@ fn generic_writer(process: ~fn(markdown: ~str)) -> Writer {
let mut keep_going = true; let mut keep_going = true;
while keep_going { while keep_going {
match po.recv() { match po.recv() {
Write(s) => markdown += s, Write(s) => markdown.push_str(s),
Done => keep_going = false Done => keep_going = false
} }
} }
@ -214,7 +214,7 @@ fn future_writer() -> (Writer, future::Future<~str>) {
let mut res = ~""; let mut res = ~"";
loop { loop {
match port.recv() { match port.recv() {
Write(s) => res += s, Write(s) => res.push_str(s),
Done => break Done => break
} }
} }

View file

@ -70,7 +70,7 @@ fn make_doc_from_pages(page_port: &PagePort) -> doc::Doc {
loop { loop {
let val = page_port.recv(); let val = page_port.recv();
if val.is_some() { if val.is_some() {
pages += [val.unwrap()]; pages.push(val.unwrap());
} else { } else {
break; break;
} }

View file

@ -402,7 +402,8 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
if line.trim() == ":}" { if line.trim() == ":}" {
end_multiline = true; end_multiline = true;
} else { } else {
multiline_cmd += line + "\n"; multiline_cmd.push_str(line);
multiline_cmd.push_char('\n');
} }
} }
} }

View file

@ -24,6 +24,7 @@
use container::Container; use container::Container;
use iterator::IteratorUtil; use iterator::IteratorUtil;
use rt::io::Writer; use rt::io::Writer;
use str::OwnedStr;
use to_bytes::IterBytes; use to_bytes::IterBytes;
use uint; use uint;
use vec::ImmutableVector; use vec::ImmutableVector;
@ -369,7 +370,7 @@ impl Streaming for SipState {
let r = self.result_bytes(); let r = self.result_bytes();
let mut s = ~""; let mut s = ~"";
for r.iter().advance |b| { for r.iter().advance |b| {
s += uint::to_str_radix(*b as uint, 16u); s.push_str(uint::to_str_radix(*b as uint, 16u));
} }
s s
} }
@ -471,7 +472,7 @@ mod tests {
fn to_hex_str(r: &[u8, ..8]) -> ~str { fn to_hex_str(r: &[u8, ..8]) -> ~str {
let mut s = ~""; let mut s = ~"";
for r.iter().advance |b| { for r.iter().advance |b| {
s += uint::to_str_radix(*b as uint, 16u); s.push_str(uint::to_str_radix(*b as uint, 16u));
} }
s s
} }
@ -492,7 +493,7 @@ mod tests {
assert!(f == i && f == v); assert!(f == i && f == v);
buf += [t as u8]; buf.push(t as u8);
stream_inc.input([t as u8]); stream_inc.input([t as u8]);
t += 1; t += 1;

View file

@ -412,7 +412,7 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(radix: uint, pow
if my_pow % 2u == 1u { if my_pow % 2u == 1u {
total = total * multiplier; total = total * multiplier;
} }
my_pow = my_pow / 2u; my_pow = my_pow / 2u;
multiplier = multiplier * multiplier; multiplier = multiplier * multiplier;
} }
total total

View file

@ -21,8 +21,8 @@ use cmp::Eq;
use iterator::IteratorUtil; use iterator::IteratorUtil;
use libc; use libc;
use option::{None, Option, Some}; use option::{None, Option, Some};
use str;
use str::{Str, StrSlice, StrVector}; use str::{Str, StrSlice, StrVector};
use str;
use to_str::ToStr; use to_str::ToStr;
use ascii::{AsciiCast, AsciiStr}; use ascii::{AsciiCast, AsciiStr};
use vec::{OwnedVector, ImmutableVector}; use vec::{OwnedVector, ImmutableVector};
@ -476,7 +476,7 @@ impl ToStr for PosixPath {
fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
let mut s = ~""; let mut s = ~"";
if self.is_absolute { if self.is_absolute {
s += "/"; s.push_str("/");
} }
s + self.components.connect("/") s + self.components.connect("/")
} }
@ -655,15 +655,21 @@ impl ToStr for WindowsPath {
fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
let mut s = ~""; let mut s = ~"";
match self.host { match self.host {
Some(ref h) => { s += "\\\\"; s += *h; } Some(ref h) => {
s.push_str("\\\\");
s.push_str(*h);
}
None => { } None => { }
} }
match self.device { match self.device {
Some(ref d) => { s += *d; s += ":"; } Some(ref d) => {
s.push_str(*d);
s.push_str(":");
}
None => { } None => { }
} }
if self.is_absolute { if self.is_absolute {
s += "\\"; s.push_str("\\");
} }
s + self.components.connect("\\") s + self.components.connect("\\")
} }

View file

@ -263,8 +263,11 @@ fn highlight_lines(cm: @codemap::CodeMap,
let s = fmt!("%s:%u ", fm.name, last_line + 1u); let s = fmt!("%s:%u ", fm.name, last_line + 1u);
let mut indent = s.len(); let mut indent = s.len();
let mut out = ~""; let mut out = ~"";
while indent > 0u { out += " "; indent -= 1u; } while indent > 0u {
out += "...\n"; out.push_char(' ');
indent -= 1u;
}
out.push_str("...\n");
io::stderr().write_str(out); io::stderr().write_str(out);
} }
@ -285,23 +288,29 @@ fn highlight_lines(cm: @codemap::CodeMap,
// part of the 'filename:line ' part of the previous line. // part of the 'filename:line ' part of the previous line.
let skip = fm.name.len() + digits + 3u; let skip = fm.name.len() + digits + 3u;
for skip.times() { for skip.times() {
s += " "; s.push_char(' ');
} }
let orig = fm.get_line(lines.lines[0] as int); let orig = fm.get_line(lines.lines[0] as int);
for uint::range(0u,left-skip) |pos| { for uint::range(0u,left-skip) |pos| {
let curChar = (orig[pos] as char); let curChar = (orig[pos] as char);
s += match curChar { // Whenever a tab occurs on the previous // Whenever a tab occurs on the previous line, we insert one on
'\t' => "\t", // line, we insert one on the error-point- // the error-point-squiggly-line as well (instead of a space).
_ => " " // -squiggly-line as well (instead of a // That way the squiggly line will usually appear in the correct
}; // space). This way the squiggly-line will // position.
} // usually appear in the correct position. match curChar {
'\t' => s.push_char('\t'),
_ => s.push_char(' '),
};
}
io::stderr().write_str(s); io::stderr().write_str(s);
let mut s = ~"^"; let mut s = ~"^";
let hi = cm.lookup_char_pos(sp.hi); let hi = cm.lookup_char_pos(sp.hi);
if hi.col != lo.col { if hi.col != lo.col {
// the ^ already takes up one space // the ^ already takes up one space
let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u; let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u;
for num_squigglies.times() { s += "~"; } for num_squigglies.times() {
s.push_char('~')
}
} }
print_maybe_colored(s + "\n", diagnosticcolor(lvl)); print_maybe_colored(s + "\n", diagnosticcolor(lvl));
} }

View file

@ -26,8 +26,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
} }
} else { } else {
match *e { match *e {
ast::tt_tok(_, token::IDENT(ident,_)) => ast::tt_tok(_, token::IDENT(ident,_)) => res_str.push_str(cx.str_of(ident)),
res_str += cx.str_of(ident),
_ => cx.span_fatal(sp, "concat_idents! requires ident args.") _ => cx.span_fatal(sp, "concat_idents! requires ident args.")
} }
} }

View file

@ -65,8 +65,8 @@ impl gen_send for message {
args_ast); args_ast);
let mut body = ~"{\n"; let mut body = ~"{\n";
body += fmt!("use super::%s;\n", name); body.push_str(fmt!("use super::%s;\n", name));
body += "let mut pipe = pipe;\n"; body.push_str("let mut pipe = pipe;\n");
if this.proto.is_bounded() { if this.proto.is_bounded() {
let (sp, rp) = match (this.dir, next.dir) { let (sp, rp) = match (this.dir, next.dir) {
@ -76,13 +76,15 @@ impl gen_send for message {
(recv, recv) => (~"c", ~"s") (recv, recv) => (~"c", ~"s")
}; };
body += "let mut b = pipe.reuse_buffer();\n"; body.push_str("let mut b = pipe.reuse_buffer();\n");
body += fmt!("let %s = ::std::pipes::SendPacketBuffered(\ body.push_str(fmt!("let %s = ::std::pipes::SendPacketBuffered(\
&mut (b.buffer.data.%s));\n", &mut (b.buffer.data.%s));\n",
sp, next.name); sp,
body += fmt!("let %s = ::std::pipes::RecvPacketBuffered(\ next.name));
&mut (b.buffer.data.%s));\n", body.push_str(fmt!("let %s = ::std::pipes::RecvPacketBuffered(\
rp, next.name); &mut (b.buffer.data.%s));\n",
rp,
next.name));
} }
else { else {
let pat = match (this.dir, next.dir) { let pat = match (this.dir, next.dir) {
@ -92,23 +94,22 @@ impl gen_send for message {
(recv, recv) => "(s, c)" (recv, recv) => "(s, c)"
}; };
body += fmt!("let %s = ::std::pipes::entangle();\n", pat); body.push_str(fmt!("let %s = ::std::pipes::entangle();\n", pat));
} }
body += fmt!("let message = %s(%s);\n", body.push_str(fmt!("let message = %s(%s);\n",
name, name,
vec::append_one( vec::append_one(arg_names.map(|x| cx.str_of(*x)), ~"s")
arg_names.map(|x| cx.str_of(*x)), .connect(", ")));
@"s").connect(", "));
if !try { if !try {
body += fmt!("::std::pipes::send(pipe, message);\n"); body.push_str(fmt!("::std::pipes::send(pipe, message);\n"));
// return the new channel // return the new channel
body += "c }"; body.push_str("c }");
} }
else { else {
body += fmt!("if ::std::pipes::send(pipe, message) {\n \ body.push_str(fmt!("if ::std::pipes::send(pipe, message) {\n \
::std::pipes::rt::make_some(c) \ ::std::pipes::rt::make_some(c) \
} else { ::std::pipes::rt::make_none() } }"); } else { ::std::pipes::rt::make_none() } }"));
} }
let body = cx.parse_expr(body.to_managed()); let body = cx.parse_expr(body.to_managed());
@ -155,19 +156,19 @@ impl gen_send for message {
}; };
let mut body = ~"{ "; let mut body = ~"{ ";
body += fmt!("use super::%s;\n", name); body.push_str(fmt!("use super::%s;\n", name));
body += fmt!("let message = %s%s;\n", name, message_args); body.push_str(fmt!("let message = %s%s;\n", name, message_args));
if !try { if !try {
body += fmt!("::std::pipes::send(pipe, message);\n"); body.push_str(fmt!("::std::pipes::send(pipe, message);\n"));
body += " }"; body.push_str(" }");
} else { } else {
body += fmt!("if ::std::pipes::send(pipe, message) \ body.push_str(fmt!("if ::std::pipes::send(pipe, message) \
{ \ { \
::std::pipes::rt::make_some(()) \ ::std::pipes::rt::make_some(()) \
} else { \ } else { \
::std::pipes::rt::make_none() \ ::std::pipes::rt::make_none() \
} }"); } }"));
} }
let body = cx.parse_expr(body.to_managed()); let body = cx.parse_expr(body.to_managed());
@ -433,10 +434,10 @@ impl gen_init for protocol {
let mut server_states = ~[]; let mut server_states = ~[];
for (copy self.states).iter().advance |s| { for (copy self.states).iter().advance |s| {
items += s.to_type_decls(cx); items.push_all_move(s.to_type_decls(cx));
client_states += s.to_endpoint_decls(cx, send); client_states.push_all_move(s.to_endpoint_decls(cx, send));
server_states += s.to_endpoint_decls(cx, recv); server_states.push_all_move(s.to_endpoint_decls(cx, recv));
} }
if self.is_bounded() { if self.is_bounded() {

View file

@ -42,7 +42,7 @@ impl parser_attr for Parser {
if self.look_ahead(1u) != token::LBRACKET { if self.look_ahead(1u) != token::LBRACKET {
break; break;
} }
attrs += [self.parse_attribute(ast::attr_outer)]; attrs.push(self.parse_attribute(ast::attr_outer));
} }
token::DOC_COMMENT(s) => { token::DOC_COMMENT(s) => {
let attr = ::attr::mk_sugared_doc_attr( let attr = ::attr::mk_sugared_doc_attr(
@ -53,7 +53,7 @@ impl parser_attr for Parser {
if attr.node.style != ast::attr_outer { if attr.node.style != ast::attr_outer {
self.fatal("expected outer comment"); self.fatal("expected outer comment");
} }
attrs += [attr]; attrs.push(attr);
self.bump(); self.bump();
} }
_ => break _ => break
@ -77,9 +77,7 @@ impl parser_attr for Parser {
self.expect(&token::RBRACKET); self.expect(&token::RBRACKET);
let hi = self.span.hi; let hi = self.span.hi;
return spanned(lo, hi, ast::attribute_ { style: style, return spanned(lo, hi, ast::attribute_ { style: style,
value: meta_item, value: meta_item, is_sugared_doc: false }); }
is_sugared_doc: false });
}
// Parse attributes that appear after the opening of an item, each // Parse attributes that appear after the opening of an item, each
// terminated by a semicolon. In addition to a vector of inner attributes, // terminated by a semicolon. In addition to a vector of inner attributes,
@ -105,7 +103,7 @@ impl parser_attr for Parser {
let attr = self.parse_attribute(ast::attr_inner); let attr = self.parse_attribute(ast::attr_inner);
if *self.token == token::SEMI { if *self.token == token::SEMI {
self.bump(); self.bump();
inner_attrs += [attr]; inner_attrs.push(attr);
} else { } else {
// It's not really an inner attribute // It's not really an inner attribute
let outer_attr = let outer_attr =
@ -113,7 +111,7 @@ impl parser_attr for Parser {
ast::attribute_ { style: ast::attr_outer, ast::attribute_ { style: ast::attr_outer,
value: attr.node.value, value: attr.node.value,
is_sugared_doc: false }); is_sugared_doc: false });
next_outer_attrs += [outer_attr]; next_outer_attrs.push(outer_attr);
break; break;
} }
} }
@ -125,9 +123,9 @@ impl parser_attr for Parser {
); );
self.bump(); self.bump();
if attr.node.style == ast::attr_inner { if attr.node.style == ast::attr_inner {
inner_attrs += [attr]; inner_attrs.push(attr);
} else { } else {
next_outer_attrs += [attr]; next_outer_attrs.push(attr);
break; break;
} }
} }

View file

@ -254,7 +254,7 @@ fn read_block_comment(rdr: @mut StringReader,
bump(rdr); bump(rdr);
} }
if !is_eof(rdr) { if !is_eof(rdr) {
curr_line += "*/"; curr_line.push_str("*/");
bump(rdr); bump(rdr);
bump(rdr); bump(rdr);
} }
@ -278,13 +278,13 @@ fn read_block_comment(rdr: @mut StringReader,
if rdr.curr == '/' && nextch(rdr) == '*' { if rdr.curr == '/' && nextch(rdr) == '*' {
bump(rdr); bump(rdr);
bump(rdr); bump(rdr);
curr_line += "*"; curr_line.push_char('*');
level += 1; level += 1;
} else { } else {
if rdr.curr == '*' && nextch(rdr) == '/' { if rdr.curr == '*' && nextch(rdr) == '/' {
bump(rdr); bump(rdr);
bump(rdr); bump(rdr);
curr_line += "/"; curr_line.push_char('/');
level -= 1; level -= 1;
} else { bump(rdr); } } else { bump(rdr); }
} }

View file

@ -192,10 +192,10 @@ impl Parser {
); );
} else { } else {
let mut s: ~str = ~"expected `"; let mut s: ~str = ~"expected `";
s += self.token_to_str(&token::GT); s.push_str(self.token_to_str(&token::GT));
s += "`, found `"; s.push_str("`, found `");
s += self.this_token_to_str(); s.push_str(self.this_token_to_str());
s += "`"; s.push_str("`");
self.fatal(s); self.fatal(s);
} }
} }

View file

@ -180,7 +180,7 @@ pub fn bump(rdr: &mut StringReader) {
let byte_offset_diff = next.next - current_byte_offset; let byte_offset_diff = next.next - current_byte_offset;
rdr.pos = rdr.pos + BytePos(byte_offset_diff); rdr.pos = rdr.pos + BytePos(byte_offset_diff);
rdr.curr = next.ch; rdr.curr = next.ch;
rdr.col += CharPos(1u); rdr.col = rdr.col + CharPos(1u);
if last_char == '\n' { if last_char == '\n' {
rdr.filemap.next_line(rdr.last_pos); rdr.filemap.next_line(rdr.last_pos);
rdr.col = CharPos(0u); rdr.col = CharPos(0u);
@ -448,8 +448,8 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
is_float = true; is_float = true;
bump(rdr); bump(rdr);
let dec_part = scan_digits(rdr, 10u); let dec_part = scan_digits(rdr, 10u);
num_str += "."; num_str.push_char('.');
num_str += dec_part; num_str.push_str(dec_part);
} }
if is_float { if is_float {
match base { match base {
@ -461,7 +461,7 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
match scan_exponent(rdr) { match scan_exponent(rdr) {
Some(ref s) => { Some(ref s) => {
is_float = true; is_float = true;
num_str += (*s); num_str.push_str(*s);
} }
None => () None => ()
} }

View file

@ -4257,8 +4257,12 @@ impl Parser {
// FAILURE TO PARSE ITEM // FAILURE TO PARSE ITEM
if visibility != inherited { if visibility != inherited {
let mut s = ~"unmatched visibility `"; let mut s = ~"unmatched visibility `";
s += if visibility == public { "pub" } else { "priv" }; if visibility == public {
s += "`"; s.push_str("pub")
} else {
s.push_str("priv")
}
s.push_char('`');
self.span_fatal(*self.last_span, s); self.span_fatal(*self.last_span, s);
} }
return iovi_none; return iovi_none;

View file

@ -178,14 +178,14 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
LIT_FLOAT(ref s, t) => { LIT_FLOAT(ref s, t) => {
let mut body = ident_to_str(s).to_owned(); let mut body = ident_to_str(s).to_owned();
if body.ends_with(".") { if body.ends_with(".") {
body += "0"; // `10.f` is not a float literal body.push_char('0'); // `10.f` is not a float literal
} }
body + ast_util::float_ty_to_str(t) body + ast_util::float_ty_to_str(t)
} }
LIT_FLOAT_UNSUFFIXED(ref s) => { LIT_FLOAT_UNSUFFIXED(ref s) => {
let mut body = ident_to_str(s).to_owned(); let mut body = ident_to_str(s).to_owned();
if body.ends_with(".") { if body.ends_with(".") {
body += "0"; // `10.f` is not a float literal body.push_char('0'); // `10.f` is not a float literal
} }
body body
} }

View file

@ -122,12 +122,14 @@ pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint,
let mut s = ~"["; let mut s = ~"[";
while i != right && L != 0u { while i != right && L != 0u {
L -= 1u; L -= 1u;
if i != left { s += ", "; } if i != left {
s += fmt!("%d=%s", szs[i], tok_str(toks[i])); s.push_str(", ");
}
s.push_str(fmt!("%d=%s", szs[i], tok_str(toks[i])));
i += 1u; i += 1u;
i %= n; i %= n;
} }
s += "]"; s.push_char(']');
return s; return s;
} }

View file

@ -87,9 +87,8 @@ fn vec_plus() {
while i < 1500 { while i < 1500 {
let rv = vec::from_elem(r.gen_uint_range(0, i + 1), i); let rv = vec::from_elem(r.gen_uint_range(0, i + 1), i);
if r.gen() { if r.gen() {
v += rv; v.push_all_move(rv);
} } else {
else {
v = rv + v; v = rv + v;
} }
i += 1; i += 1;

View file

@ -50,8 +50,8 @@ fn show_color(cc: color) -> ~str {
fn show_color_list(set: ~[color]) -> ~str { fn show_color_list(set: ~[color]) -> ~str {
let mut out = ~""; let mut out = ~"";
for set.iter().advance |col| { for set.iter().advance |col| {
out += " "; out.push_char(' ');
out += show_color(*col); out.push_str(show_color(*col));
} }
return out; return out;
} }

View file

@ -47,7 +47,7 @@ fn make_cumulative(aa: ~[AminoAcids]) -> ~[AminoAcids] {
let mut ans: ~[AminoAcids] = ~[]; let mut ans: ~[AminoAcids] = ~[];
for aa.iter().advance |a| { for aa.iter().advance |a| {
cp += a.prob; cp += a.prob;
ans += [AminoAcids {ch: a.ch, prob: cp}]; ans.push(AminoAcids {ch: a.ch, prob: cp});
} }
ans ans
} }

View file

@ -70,7 +70,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
let b = str::raw::from_bytes(k); let b = str::raw::from_bytes(k);
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
// to_ascii_consume and to_str_consume to not do a unnecessary copy. // to_ascii_consume and to_str_consume to not do a unnecessary copy.
buffer += (fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v)); buffer.push_str(fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v));
} }
} }

View file

@ -103,7 +103,9 @@ impl Sudoku {
for u8::range(0u8, 9u8) |row| { for u8::range(0u8, 9u8) |row| {
for u8::range(0u8, 9u8) |col| { for u8::range(0u8, 9u8) |col| {
let color = self.grid[row][col]; let color = self.grid[row][col];
if color == 0u8 { work += [(row, col)]; } if color == 0u8 {
work.push((row, col));
}
} }
} }

View file

@ -15,7 +15,7 @@ trait vec_monad<A> {
impl<A> vec_monad<A> for ~[A] { impl<A> vec_monad<A> for ~[A] {
fn bind<B>(&self, f: &fn(A) -> ~[B]) { fn bind<B>(&self, f: &fn(A) -> ~[B]) {
let mut r = fail!(); let mut r = fail!();
for self.iter().advance |elt| { r += f(*elt); } for self.iter().advance |elt| { r = r + f(*elt); }
//~^ WARNING unreachable expression //~^ WARNING unreachable expression
//~^^ ERROR the type of this value must be known //~^^ ERROR the type of this value must be known
} }

View file

@ -10,9 +10,9 @@
// error-pattern:so long // error-pattern:so long
fn main() { fn main() {
let x = ~[]; let mut x = ~[];
let y = ~[3]; let y = ~[3];
fail!("so long"); fail!("so long");
x += y; x.push_all_move(y);
~"good" + ~"bye"; ~"good" + ~"bye";
} }

View file

@ -44,19 +44,19 @@ fn test_heap_add() {
fn test_append() { fn test_append() {
let mut s = ~""; let mut s = ~"";
s += ~"a"; s.push_str(~"a");
assert_eq!(s, ~"a"); assert_eq!(s, ~"a");
let mut s = ~"a"; let mut s = ~"a";
s += ~"b"; s.push_str(~"b");
debug!(s.clone()); debug!(s.clone());
assert_eq!(s, ~"ab"); assert_eq!(s, ~"ab");
let mut s = ~"c"; let mut s = ~"c";
s += ~"offee"; s.push_str(~"offee");
assert!(s == ~"coffee"); assert!(s == ~"coffee");
s += ~"&tea"; s.push_str(~"&tea");
assert!(s == ~"coffee&tea"); assert!(s == ~"coffee&tea");
} }

View file

@ -15,7 +15,7 @@ fn the_loop() {
loop { loop {
let x = 5; let x = 5;
if x > 3 { if x > 3 {
list += ~[take(x)]; list.push(take(x));
} else { } else {
break; break;
} }

View file

@ -23,7 +23,7 @@ fn foo<T>(y: Option<T>) {
None::<T> => x = 17, None::<T> => x = 17,
_ => x = 42 _ => x = 42
} }
rs += ~[x]; rs.push(x);
} }
return; return;
} }

View file

@ -19,7 +19,9 @@ trait vec_monad<A> {
impl<A> vec_monad<A> for ~[A] { impl<A> vec_monad<A> for ~[A] {
fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B] { fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B] {
let mut r = ~[]; let mut r = ~[];
for self.iter().advance |elt| { r += f(elt); } for self.iter().advance |elt| {
r.push_all_move(f(elt));
}
r r
} }
} }

View file

@ -13,7 +13,9 @@ extern mod extra;
use std::vec; use std::vec;
fn grow(v: &mut ~[int]) { *v += ~[1]; } fn grow(v: &mut ~[int]) {
v.push(1);
}
pub fn main() { pub fn main() {
let mut v: ~[int] = ~[]; let mut v: ~[int] = ~[];

View file

@ -57,7 +57,7 @@ impl cmp::Eq for Point {
pub fn main() { pub fn main() {
let mut p = Point {x: 10, y: 20}; let mut p = Point {x: 10, y: 20};
p += Point {x: 101, y: 102}; p = p + Point {x: 101, y: 102};
p = p - Point {x: 100, y: 100}; p = p - Point {x: 100, y: 100};
assert_eq!(p + Point {x: 5, y: 5}, Point {x: 16, y: 27}); assert_eq!(p + Point {x: 5, y: 5}, Point {x: 16, y: 27});
assert_eq!(-p, Point {x: -11, y: -22}); assert_eq!(-p, Point {x: -11, y: -22});

View file

@ -19,7 +19,7 @@ fn foo(c: ~[int]) {
for c.iter().advance |i| { for c.iter().advance |i| {
debug!(a); debug!(a);
let a = 17; let a = 17;
b += ~[a]; b.push(a);
} }
} }
_ => { } _ => { }

View file

@ -51,7 +51,9 @@ impl<T> vec_utils<T> for ~[T] {
fn iter_(&self, f: &fn(&T)) { for self.iter().advance |x| { f(x); } } fn iter_(&self, f: &fn(&T)) { for self.iter().advance |x| { f(x); } }
fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] { fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r = ~[]; let mut r = ~[];
for self.iter().advance |elt| { r += ~[f(elt)]; } for self.iter().advance |elt| {
r.push(f(elt));
}
r r
} }
} }

View file

@ -15,7 +15,7 @@ extern mod extra;
fn test1() { fn test1() {
let mut s: ~str = ~"hello"; let mut s: ~str = ~"hello";
s += ~"world"; s.push_str("world");
debug!(s.clone()); debug!(s.clone());
assert_eq!(s[9], 'd' as u8); assert_eq!(s[9], 'd' as u8);
} }

View file

@ -12,11 +12,11 @@
pub fn main() { pub fn main() {
let mut s = ~"a"; let mut s = ~"a";
s += ~"b"; s.push_char('b');
assert_eq!(s[0], 'a' as u8); assert_eq!(s[0], 'a' as u8);
assert_eq!(s[1], 'b' as u8); assert_eq!(s[1], 'b' as u8);
s += ~"c"; s.push_char('c');
s += ~"d"; s.push_char('d');
assert_eq!(s[0], 'a' as u8); assert_eq!(s[0], 'a' as u8);
assert_eq!(s[1], 'b' as u8); assert_eq!(s[1], 'b' as u8);
assert_eq!(s[2], 'c' as u8); assert_eq!(s[2], 'c' as u8);

View file

@ -33,7 +33,7 @@ impl<T> map<T> for ~[T] {
let mut r = ~[]; let mut r = ~[];
// FIXME: #7355 generates bad code with Iterator // FIXME: #7355 generates bad code with Iterator
for std::uint::range(0, self.len()) |i| { for std::uint::range(0, self.len()) |i| {
r += ~[f(&self[i])]; r.push(f(&self[i]));
} }
r r
} }

View file

@ -12,10 +12,10 @@
pub fn main() { pub fn main() {
let mut v = ~[1]; let mut v = ~[1];
v += ~[2]; v.push(2);
v += ~[3]; v.push(3);
v += ~[4]; v.push(4);
v += ~[5]; v.push(5);
assert_eq!(v[0], 1); assert_eq!(v[0], 1);
assert_eq!(v[1], 2); assert_eq!(v[1], 2);
assert_eq!(v[2], 3); assert_eq!(v[2], 3);

View file

@ -17,7 +17,7 @@ fn make(i: int) -> t {
let mut s = ~"hello"; let mut s = ~"hello";
// Ensure s is non-const. // Ensure s is non-const.
s += ~"there"; s.push_str("there");
return b(s); return b(s);
} }