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:
parent
3fcd4dca30
commit
a1531ed946
@ -1281,9 +1281,9 @@ let your_crayons = ~[BananaMania, Beaver, Bittersweet];
|
||||
// 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
|
||||
|
@ -21,7 +21,7 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
|
||||
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;
|
||||
|
@ -226,8 +226,8 @@ actual:\n\
|
||||
~"-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};
|
||||
}
|
||||
}
|
||||
@ -581,8 +581,8 @@ fn make_compile_args(config: &config, props: &TestProps, extras: ~[~str],
|
||||
~"-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};
|
||||
}
|
||||
|
||||
|
@ -186,20 +186,18 @@ impl Arena {
|
||||
#[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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +235,7 @@ impl Arena {
|
||||
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>());
|
||||
@ -245,7 +243,7 @@ impl Arena {
|
||||
//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));
|
||||
}
|
||||
}
|
||||
|
@ -476,9 +476,15 @@ impl Bitv {
|
||||
* 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
|
||||
}
|
||||
|
||||
|
||||
|
@ -606,33 +606,47 @@ pub mod groups {
|
||||
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 = ~"";
|
||||
@ -649,7 +663,7 @@ pub mod groups {
|
||||
|
||||
// FIXME: #5516
|
||||
// wrapped description
|
||||
row += desc_rows.connect(desc_sep);
|
||||
row.push_str(desc_rows.connect(desc_sep));
|
||||
|
||||
row
|
||||
});
|
||||
|
@ -60,25 +60,27 @@ fn escape_str(s: &str) -> ~str {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,10 @@ pub fn md4_str(msg: &[u8]) -> ~str {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -93,10 +93,10 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,7 +192,7 @@ fn encode_plus(s: &str) -> ~str {
|
||||
out.push_char(ch);
|
||||
}
|
||||
' ' => 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;
|
||||
}
|
||||
|
||||
out += fmt!("%s=%s", key, encode_plus(*value));
|
||||
out.push_str(fmt!("%s=%s", key, encode_plus(*value)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,11 +510,11 @@ impl ToStrRadix for BigUint {
|
||||
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;
|
||||
}
|
||||
|
@ -849,7 +849,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -642,15 +642,15 @@ pub fn sanitize(s: &str) -> ~str {
|
||||
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 ':'
|
||||
@ -686,12 +686,14 @@ pub fn mangle(sess: Session, ss: path) -> ~str {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -979,7 +979,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
|
||||
// >:-<
|
||||
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()});
|
||||
|
@ -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 {
|
||||
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;
|
||||
|
@ -2091,8 +2091,12 @@ impl Resolver {
|
||||
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;
|
||||
}
|
||||
|
@ -98,15 +98,15 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
|
||||
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);
|
||||
|
@ -68,13 +68,13 @@ pub fn count_insn(cx: block, category: &str) {
|
||||
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,
|
||||
|
@ -964,9 +964,12 @@ pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2120,7 +2120,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
|
||||
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)
|
||||
}
|
||||
@ -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 {
|
||||
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
|
||||
}
|
||||
|
@ -213,6 +213,13 @@ impl PurityState {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
@ -1487,7 +1494,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
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;
|
||||
|
||||
@ -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,
|
||||
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);
|
||||
@ -2229,7 +2259,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
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) ||
|
||||
@ -2242,7 +2280,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
@ -192,11 +192,11 @@ pub fn header_name(doc: doc::ItemTag) -> ~str {
|
||||
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)
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ fn generic_writer(process: ~fn(markdown: ~str)) -> Writer {
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -214,7 +214,7 @@ fn future_writer() -> (Writer, future::Future<~str>) {
|
||||
let mut res = ~"";
|
||||
loop {
|
||||
match port.recv() {
|
||||
Write(s) => res += s,
|
||||
Write(s) => res.push_str(s),
|
||||
Done => break
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ fn make_doc_from_pages(page_port: &PagePort) -> doc::Doc {
|
||||
loop {
|
||||
let val = page_port.recv();
|
||||
if val.is_some() {
|
||||
pages += [val.unwrap()];
|
||||
pages.push(val.unwrap());
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -402,7 +402,8 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
|
||||
if line.trim() == ":}" {
|
||||
end_multiline = true;
|
||||
} else {
|
||||
multiline_cmd += line + "\n";
|
||||
multiline_cmd.push_str(line);
|
||||
multiline_cmd.push_char('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
use container::Container;
|
||||
use iterator::IteratorUtil;
|
||||
use rt::io::Writer;
|
||||
use str::OwnedStr;
|
||||
use to_bytes::IterBytes;
|
||||
use uint;
|
||||
use vec::ImmutableVector;
|
||||
@ -369,7 +370,7 @@ impl Streaming for SipState {
|
||||
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
|
||||
}
|
||||
@ -471,7 +472,7 @@ mod tests {
|
||||
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
|
||||
}
|
||||
@ -492,7 +493,7 @@ mod tests {
|
||||
|
||||
assert!(f == i && f == v);
|
||||
|
||||
buf += [t as u8];
|
||||
buf.push(t as u8);
|
||||
stream_inc.input([t as u8]);
|
||||
|
||||
t += 1;
|
||||
|
@ -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 {
|
||||
total = total * multiplier;
|
||||
}
|
||||
my_pow = my_pow / 2u;
|
||||
my_pow = my_pow / 2u;
|
||||
multiplier = multiplier * multiplier;
|
||||
}
|
||||
total
|
||||
|
@ -21,8 +21,8 @@ use cmp::Eq;
|
||||
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};
|
||||
@ -476,7 +476,7 @@ impl ToStr for PosixPath {
|
||||
fn to_str(&self) -> ~str {
|
||||
let mut s = ~"";
|
||||
if self.is_absolute {
|
||||
s += "/";
|
||||
s.push_str("/");
|
||||
}
|
||||
s + self.components.connect("/")
|
||||
}
|
||||
@ -655,15 +655,21 @@ impl ToStr for WindowsPath {
|
||||
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("\\")
|
||||
}
|
||||
|
@ -263,8 +263,11 @@ fn highlight_lines(cm: @codemap::CodeMap,
|
||||
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);
|
||||
}
|
||||
|
||||
@ -285,23 +288,29 @@ fn highlight_lines(cm: @codemap::CodeMap,
|
||||
// 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));
|
||||
}
|
||||
|
@ -26,8 +26,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
||||
}
|
||||
} 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.")
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ impl gen_send for message {
|
||||
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) {
|
||||
@ -76,13 +76,15 @@ impl gen_send for message {
|
||||
(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) {
|
||||
@ -92,23 +94,22 @@ impl gen_send for message {
|
||||
(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());
|
||||
@ -155,19 +156,19 @@ impl gen_send for message {
|
||||
};
|
||||
|
||||
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());
|
||||
@ -433,10 +434,10 @@ impl gen_init for protocol {
|
||||
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() {
|
||||
|
@ -42,7 +42,7 @@ impl parser_attr for Parser {
|
||||
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(
|
||||
@ -53,7 +53,7 @@ impl parser_attr for Parser {
|
||||
if attr.node.style != ast::attr_outer {
|
||||
self.fatal("expected outer comment");
|
||||
}
|
||||
attrs += [attr];
|
||||
attrs.push(attr);
|
||||
self.bump();
|
||||
}
|
||||
_ => break
|
||||
@ -77,9 +77,7 @@ impl parser_attr for Parser {
|
||||
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,
|
||||
@ -105,7 +103,7 @@ impl parser_attr for Parser {
|
||||
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 =
|
||||
@ -113,7 +111,7 @@ impl parser_attr for Parser {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -125,9 +123,9 @@ impl parser_attr for Parser {
|
||||
);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ fn read_block_comment(rdr: @mut StringReader,
|
||||
bump(rdr);
|
||||
}
|
||||
if !is_eof(rdr) {
|
||||
curr_line += "*/";
|
||||
curr_line.push_str("*/");
|
||||
bump(rdr);
|
||||
bump(rdr);
|
||||
}
|
||||
@ -278,13 +278,13 @@ fn read_block_comment(rdr: @mut StringReader,
|
||||
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); }
|
||||
}
|
||||
|
@ -192,10 +192,10 @@ impl Parser {
|
||||
);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ pub fn bump(rdr: &mut StringReader) {
|
||||
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);
|
||||
@ -448,8 +448,8 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
|
||||
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 {
|
||||
@ -461,7 +461,7 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
|
||||
match scan_exponent(rdr) {
|
||||
Some(ref s) => {
|
||||
is_float = true;
|
||||
num_str += (*s);
|
||||
num_str.push_str(*s);
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
|
@ -4257,8 +4257,12 @@ impl Parser {
|
||||
// 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;
|
||||
|
@ -178,14 +178,14 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
|
||||
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
|
||||
}
|
||||
|
@ -122,12 +122,14 @@ pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -87,9 +87,8 @@ fn vec_plus() {
|
||||
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;
|
||||
|
@ -50,8 +50,8 @@ fn show_color(cc: color) -> ~str {
|
||||
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;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ fn make_cumulative(aa: ~[AminoAcids]) -> ~[AminoAcids] {
|
||||
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
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,9 @@ impl Sudoku {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ trait vec_monad<A> {
|
||||
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
|
||||
}
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
// 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";
|
||||
}
|
||||
|
@ -44,19 +44,19 @@ fn test_heap_add() {
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ fn the_loop() {
|
||||
loop {
|
||||
let x = 5;
|
||||
if x > 3 {
|
||||
list += ~[take(x)];
|
||||
list.push(take(x));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ fn foo<T>(y: Option<T>) {
|
||||
None::<T> => x = 17,
|
||||
_ => x = 42
|
||||
}
|
||||
rs += ~[x];
|
||||
rs.push(x);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ trait vec_monad<A> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ extern mod extra;
|
||||
|
||||
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] = ~[];
|
||||
|
@ -57,7 +57,7 @@ impl cmp::Eq for Point {
|
||||
|
||||
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});
|
||||
|
@ -19,7 +19,7 @@ fn foo(c: ~[int]) {
|
||||
for c.iter().advance |i| {
|
||||
debug!(a);
|
||||
let a = 17;
|
||||
b += ~[a];
|
||||
b.push(a);
|
||||
}
|
||||
}
|
||||
_ => { }
|
||||
|
@ -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 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
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ extern mod extra;
|
||||
|
||||
fn test1() {
|
||||
let mut s: ~str = ~"hello";
|
||||
s += ~"world";
|
||||
s.push_str("world");
|
||||
debug!(s.clone());
|
||||
assert_eq!(s[9], 'd' as u8);
|
||||
}
|
||||
|
@ -12,11 +12,11 @@
|
||||
|
||||
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);
|
||||
|
@ -33,7 +33,7 @@ impl<T> map<T> for ~[T] {
|
||||
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
|
||||
}
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
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);
|
||||
|
@ -17,7 +17,7 @@ fn make(i: int) -> t {
|
||||
let mut s = ~"hello";
|
||||
// Ensure s is non-const.
|
||||
|
||||
s += ~"there";
|
||||
s.push_str("there");
|
||||
return b(s);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user