Skip to content

Commit a1531ed

Browse files
pcwaltonemberian
authored andcommitted
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.
1 parent 3fcd4dc commit a1531ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+316
-209
lines changed

doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,9 @@ let your_crayons = ~[BananaMania, Beaver, Bittersweet];
12811281
// Add two vectors to create a new one
12821282
let our_crayons = my_crayons + your_crayons;
12831283
1284-
// += will append to a vector, provided it lives in a mutable slot
1284+
// .push_all() will append to a vector, provided it lives in a mutable slot
12851285
let mut my_crayons = my_crayons;
1286-
my_crayons += your_crayons;
1286+
my_crayons.push_all(your_crayons);
12871287
~~~~
12881288
12891289
> ***Note:*** The above examples of vector addition use owned

src/compiletest/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
2121
let mut line_num = 1u;
2222
while !rdr.eof() {
2323
let ln = rdr.read_line();
24-
error_patterns += parse_expected(line_num, ln);
24+
error_patterns.push_all_move(parse_expected(line_num, ln));
2525
line_num += 1u;
2626
}
2727
return error_patterns;

src/compiletest/runtest.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ actual:\n\
226226
~"-L", config.build_base.to_str(),
227227
~"-L",
228228
aux_output_dir_name(config, testfile).to_str()];
229-
args += split_maybe_args(&config.rustcflags);
230-
args += split_maybe_args(&props.compile_flags);
229+
args.push_all_move(split_maybe_args(&config.rustcflags));
230+
args.push_all_move(split_maybe_args(&props.compile_flags));
231231
return ProcArgs {prog: config.rustc_path.to_str(), args: args};
232232
}
233233
}
@@ -581,8 +581,8 @@ fn make_compile_args(config: &config, props: &TestProps, extras: ~[~str],
581581
~"-o", xform(config, testfile).to_str(),
582582
~"-L", config.build_base.to_str()]
583583
+ extras;
584-
args += split_maybe_args(&config.rustcflags);
585-
args += split_maybe_args(&props.compile_flags);
584+
args.push_all_move(split_maybe_args(&config.rustcflags));
585+
args.push_all_move(split_maybe_args(&props.compile_flags));
586586
return ProcArgs {prog: config.rustc_path.to_str(), args: args};
587587
}
588588

src/libextra/arena.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,18 @@ impl Arena {
186186
#[inline]
187187
fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
188188
unsafe {
189-
// XXX: Borrow check
190-
let head = transmute_mut_region(&mut self.pod_head);
191-
192-
let start = round_up_to(head.fill, align);
189+
let this = transmute_mut_region(self);
190+
let start = round_up_to(this.pod_head.fill, align);
193191
let end = start + n_bytes;
194-
if end > at_vec::capacity(head.data) {
195-
return self.alloc_pod_grow(n_bytes, align);
192+
if end > at_vec::capacity(this.pod_head.data) {
193+
return this.alloc_pod_grow(n_bytes, align);
196194
}
197-
head.fill = end;
195+
this.pod_head.fill = end;
198196

199197
//debug!("idx = %u, size = %u, align = %u, fill = %u",
200198
// start, n_bytes, align, head.fill);
201199

202-
ptr::offset(vec::raw::to_ptr(head.data), start)
200+
ptr::offset(vec::raw::to_ptr(this.pod_head.data), start)
203201
}
204202
}
205203

@@ -237,15 +235,15 @@ impl Arena {
237235
let after_tydesc = head.fill + sys::size_of::<*TyDesc>();
238236
let start = round_up_to(after_tydesc, align);
239237
let end = start + n_bytes;
240-
if end > at_vec::capacity(head.data) {
238+
if end > at_vec::capacity(self.head.data) {
241239
return self.alloc_nonpod_grow(n_bytes, align);
242240
}
243241
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>());
244242

245243
//debug!("idx = %u, size = %u, align = %u, fill = %u",
246244
// start, n_bytes, align, head.fill);
247245

248-
let buf = vec::raw::to_ptr(head.data);
246+
let buf = vec::raw::to_ptr(self.head.data);
249247
return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
250248
}
251249
}

