Skip to content

Commit ce9c022

Browse files
committed
auto merge of #6349 : thestinger/rust/explicit_copy, r=thestinger
I removed some of the copies, but most are just made explicit. The usage in `libcore` was already fixed, but the attribute was only set to warn (not removed).
2 parents 7a4c6e5 + 2bc1263 commit ce9c022

14 files changed

+105
-106
lines changed

src/libcore/core.rc

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ they contained the following prologue:
6060
// Don't link to core. We are core.
6161
#[no_core];
6262

63-
#[warn(vecs_implicitly_copyable)];
6463
#[deny(non_camel_case_types)];
6564
#[allow(deprecated_mutable_fields)];
6665

src/libstd/arc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ mod tests {
498498

499499
let arc_v = p.recv();
500500

501-
let v = *arc::get::<~[int]>(&arc_v);
501+
let v = copy *arc::get::<~[int]>(&arc_v);
502502
assert!(v[3] == 4);
503503
};
504504

src/libstd/future.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ mod test {
238238
239239
#[test]
240240
fn test_sendable_future() {
241-
let expected = ~"schlorf";
242-
let f = Cell(do spawn { copy expected });
241+
let expected = "schlorf";
242+
let f = Cell(do spawn { expected });
243243
do task::spawn {
244244
let mut f = f.take();
245245
let actual = f.get();

src/libstd/getopts.rs

+38-33
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
229229
let l = args.len();
230230
let mut i = 0;
231231
while i < l {
232-
let cur = args[i];
232+
let cur = copy args[i];
233233
let curlen = cur.len();
234234
if !is_arg(cur) {
235235
free.push(cur);
236236
} else if cur == ~"--" {
237237
let mut j = i + 1;
238-
while j < l { free.push(args[j]); j += 1; }
238+
while j < l { free.push(copy args[j]); j += 1; }
239239
break;
240240
} else {
241241
let mut names;
@@ -248,8 +248,8 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
248248
names = ~[Long(tail)];
249249
} else {
250250
names =
251-
~[Long(tail_eq[0])];
252-
i_arg = Some(tail_eq[1]);
251+
~[Long(copy tail_eq[0])];
252+
i_arg = Some(copy tail_eq[1]);
253253
}
254254
} else {
255255
let mut j = 1;
@@ -266,7 +266,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
266266
interpreted correctly
267267
*/
268268
269-
match find_opt(opts, opt) {
269+
match find_opt(opts, copy opt) {
270270
Some(id) => last_valid_opt_id = Some(id),
271271
None => {
272272
let arg_follows =
@@ -292,7 +292,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
292292
let mut name_pos = 0;
293293
for names.each() |nm| {
294294
name_pos += 1;
295-
let optid = match find_opt(opts, *nm) {
295+
let optid = match find_opt(opts, copy *nm) {
296296
Some(id) => id,
297297
None => return Err(UnrecognizedOption(name_str(nm)))
298298
};
@@ -305,18 +305,18 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
305305
}
306306
Maybe => {
307307
if !i_arg.is_none() {
308-
vals[optid].push(Val(i_arg.get()));
308+
vals[optid].push(Val((copy i_arg).get()));
309309
} else if name_pos < names.len() ||
310310
i + 1 == l || is_arg(args[i + 1]) {
311311
vals[optid].push(Given);
312-
} else { i += 1; vals[optid].push(Val(args[i])); }
312+
} else { i += 1; vals[optid].push(Val(copy args[i])); }
313313
}
314314
Yes => {
315315
if !i_arg.is_none() {
316-
vals[optid].push(Val(i_arg.get()));
316+
vals[optid].push(Val((copy i_arg).get()));
317317
} else if i + 1 == l {
318318
return Err(ArgumentMissing(name_str(nm)));
319-
} else { i += 1; vals[optid].push(Val(args[i])); }
319+
} else { i += 1; vals[optid].push(Val(copy args[i])); }
320320
}
321321
}
322322
}
@@ -346,15 +346,15 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
346346
347347
fn opt_vals(mm: &Matches, nm: &str) -> ~[Optval] {
348348
return match find_opt(mm.opts, mkname(nm)) {
349-
Some(id) => mm.vals[id],
349+
Some(id) => copy mm.vals[id],
350350
None => {
351351
error!("No option '%s' defined", nm);
352352
fail!()
353353
}
354354
};
355355
}
356356

357-
fn opt_val(mm: &Matches, nm: &str) -> Optval { return opt_vals(mm, nm)[0]; }
357+
fn opt_val(mm: &Matches, nm: &str) -> Optval { copy opt_vals(mm, nm)[0] }
358358

359359
/// Returns true if an option was matched
360360
pub fn opt_present(mm: &Matches, nm: &str) -> bool {
@@ -547,25 +547,29 @@ pub mod groups {
547547
// translate OptGroup into Opt
548548
// (both short and long names correspond to different Opts)
549549
pub fn long_to_short(lopt: &OptGroup) -> ~[Opt] {
550-
match ((*lopt).short_name.len(),
551-
(*lopt).long_name.len()) {
550+
let OptGroup{short_name: short_name,
551+
long_name: long_name,
552+
hasarg: hasarg,
553+
occur: occur,
554+
_} = copy *lopt;
552555

556+
match (short_name.len(), long_name.len()) {
553557
(0,0) => fail!(~"this long-format option was given no name"),
554558
555-
(0,_) => ~[Opt {name: Long(((*lopt).long_name)),
556-
hasarg: (*lopt).hasarg,
557-
occur: (*lopt).occur}],
559+
(0,_) => ~[Opt {name: Long((long_name)),
560+
hasarg: hasarg,
561+
occur: occur}],
558562
559-
(1,0) => ~[Opt {name: Short(str::char_at((*lopt).short_name, 0)),
560-
hasarg: (*lopt).hasarg,
561-
occur: (*lopt).occur}],
563+
(1,0) => ~[Opt {name: Short(str::char_at(short_name, 0)),
564+
hasarg: hasarg,
565+
occur: occur}],
562566
563-
(1,_) => ~[Opt {name: Short(str::char_at((*lopt).short_name, 0)),
564-
hasarg: (*lopt).hasarg,
565-
occur: (*lopt).occur},
566-
Opt {name: Long(((*lopt).long_name)),
567-
hasarg: (*lopt).hasarg,
568-
occur: (*lopt).occur}],
567+
(1,_) => ~[Opt {name: Short(str::char_at(short_name, 0)),
568+
hasarg: hasarg,
569+
occur: occur},
570+
Opt {name: Long((long_name)),
571+
hasarg: hasarg,
572+
occur: occur}],
569573
570574
(_,_) => fail!(~"something is wrong with the long-form opt")
571575
}
@@ -586,11 +590,12 @@ pub mod groups {
586590
let desc_sep = ~"\n" + str::repeat(~" ", 24);
587591
588592
let rows = vec::map(opts, |optref| {
589-
let short_name = (*optref).short_name;
590-
let long_name = (*optref).long_name;
591-
let hint = (*optref).hint;
592-
let desc = (*optref).desc;
593-
let hasarg = (*optref).hasarg;
593+
let OptGroup{short_name: short_name,
594+
long_name: long_name,
595+
hint: hint,
596+
desc: desc,
597+
hasarg: hasarg,
598+
_} = copy *optref;
594599
595600
let mut row = str::repeat(~" ", 4);
596601
@@ -620,7 +625,7 @@ pub mod groups {
620625
row += if rowlen < 24 {
621626
str::repeat(~" ", 24 - rowlen)
622627
} else {
623-
desc_sep
628+
copy desc_sep
624629
};
625630
626631
// Normalize desc to contain words separated by one space character
@@ -892,7 +897,7 @@ mod tests {
892897
let rs = getopts(args, opts);
893898
match rs {
894899
Err(copy f) => {
895-
error!(fail_str(f));
900+
error!(fail_str(copy f));
896901
check_fail_type(f, UnexpectedArgument_);
897902
}
898903
_ => fail!()

src/libstd/net_ip.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub mod v4 {
175175
pub fn parse_addr(ip: &str) -> IpAddr {
176176
match try_parse_addr(ip) {
177177
result::Ok(addr) => addr,
178-
result::Err(ref err_data) => fail!(err_data.err_msg)
178+
result::Err(ref err_data) => fail!(copy err_data.err_msg)
179179
}
180180
}
181181
// the simple, old style numberic representation of
@@ -272,7 +272,7 @@ pub mod v6 {
272272
pub fn parse_addr(ip: &str) -> IpAddr {
273273
match try_parse_addr(ip) {
274274
result::Ok(addr) => addr,
275-
result::Err(copy err_data) => fail!(err_data.err_msg)
275+
result::Err(copy err_data) => fail!(copy err_data.err_msg)
276276
}
277277
}
278278
pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {

0 commit comments

Comments
 (0)