// Add two vectors to create a new one
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;
-my_crayons += your_crayons;
+my_crayons.push_all(your_crayons);
~~~~
> ***Note:*** The above examples of vector addition use owned
let mut line_num = 1u;
while !rdr.eof() {
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;
}
return error_patterns;
~"-L", config.build_base.to_str(),
~"-L",
aux_output_dir_name(config, testfile).to_str()];
- args += split_maybe_args(&config.rustcflags);
- args += split_maybe_args(&props.compile_flags);
+ args.push_all_move(split_maybe_args(&config.rustcflags));
+ args.push_all_move(split_maybe_args(&props.compile_flags));
return ProcArgs {prog: config.rustc_path.to_str(), args: args};
}
}
~"-o", xform(config, testfile).to_str(),
~"-L", config.build_base.to_str()]
+ extras;
- args += split_maybe_args(&config.rustcflags);
- args += split_maybe_args(&props.compile_flags);
+ args.push_all_move(split_maybe_args(&config.rustcflags));
+ args.push_all_move(split_maybe_args(&props.compile_flags));
return ProcArgs {prog: config.rustc_path.to_str(), args: args};
}
#[inline]
fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
unsafe {
- // XXX: Borrow check
- let head = transmute_mut_region(&mut self.pod_head);
-
- let start = round_up_to(head.fill, align);
+ let this = transmute_mut_region(self);
+ let start = round_up_to(this.pod_head.fill, align);
let end = start + n_bytes;
- if end > at_vec::capacity(head.data) {
- return self.alloc_pod_grow(n_bytes, align);
+ if end > at_vec::capacity(this.pod_head.data) {
+ 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",
// 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)
}
}
let after_tydesc = head.fill + sys::size_of::<*TyDesc>();
let start = round_up_to(after_tydesc, align);
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);
}
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>());
//debug!("idx = %u, size = %u, align = %u, fill = %u",
// 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));
}
}
* character is either '0' or '1'.
*/
pub fn to_str(&self) -> ~str {
- let mut rs = ~"";
- for self.each() |i| { if i { rs += "1"; } else { rs += "0"; } };
- rs
+ let mut rs = ~"";
+ for self.each() |i| {
+ if i {
+ rs.push_char('1');
+ } else {
+ rs.push_char('0');
+ }
+ };
+ rs
}
let mut row = " ".repeat(4);
// short option
- row += match short_name.len() {
- 0 => ~"",
- 1 => ~"-" + short_name + " ",
+ match short_name.len() {
+ 0 => {}
+ 1 => {
+ row.push_char('-');
+ row.push_str(short_name);
+ row.push_char(' ');
+ }
_ => fail!("the short name should only be 1 ascii char long"),
- };
+ }
// long option
- row += match long_name.len() {
- 0 => ~"",
- _ => ~"--" + long_name + " ",
- };
+ match long_name.len() {
+ 0 => {}
+ _ => {
+ row.push_str("--");
+ row.push_str(long_name);
+ row.push_char(' ');
+ }
+ }
// arg
- row += match hasarg {
- No => ~"",
- Yes => hint,
- Maybe => ~"[" + hint + "]",
- };
+ match hasarg {
+ No => {}
+ Yes => row.push_str(hint),
+ Maybe => {
+ row.push_char('[');
+ row.push_str(hint);
+ row.push_char(']');
+ }
+ }
// FIXME: #5516
// here we just need to indent the start of the description
let rowlen = row.len();
- row += if rowlen < 24 {
- " ".repeat(24 - rowlen)
+ if rowlen < 24 {
+ for (24 - rowlen).times {
+ row.push_char(' ')
+ }
} else {
- copy desc_sep
- };
+ row.push_str(desc_sep)
+ }
// Normalize desc to contain words separated by one space character
let mut desc_normalized_whitespace = ~"";
// FIXME: #5516
// wrapped description
- row += desc_rows.connect(desc_sep);
+ row.push_str(desc_rows.connect(desc_sep));
row
});
let mut escaped = ~"\"";
for s.iter().advance |c| {
match c {
- '"' => escaped += "\\\"",
- '\\' => escaped += "\\\\",
- '\x08' => escaped += "\\b",
- '\x0c' => escaped += "\\f",
- '\n' => escaped += "\\n",
- '\r' => escaped += "\\r",
- '\t' => escaped += "\\t",
- _ => escaped += str::from_char(c)
+ '"' => escaped.push_str("\\\""),
+ '\\' => escaped.push_str("\\\\"),
+ '\x08' => escaped.push_str("\\b"),
+ '\x0c' => escaped.push_str("\\f"),
+ '\n' => escaped.push_str("\\n"),
+ '\r' => escaped.push_str("\\r"),
+ '\t' => escaped.push_str("\\t"),
+ _ => escaped.push_char(c),
}
};
- escaped += "\"";
+ escaped.push_char('"');
escaped
}
fn spaces(n: uint) -> ~str {
let mut ss = ~"";
- for n.times { ss.push_str(" "); }
+ for n.times {
+ ss.push_str(" ");
+ }
return ss;
}
let mut i = 0u32;
while i < 4u32 {
let byte = (u >> (i * 8u32)) as u8;
- if byte <= 16u8 { result += "0"; }
- result += uint::to_str_radix(byte as uint, 16u);
+ if byte <= 16u8 {
+ result.push_char('0')
+ }
+ result.push_str(uint::to_str_radix(byte as uint, 16u));
i += 1u32;
}
}
out.push_char(ch);
}
- _ => out += fmt!("%%%X", ch as uint)
+ _ => out.push_str(fmt!("%%%X", ch as uint))
}
} else {
- out += fmt!("%%%X", ch as uint);
+ out.push_str(fmt!("%%%X", ch as uint));
}
}
}
out.push_char(ch);
}
' ' => out.push_char('+'),
- _ => out += fmt!("%%%X", ch as uint)
+ _ => out.push_str(fmt!("%%%X", ch as uint))
}
}
first = false;
}
- out += fmt!("%s=%s", key, encode_plus(*value));
+ out.push_str(fmt!("%s=%s", key, encode_plus(*value)));
}
}
let mut m = n;
while m > divider {
let (d, m0) = m.div_mod_floor(÷r);
- result += [m0.to_uint() as BigDigit];
+ result.push(m0.to_uint() as BigDigit);
m = d;
}
if !m.is_zero() {
- result += [m.to_uint() as BigDigit];
+ result.push(m.to_uint() as BigDigit);
}
return result;
}
do io::with_str_reader(format) |rdr| {
while !rdr.eof() {
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)
}
}
for s.iter().advance |c| {
match c {
// Escape these with $ sequences
- '@' => result += "$SP$",
- '~' => result += "$UP$",
- '*' => result += "$RP$",
- '&' => result += "$BP$",
- '<' => result += "$LT$",
- '>' => result += "$GT$",
- '(' => result += "$LP$",
- ')' => result += "$RP$",
- ',' => result += "$C$",
+ '@' => result.push_str("$SP$"),
+ '~' => result.push_str("$UP$"),
+ '*' => result.push_str("$RP$"),
+ '&' => result.push_str("$BP$"),
+ '<' => result.push_str("$LT$"),
+ '>' => result.push_str("$GT$"),
+ '(' => result.push_str("$LP$"),
+ ')' => result.push_str("$RP$"),
+ ',' => result.push_str("$C$"),
// '.' doesn't occur in types and functions, so reuse it
// for ':'
let mut n = ~"_ZN"; // Begin name-sequence.
for ss.iter().advance |s| {
- match *s { path_name(s) | path_mod(s) => {
- let sani = sanitize(sess.str_of(s));
- n += fmt!("%u%s", sani.len(), sani);
- } }
+ match *s {
+ path_name(s) | path_mod(s) => {
+ 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
}
// >:-<
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| {
index.push(entry {val: m.id, pos: ebml_w.writer.tell()});
fn parse_str(st: &mut PState, term: char) -> ~str {
let mut result = ~"";
while peek(st) != term {
- result += str::from_byte(next_byte(st));
+ unsafe {
+ str::raw::push_byte(&mut result, next_byte(st));
+ }
}
next(st);
return result;
let mut first = true;
let mut result = ~"";
for idents.iter().advance |ident| {
- if first { first = false; } else { result += "::" };
- result += self.session.str_of(*ident);
+ if first {
+ first = false
+ } else {
+ result.push_str("::")
+ }
+ result.push_str(*self.session.str_of(*ident));
};
return result;
}
if !ia.clobbers.is_empty() && !clobbers.is_empty() {
clobbers = fmt!("%s,%s", ia.clobbers, clobbers);
} else {
- clobbers += ia.clobbers;
+ clobbers.push_str(*ia.clobbers);
};
// Add the clobbers to our constraints list
- if !clobbers.is_empty() && !constraints.is_empty() {
- constraints += ",";
- constraints += clobbers;
+ if clobbers.len() != 0 && constraints.len() != 0 {
+ constraints.push_char(',');
+ constraints.push_str(clobbers);
} else {
- constraints += clobbers;
+ constraints.push_str(clobbers);
}
debug!("Asm Constraints: %?", constraints);
i = 0u;
while i < len {
i = *mm.get(&v[i]);
- s += "/";
- s += v[i];
+ s.push_char('/');
+ s.push_str(v[i]);
i += 1u;
}
- s += "/";
- s += category;
+ s.push_char('/');
+ s.push_str(category);
let n = match h.find(&s) {
Some(&n) => n,
for p.iter().advance |e| {
match *e {
ast_map::path_name(s) | ast_map::path_mod(s) => {
- if first { first = false; }
- else { r += "::"; }
- r += sess.str_of(s);
+ if first {
+ first = false
+ } else {
+ r.push_str("::")
+ }
+ r.push_str(*sess.str_of(s));
}
}
}
TC_NONE,
|tc, f| tc + tc_mt(cx, f.mt, cache));
if ty::has_dtor(cx, did) {
- res += TC_DTOR;
+ res = res + TC_DTOR;
}
apply_tc_attr(cx, did, res)
}
fn apply_tc_attr(cx: ctxt, did: def_id, mut tc: TypeContents) -> TypeContents {
if has_attr(cx, did, "mutable") {
- tc += TC_MUTABLE;
+ tc = tc + TC_MUTABLE;
}
if has_attr(cx, did, "non_sendable") {
- tc += TC_NON_SENDABLE;
+ tc = tc + TC_NON_SENDABLE;
}
tc
}
}
}
+/// Whether `check_binop` allows overloaded operators to be invoked.
+#[deriving(Eq)]
+enum AllowOverloadedOperatorsFlag {
+ AllowOverloadedOperators,
+ DontAllowOverloadedOperators,
+}
+
pub struct FnCtxt {
// Number of errors that had been reported when we started
// checking this function. On exit, if we find that *more* errors
lhs: @ast::expr,
rhs: @ast::expr,
// 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 result_t = check_user_binop(fcx, callee_id, expr, lhs, lhs_t, op, rhs,
- expected_result);
+ // Check for overloaded operators if allowed.
+ 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);
if ty::type_is_error(result_t) {
fcx.write_ty(rhs.id, result_t);
fcx.write_ty(id, typ);
}
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 rhs_ty = fcx.expr_ty(rhs);
if ty::type_is_error(lhs_ty) ||
}
}
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 result_t = fcx.expr_ty(expr);
demand::suptype(fcx, expr.span, result_t, lhs_t);
let mut trait_part = ~"";
for doc.trait_types.iter().enumerate().advance |(i, trait_type)| {
if i == 0 {
- trait_part += " of ";
+ trait_part.push_str(" of ");
} 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)
}
let mut keep_going = true;
while keep_going {
match po.recv() {
- Write(s) => markdown += s,
+ Write(s) => markdown.push_str(s),
Done => keep_going = false
}
}
let mut res = ~"";
loop {
match port.recv() {
- Write(s) => res += s,
+ Write(s) => res.push_str(s),
Done => break
}
}
loop {
let val = page_port.recv();
if val.is_some() {
- pages += [val.unwrap()];
+ pages.push(val.unwrap());
} else {
break;
}
if line.trim() == ":}" {
end_multiline = true;
} else {
- multiline_cmd += line + "\n";
+ multiline_cmd.push_str(line);
+ multiline_cmd.push_char('\n');
}
}
}
use container::Container;
use iterator::IteratorUtil;
use rt::io::Writer;
+use str::OwnedStr;
use to_bytes::IterBytes;
use uint;
use vec::ImmutableVector;
let r = self.result_bytes();
let mut s = ~"";
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
}
fn to_hex_str(r: &[u8, ..8]) -> ~str {
let mut s = ~"";
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
}
assert!(f == i && f == v);
- buf += [t as u8];
+ buf.push(t as u8);
stream_inc.input([t as u8]);
t += 1;
if my_pow % 2u == 1u {
total = total * multiplier;
}
- my_pow = my_pow / 2u;
+ my_pow = my_pow / 2u;
multiplier = multiplier * multiplier;
}
total
use iterator::IteratorUtil;
use libc;
use option::{None, Option, Some};
-use str;
use str::{Str, StrSlice, StrVector};
+use str;
use to_str::ToStr;
use ascii::{AsciiCast, AsciiStr};
use vec::{OwnedVector, ImmutableVector};
fn to_str(&self) -> ~str {
let mut s = ~"";
if self.is_absolute {
- s += "/";
+ s.push_str("/");
}
s + self.components.connect("/")
}
fn to_str(&self) -> ~str {
let mut s = ~"";
match self.host {
- Some(ref h) => { s += "\\\\"; s += *h; }
+ Some(ref h) => {
+ s.push_str("\\\\");
+ s.push_str(*h);
+ }
None => { }
}
match self.device {
- Some(ref d) => { s += *d; s += ":"; }
+ Some(ref d) => {
+ s.push_str(*d);
+ s.push_str(":");
+ }
None => { }
}
if self.is_absolute {
- s += "\\";
+ s.push_str("\\");
}
s + self.components.connect("\\")
}
let s = fmt!("%s:%u ", fm.name, last_line + 1u);
let mut indent = s.len();
let mut out = ~"";
- while indent > 0u { out += " "; indent -= 1u; }
- out += "...\n";
+ while indent > 0u {
+ out.push_char(' ');
+ indent -= 1u;
+ }
+ out.push_str("...\n");
io::stderr().write_str(out);
}
// part of the 'filename:line ' part of the previous line.
let skip = fm.name.len() + digits + 3u;
for skip.times() {
- s += " ";
+ s.push_char(' ');
}
let orig = fm.get_line(lines.lines[0] as int);
for uint::range(0u,left-skip) |pos| {
let curChar = (orig[pos] as char);
- s += match curChar { // Whenever a tab occurs on the previous
- '\t' => "\t", // line, we insert one on the error-point-
- _ => " " // -squiggly-line as well (instead of a
- }; // space). This way the squiggly-line will
- } // usually appear in the correct position.
+ // Whenever a tab occurs on the previous line, we insert one on
+ // the error-point-squiggly-line as well (instead of a space).
+ // That way the squiggly line will usually appear in the correct
+ // position.
+ match curChar {
+ '\t' => s.push_char('\t'),
+ _ => s.push_char(' '),
+ };
+ }
io::stderr().write_str(s);
let mut s = ~"^";
let hi = cm.lookup_char_pos(sp.hi);
if hi.col != lo.col {
// the ^ already takes up one space
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));
}
}
} else {
match *e {
- ast::tt_tok(_, token::IDENT(ident,_)) =>
- res_str += cx.str_of(ident),
+ ast::tt_tok(_, token::IDENT(ident,_)) => res_str.push_str(cx.str_of(ident)),
_ => cx.span_fatal(sp, "concat_idents! requires ident args.")
}
}
args_ast);
let mut body = ~"{\n";
- body += fmt!("use super::%s;\n", name);
- body += "let mut pipe = pipe;\n";
+ body.push_str(fmt!("use super::%s;\n", name));
+ body.push_str("let mut pipe = pipe;\n");
if this.proto.is_bounded() {
let (sp, rp) = match (this.dir, next.dir) {
(recv, recv) => (~"c", ~"s")
};
- body += "let mut b = pipe.reuse_buffer();\n";
- body += fmt!("let %s = ::std::pipes::SendPacketBuffered(\
- &mut (b.buffer.data.%s));\n",
- sp, next.name);
- body += fmt!("let %s = ::std::pipes::RecvPacketBuffered(\
- &mut (b.buffer.data.%s));\n",
- rp, next.name);
+ body.push_str("let mut b = pipe.reuse_buffer();\n");
+ body.push_str(fmt!("let %s = ::std::pipes::SendPacketBuffered(\
+ &mut (b.buffer.data.%s));\n",
+ sp,
+ next.name));
+ body.push_str(fmt!("let %s = ::std::pipes::RecvPacketBuffered(\
+ &mut (b.buffer.data.%s));\n",
+ rp,
+ next.name));
}
else {
let pat = match (this.dir, next.dir) {
(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",
- name,
- vec::append_one(
- arg_names.map(|x| cx.str_of(*x)),
- @"s").connect(", "));
+ body.push_str(fmt!("let message = %s(%s);\n",
+ name,
+ vec::append_one(arg_names.map(|x| cx.str_of(*x)), ~"s")
+ .connect(", ")));
if !try {
- body += fmt!("::std::pipes::send(pipe, message);\n");
+ body.push_str(fmt!("::std::pipes::send(pipe, message);\n"));
// return the new channel
- body += "c }";
+ body.push_str("c }");
}
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) \
- } else { ::std::pipes::rt::make_none() } }");
+ } else { ::std::pipes::rt::make_none() } }"));
}
let body = cx.parse_expr(body.to_managed());
};
let mut body = ~"{ ";
- body += fmt!("use super::%s;\n", name);
- body += fmt!("let message = %s%s;\n", name, message_args);
+ body.push_str(fmt!("use super::%s;\n", name));
+ body.push_str(fmt!("let message = %s%s;\n", name, message_args));
if !try {
- body += fmt!("::std::pipes::send(pipe, message);\n");
- body += " }";
+ body.push_str(fmt!("::std::pipes::send(pipe, message);\n"));
+ body.push_str(" }");
} else {
- body += fmt!("if ::std::pipes::send(pipe, message) \
+ body.push_str(fmt!("if ::std::pipes::send(pipe, message) \
{ \
::std::pipes::rt::make_some(()) \
} else { \
::std::pipes::rt::make_none() \
- } }");
+ } }"));
}
let body = cx.parse_expr(body.to_managed());
let mut server_states = ~[];
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);
- server_states += s.to_endpoint_decls(cx, recv);
+ client_states.push_all_move(s.to_endpoint_decls(cx, send));
+ server_states.push_all_move(s.to_endpoint_decls(cx, recv));
}
if self.is_bounded() {
if self.look_ahead(1u) != token::LBRACKET {
break;
}
- attrs += [self.parse_attribute(ast::attr_outer)];
+ attrs.push(self.parse_attribute(ast::attr_outer));
}
token::DOC_COMMENT(s) => {
let attr = ::attr::mk_sugared_doc_attr(
if attr.node.style != ast::attr_outer {
self.fatal("expected outer comment");
}
- attrs += [attr];
+ attrs.push(attr);
self.bump();
}
_ => break
self.expect(&token::RBRACKET);
let hi = self.span.hi;
return spanned(lo, hi, ast::attribute_ { style: style,
- value: meta_item,
- is_sugared_doc: false });
- }
+ value: meta_item, is_sugared_doc: false }); }
// Parse attributes that appear after the opening of an item, each
// terminated by a semicolon. In addition to a vector of inner attributes,
let attr = self.parse_attribute(ast::attr_inner);
if *self.token == token::SEMI {
self.bump();
- inner_attrs += [attr];
+ inner_attrs.push(attr);
} else {
// It's not really an inner attribute
let outer_attr =
ast::attribute_ { style: ast::attr_outer,
value: attr.node.value,
is_sugared_doc: false });
- next_outer_attrs += [outer_attr];
+ next_outer_attrs.push(outer_attr);
break;
}
}
);
self.bump();
if attr.node.style == ast::attr_inner {
- inner_attrs += [attr];
+ inner_attrs.push(attr);
} else {
- next_outer_attrs += [attr];
+ next_outer_attrs.push(attr);
break;
}
}
bump(rdr);
}
if !is_eof(rdr) {
- curr_line += "*/";
+ curr_line.push_str("*/");
bump(rdr);
bump(rdr);
}
if rdr.curr == '/' && nextch(rdr) == '*' {
bump(rdr);
bump(rdr);
- curr_line += "*";
+ curr_line.push_char('*');
level += 1;
} else {
if rdr.curr == '*' && nextch(rdr) == '/' {
bump(rdr);
bump(rdr);
- curr_line += "/";
+ curr_line.push_char('/');
level -= 1;
} else { bump(rdr); }
}
);
} else {
let mut s: ~str = ~"expected `";
- s += self.token_to_str(&token::GT);
- s += "`, found `";
- s += self.this_token_to_str();
- s += "`";
+ s.push_str(self.token_to_str(&token::GT));
+ s.push_str("`, found `");
+ s.push_str(self.this_token_to_str());
+ s.push_str("`");
self.fatal(s);
}
}
let byte_offset_diff = next.next - current_byte_offset;
rdr.pos = rdr.pos + BytePos(byte_offset_diff);
rdr.curr = next.ch;
- rdr.col += CharPos(1u);
+ rdr.col = rdr.col + CharPos(1u);
if last_char == '\n' {
rdr.filemap.next_line(rdr.last_pos);
rdr.col = CharPos(0u);
is_float = true;
bump(rdr);
let dec_part = scan_digits(rdr, 10u);
- num_str += ".";
- num_str += dec_part;
+ num_str.push_char('.');
+ num_str.push_str(dec_part);
}
if is_float {
match base {
match scan_exponent(rdr) {
Some(ref s) => {
is_float = true;
- num_str += (*s);
+ num_str.push_str(*s);
}
None => ()
}
// FAILURE TO PARSE ITEM
if visibility != inherited {
let mut s = ~"unmatched visibility `";
- s += if visibility == public { "pub" } else { "priv" };
- s += "`";
+ if visibility == public {
+ s.push_str("pub")
+ } else {
+ s.push_str("priv")
+ }
+ s.push_char('`');
self.span_fatal(*self.last_span, s);
}
return iovi_none;
LIT_FLOAT(ref s, t) => {
let mut body = ident_to_str(s).to_owned();
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)
}
LIT_FLOAT_UNSUFFIXED(ref s) => {
let mut body = ident_to_str(s).to_owned();
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
}
let mut s = ~"[";
while i != right && L != 0u {
L -= 1u;
- if i != left { s += ", "; }
- s += fmt!("%d=%s", szs[i], tok_str(toks[i]));
+ if i != left {
+ s.push_str(", ");
+ }
+ s.push_str(fmt!("%d=%s", szs[i], tok_str(toks[i])));
i += 1u;
i %= n;
}
- s += "]";
+ s.push_char(']');
return s;
}
while i < 1500 {
let rv = vec::from_elem(r.gen_uint_range(0, i + 1), i);
if r.gen() {
- v += rv;
- }
- else {
+ v.push_all_move(rv);
+ } else {
v = rv + v;
}
i += 1;
fn show_color_list(set: ~[color]) -> ~str {
let mut out = ~"";
for set.iter().advance |col| {
- out += " ";
- out += show_color(*col);
+ out.push_char(' ');
+ out.push_str(show_color(*col));
}
return out;
}
let mut ans: ~[AminoAcids] = ~[];
for aa.iter().advance |a| {
cp += a.prob;
- ans += [AminoAcids {ch: a.ch, prob: cp}];
+ ans.push(AminoAcids {ch: a.ch, prob: cp});
}
ans
}
let b = str::raw::from_bytes(k);
// 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.
- 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));
}
}
for u8::range(0u8, 9u8) |row| {
for u8::range(0u8, 9u8) |col| {
let color = self.grid[row][col];
- if color == 0u8 { work += [(row, col)]; }
+ if color == 0u8 {
+ work.push((row, col));
+ }
}
}
impl<A> vec_monad<A> for ~[A] {
fn bind<B>(&self, f: &fn(A) -> ~[B]) {
let mut r = fail!();
- for self.iter().advance |elt| { r += f(*elt); }
+ for self.iter().advance |elt| { r = r + f(*elt); }
//~^ WARNING unreachable expression
//~^^ ERROR the type of this value must be known
}
// error-pattern:so long
fn main() {
- let x = ~[];
+ let mut x = ~[];
let y = ~[3];
fail!("so long");
- x += y;
+ x.push_all_move(y);
~"good" + ~"bye";
}
fn test_append() {
let mut s = ~"";
- s += ~"a";
+ s.push_str(~"a");
assert_eq!(s, ~"a");
let mut s = ~"a";
- s += ~"b";
+ s.push_str(~"b");
debug!(s.clone());
assert_eq!(s, ~"ab");
let mut s = ~"c";
- s += ~"offee";
+ s.push_str(~"offee");
assert!(s == ~"coffee");
- s += ~"&tea";
+ s.push_str(~"&tea");
assert!(s == ~"coffee&tea");
}
loop {
let x = 5;
if x > 3 {
- list += ~[take(x)];
+ list.push(take(x));
} else {
break;
}
None::<T> => x = 17,
_ => x = 42
}
- rs += ~[x];
+ rs.push(x);
}
return;
}
impl<A> vec_monad<A> for ~[A] {
fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B] {
let mut r = ~[];
- for self.iter().advance |elt| { r += f(elt); }
+ for self.iter().advance |elt| {
+ r.push_all_move(f(elt));
+ }
r
}
}
use std::vec;
-fn grow(v: &mut ~[int]) { *v += ~[1]; }
+fn grow(v: &mut ~[int]) {
+ v.push(1);
+}
pub fn main() {
let mut v: ~[int] = ~[];
pub fn main() {
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};
assert_eq!(p + Point {x: 5, y: 5}, Point {x: 16, y: 27});
assert_eq!(-p, Point {x: -11, y: -22});
for c.iter().advance |i| {
debug!(a);
let a = 17;
- b += ~[a];
+ b.push(a);
}
}
_ => { }
fn iter_(&self, f: &fn(&T)) { for self.iter().advance |x| { f(x); } }
fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r = ~[];
- for self.iter().advance |elt| { r += ~[f(elt)]; }
+ for self.iter().advance |elt| {
+ r.push(f(elt));
+ }
r
}
}
fn test1() {
let mut s: ~str = ~"hello";
- s += ~"world";
+ s.push_str("world");
debug!(s.clone());
assert_eq!(s[9], 'd' as u8);
}
pub fn main() {
let mut s = ~"a";
- s += ~"b";
+ s.push_char('b');
assert_eq!(s[0], 'a' as u8);
assert_eq!(s[1], 'b' as u8);
- s += ~"c";
- s += ~"d";
+ s.push_char('c');
+ s.push_char('d');
assert_eq!(s[0], 'a' as u8);
assert_eq!(s[1], 'b' as u8);
assert_eq!(s[2], 'c' as u8);
let mut r = ~[];
// FIXME: #7355 generates bad code with Iterator
for std::uint::range(0, self.len()) |i| {
- r += ~[f(&self[i])];
+ r.push(f(&self[i]));
}
r
}
pub fn main() {
let mut v = ~[1];
- v += ~[2];
- v += ~[3];
- v += ~[4];
- v += ~[5];
+ v.push(2);
+ v.push(3);
+ v.push(4);
+ v.push(5);
assert_eq!(v[0], 1);
assert_eq!(v[1], 2);
assert_eq!(v[2], 3);
let mut s = ~"hello";
// Ensure s is non-const.
- s += ~"there";
+ s.push_str("there");
return b(s);
}