src/libextra/bitv.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,15 @@ impl Bitv {
476476
* character is either '0' or '1'.
477477
*/
478478
pub fn to_str(&self) -> ~str {
479-
let mut rs = ~"";
480-
for self.each() |i| { if i { rs += "1"; } else { rs += "0"; } };
481-
rs
479+
let mut rs = ~"";
480+
for self.each() |i| {
481+
if i {
482+
rs.push_char('1');
483+
} else {
484+
rs.push_char('0');
485+
}
486+
};
487+
rs
482488
}
483489

484490

src/libextra/getopts.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -606,33 +606,47 @@ pub mod groups {
606606
let mut row = " ".repeat(4);
607607

608608
// short option
609-
row += match short_name.len() {
610-
0 => ~"",
611-
1 => ~"-" + short_name + " ",
609+
match short_name.len() {
610+
0 => {}
611+
1 => {
612+
row.push_char('-');
613+
row.push_str(short_name);
614+
row.push_char(' ');
615+
}
612616
_ => fail!("the short name should only be 1 ascii char long"),
613-
};
617+
}
614618

615619
// long option
616-
row += match long_name.len() {
617-
0 => ~"",
618-
_ => ~"--" + long_name + " ",
619-
};
620+
match long_name.len() {
621+
0 => {}
622+
_ => {
623+
row.push_str("--");
624+
row.push_str(long_name);
625+
row.push_char(' ');
626+
}
627+
}
620628

621629
// arg
622-
row += match hasarg {
623-
No => ~"",
624-
Yes => hint,
625-
Maybe => ~"[" + hint + "]",
626-
};
630+
match hasarg {
631+
No => {}
632+
Yes => row.push_str(hint),
633+
Maybe => {
634+
row.push_char('[');
635+
row.push_str(hint);
636+
row.push_char(']');
637+
}
638+
}
627639

628640
// FIXME: #5516
629641
// here we just need to indent the start of the description
630642
let rowlen = row.len();
631-
row += if rowlen < 24 {
632-
" ".repeat(24 - rowlen)
643+
if rowlen < 24 {
644+
for (24 - rowlen).times {
645+
row.push_char(' ')
646+
}
633647
} else {
634-
copy desc_sep
635-
};
648+
row.push_str(desc_sep)
649+
}
636650

637651
// Normalize desc to contain words separated by one space character
638652
let mut desc_normalized_whitespace = ~"";
@@ -649,7 +663,7 @@ pub mod groups {
649663

650664
// FIXME: #5516
651665
// wrapped description
652-
row += desc_rows.connect(desc_sep);
666+
row.push_str(desc_rows.connect(desc_sep));
653667

654668
row
655669
});

src/libextra/json.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,27 @@ fn escape_str(s: &str) -> ~str {
6060
let mut escaped = ~"\"";
6161
for s.iter().advance |c| {
6262
match c {
63-
'"' => escaped += "\\\"",
64-
'\\' => escaped += "\\\\",
65-
'\x08' => escaped += "\\b",
66-
'\x0c' => escaped += "\\f",
67-
'\n' => escaped += "\\n",
68-
'\r' => escaped += "\\r",
69-
'\t' => escaped += "\\t",
70-
_ => escaped += str::from_char(c)
63+
'"' => escaped.push_str("\\\""),
64+
'\\' => escaped.push_str("\\\\"),
65+
'\x08' => escaped.push_str("\\b"),
66+
'\x0c' => escaped.push_str("\\f"),
67+
'\n' => escaped.push_str("\\n"),
68+
'\r' => escaped.push_str("\\r"),
69+
'\t' => escaped.push_str("\\t"),
70+
_ => escaped.push_char(c),
7171
}
7272
};
7373

74-
escaped += "\"";
74+
escaped.push_char('"');
7575

7676
escaped
7777
}
7878

7979
fn spaces(n: uint) -> ~str {
8080
let mut ss = ~"";
81-
for n.times { ss.push_str(" "); }
81+
for n.times {
82+
ss.push_str(" ");
83+
}
8284
return ss;
8385
}
8486

src/libextra/md4.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ pub fn md4_str(msg: &[u8]) -> ~str {
119119
let mut i = 0u32;
120120
while i < 4u32 {
121121
let byte = (u >> (i * 8u32)) as u8;
122-
if byte <= 16u8 { result += "0"; }
123-
result += uint::to_str_radix(byte as uint, 16u);
122+
if byte <= 16u8 {
123+
result.push_char('0')
124+
}
125+
result.push_str(uint::to_str_radix(byte as uint, 16u));
124126
i += 1u32;
125127
}
126128
}

src/libextra/net_url.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
9393
out.push_char(ch);
9494
}
9595

96-
_ => out += fmt!("%%%X", ch as uint)
96+
_ => out.push_str(fmt!("%%%X", ch as uint))
9797
}
9898
} else {
99-
out += fmt!("%%%X", ch as uint);
99+
out.push_str(fmt!("%%%X", ch as uint));
100100
}
101101
}
102102
}
@@ -192,7 +192,7 @@ fn encode_plus(s: &str) -> ~str {
192192
out.push_char(ch);
193193
}
194194
' ' => out.push_char('+'),
195-
_ => out += fmt!("%%%X", ch as uint)
195+
_ => out.push_str(fmt!("%%%X", ch as uint))
196196
}
197197
}
198198

@@ -218,7 +218,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
218218
first = false;
219219
}
220220

221-
out += fmt!("%s=%s", key, encode_plus(*value));
221+
out.push_str(fmt!("%s=%s", key, encode_plus(*value)));
222222
}
223223
}
224224

src/libextra/num/bigint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,11 @@ impl ToStrRadix for BigUint {
510510
let mut m = n;
511511
while m > divider {
512512
let (d, m0) = m.div_mod_floor(&divider);
513-
result += [m0.to_uint() as BigDigit];
513+
result.push(m0.to_uint() as BigDigit);
514514
m = d;
515515
}
516516
if !m.is_zero() {
517-
result += [m.to_uint() as BigDigit];
517+
result.push(m.to_uint() as BigDigit);
518518
}
519519
return result;
520520
}

src/libextra/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str {
849849
do io::with_str_reader(format) |rdr| {
850850
while !rdr.eof() {
851851
match rdr.read_char() {
852-
'%' => buf += parse_type(rdr.read_char(), tm),
852+
'%' => buf.push_str(parse_type(rdr.read_char(), tm)),
853853
ch => buf.push_char(ch)
854854
}
855855
}

src/librustc/back/link.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -642,15 +642,15 @@ pub fn sanitize(s: &str) -> ~str {
642642
for s.iter().advance |c| {
643643
match c {
644644
// Escape these with $ sequences
645-
'@' => result += "$SP$",
646-
'~' => result += "$UP$",
647-
'*' => result += "$RP$",
648-
'&' => result += "$BP$",
649-
'<' => result += "$LT$",
650-
'>' => result += "$GT$",
651-
'(' => result += "$LP$",
652-
')' => result += "$RP$",
653-
',' => result += "$C$",
645+
'@' => result.push_str("$SP$"),
646+
'~' => result.push_str("$UP$"),
647+
'*' => result.push_str("$RP$"),
648+
'&' => result.push_str("$BP$"),
649+
'<' => result.push_str("$LT$"),
650+
'>' => result.push_str("$GT$"),
651+
'(' => result.push_str("$LP$"),
652+
')' => result.push_str("$RP$"),
653+
',' => result.push_str("$C$"),
654654

655655
// '.' doesn't occur in types and functions, so reuse it
656656
// for ':'
@@ -686,12 +686,14 @@ pub fn mangle(sess: Session, ss: path) -> ~str {
686686
let mut n = ~"_ZN"; // Begin name-sequence.
687687

688688
for ss.iter().advance |s| {
689-
match *s { path_name(s) | path_mod(s) => {
690-
let sani = sanitize(sess.str_of(s));
691-
n += fmt!("%u%s", sani.len(), sani);
692-
} }
689+
match *s {
690+
path_name(s) | path_mod(s) => {
691+
let sani = sanitize(sess.str_of(s));
692+
n.push_str(fmt!("%u%s", sani.len(), sani));
693+
}
694+
}
693695
}
694-
n += "E"; // End name-sequence.
696+
n.push_char('E'); // End name-sequence.
695697
n
696698
}
697699

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
979979

980980
// >:-<
981981
let mut impl_path = vec::append(~[], path);
982-
impl_path += [ast_map::path_name(item.ident)];
982+
impl_path.push(ast_map::path_name(item.ident));
983983

984984
for methods.iter().advance |m| {
985985
index.push(entry {val: m.id, pos: ebml_w.writer.tell()});

src/librustc/metadata/tydecode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ fn parse_opt<T>(st: &mut PState, f: &fn(&mut PState) -> T) -> Option<T> {
261261
fn parse_str(st: &mut PState, term: char) -> ~str {
262262
let mut result = ~"";
263263
while peek(st) != term {
264-
result += str::from_byte(next_byte(st));
264+
unsafe {
265+
str::raw::push_byte(&mut result, next_byte(st));
266+
}
265267
}
266268
next(st);
267269
return result;

src/librustc/middle/resolve.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,8 +2091,12 @@ impl Resolver {
20912091
let mut first = true;
20922092
let mut result = ~"";
20932093
for idents.iter().advance |ident| {
2094-
if first { first = false; } else { result += "::" };
2095-
result += self.session.str_of(*ident);
2094+
if first {
2095+
first = false
2096+
} else {
2097+
result.push_str("::")
2098+
}
2099+
result.push_str(*self.session.str_of(*ident));
20962100
};
20972101
return result;
20982102
}

src/librustc/middle/trans/asm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
9898
if !ia.clobbers.is_empty() && !clobbers.is_empty() {
9999
clobbers = fmt!("%s,%s", ia.clobbers, clobbers);
100100
} else {
101-
clobbers += ia.clobbers;
101+
clobbers.push_str(*ia.clobbers);
102102
};
103103

104104
// Add the clobbers to our constraints list
105-
if !clobbers.is_empty() && !constraints.is_empty() {
106-
constraints += ",";
107-
constraints += clobbers;
105+
if clobbers.len() != 0 && constraints.len() != 0 {
106+
constraints.push_char(',');
107+
constraints.push_str(clobbers);
108108
} else {
109-
constraints += clobbers;
109+
constraints.push_str(clobbers);
110110
}
111111

112112
debug!("Asm Constraints: %?", constraints);

0 commit comments

Comments
 (0)