Skip to content

Commit cfed923

Browse files
committed
demode the each() method on vec and other iterables.
1 parent 1c39f19 commit cfed923

File tree

110 files changed

+483
-456
lines changed

Some content is hidden

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

110 files changed

+483
-456
lines changed

src/cargo/cargo.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ fn load_crate(filename: &Path) -> Option<crate> {
325325
let mut attr_from = ~"";
326326

327327
for m.each |item| {
328-
match attr::get_meta_item_value_str(item) {
328+
match attr::get_meta_item_value_str(*item) {
329329
Some(value) => {
330-
let name = attr::get_meta_item_name(item);
330+
let name = attr::get_meta_item_name(*item);
331331

332332
match name {
333333
~"vers" => attr_vers = value,
@@ -530,7 +530,7 @@ fn load_one_source_package(src: source, p: map::HashMap<~str, json::Json>) {
530530
match p.find(~"tags") {
531531
Some(json::List(js)) => {
532532
for (*js).each |j| {
533-
match j {
533+
match *j {
534534
json::String(j) => vec::grow(tags, 1u, *j),
535535
_ => ()
536536
}
@@ -602,7 +602,7 @@ fn load_source_packages(c: &cargo, src: source) {
602602
match json::from_str(result::get(pkgstr)) {
603603
Ok(json::List(js)) => {
604604
for (*js).each |j| {
605-
match j {
605+
match *j {
606606
json::Dict(p) => {
607607
load_one_source_package(src, p);
608608
}
@@ -715,7 +715,7 @@ fn configure(opts: options) -> cargo {
715715
fn for_each_package(c: &cargo, b: fn(source, package)) {
716716
for c.sources.each_value |v| {
717717
for v.packages.each |p| {
718-
b(v, p);
718+
b(v, *p);
719719
}
720720
}
721721
}
@@ -773,15 +773,15 @@ fn install_one_crate(c: &cargo, path: &Path, cf: &Path) {
773773
!str::starts_with(option::get(ct.filename()),
774774
~"lib")) {
775775
debug!(" bin: %s", ct.to_str());
776-
install_to_dir(ct, &c.bindir);
776+
install_to_dir(*ct, &c.bindir);
777777
if c.opts.mode == system_mode {
778778
// FIXME (#2662): Put this file in PATH / symlink it so it can
779779
// be used as a generic executable
780780
// `cargo install -G rustray` and `rustray file.obj`
781781
}
782782
} else {
783783
debug!(" lib: %s", ct.to_str());
784-
install_to_dir(ct, &c.libdir);
784+
install_to_dir(*ct, &c.libdir);
785785
}
786786
}
787787
}
@@ -814,7 +814,7 @@ fn install_source(c: &cargo, path: &Path) {
814814
}
815815

816816
for cratefiles.each |cf| {
817-
match load_crate(&cf) {
817+
match load_crate(cf) {
818818
None => loop,
819819
Some(crate) => {
820820
for crate.deps.each |query| {
@@ -823,15 +823,15 @@ fn install_source(c: &cargo, path: &Path) {
823823
// condition")
824824

825825
let wd = get_temp_workdir(c);
826-
install_query(c, &wd, query);
826+
install_query(c, &wd, *query);
827827
}
828828

829829
os::change_dir(path);
830830

831831
if c.opts.test {
832-
test_one_crate(c, path, &cf);
832+
test_one_crate(c, path, cf);
833833
}
834-
install_one_crate(c, path, &cf);
834+
install_one_crate(c, path, cf);
835835
}
836836
}
837837
}
@@ -915,7 +915,7 @@ fn install_uuid(c: &cargo, wd: &Path, uuid: ~str) {
915915
}
916916
error(~"found multiple packages:");
917917
for ps.each |elt| {
918-
let (sname,p) = copy elt;
918+
let (sname,p) = copy *elt;
919919
info(~" " + sname + ~"/" + p.uuid + ~" (" + p.name + ~")");
920920
}
921921
}
@@ -939,7 +939,7 @@ fn install_named(c: &cargo, wd: &Path, name: ~str) {
939939
}
940940
error(~"found multiple packages:");
941941
for ps.each |elt| {
942-
let (sname,p) = copy elt;
942+
let (sname,p) = copy *elt;
943943
info(~" " + sname + ~"/" + p.uuid + ~" (" + p.name + ~")");
944944
}
945945
}
@@ -949,7 +949,7 @@ fn install_uuid_specific(c: &cargo, wd: &Path, src: ~str, uuid: ~str) {
949949
Some(s) => {
950950
for s.packages.each |p| {
951951
if p.uuid == uuid {
952-
install_package(c, src, wd, p);
952+
install_package(c, src, wd, *p);
953953
return;
954954
}
955955
}
@@ -964,7 +964,7 @@ fn install_named_specific(c: &cargo, wd: &Path, src: ~str, name: ~str) {
964964
Some(s) => {
965965
for s.packages.each |p| {
966966
if p.name == name {
967-
install_package(c, src, wd, p);
967+
install_package(c, src, wd, *p);
968968
return;
969969
}
970970
}
@@ -1002,22 +1002,22 @@ fn cmd_uninstall(c: &cargo) {
10021002

10031003
if is_uuid(target) {
10041004
for os::list_dir(lib).each |file| {
1005-
match str::find_str(file, ~"-" + target + ~"-") {
1006-
Some(_) => if !try_uninstall(&lib.push(file)) { return },
1005+
match str::find_str(*file, ~"-" + target + ~"-") {
1006+
Some(_) => if !try_uninstall(&lib.push(*file)) { return },
10071007
None => ()
10081008
}
10091009
}
10101010
error(~"can't find package with uuid: " + target);
10111011
} else {
10121012
for os::list_dir(lib).each |file| {
1013-
match str::find_str(file, ~"lib" + target + ~"-") {
1014-
Some(_) => if !try_uninstall(&lib.push(file)) { return },
1013+
match str::find_str(*file, ~"lib" + target + ~"-") {
1014+
Some(_) => if !try_uninstall(&lib.push(*file)) { return },
10151015
None => ()
10161016
}
10171017
}
10181018
for os::list_dir(bin).each |file| {
1019-
match str::find_str(file, target) {
1020-
Some(_) => if !try_uninstall(&lib.push(file)) { return },
1019+
match str::find_str(*file, target) {
1020+
Some(_) => if !try_uninstall(&lib.push(*file)) { return },
10211021
None => ()
10221022
}
10231023
}

src/cargo/pgp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn verify(root: &Path, data: &Path, sig: &Path, keyfp: ~str) -> bool {
9595
~"--verify", sig.to_str(),
9696
data.to_str()]);
9797
let res = ~"Primary key fingerprint: " + keyfp;
98-
for str::split_char(p.err, '\n').each |line| {
98+
for str::split_char_each(p.err, '\n') |line| {
9999
if line == res { return true; }
100100
}
101101
return false;

src/compiletest/compiletest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn make_tests(config: config) -> ~[test::TestDesc] {
138138
config.src_base.to_str());
139139
let mut tests = ~[];
140140
for os::list_dir_path(&config.src_base).each |file| {
141-
let file = copy file;
141+
let file = copy *file;
142142
debug!("inspecting file %s", file.to_str());
143143
if is_test(config, file) {
144144
vec::push(tests, make_test(config, file))
@@ -160,11 +160,11 @@ fn is_test(config: config, testfile: &Path) -> bool {
160160
let mut valid = false;
161161

162162
for valid_extensions.each |ext| {
163-
if str::ends_with(name, ext) { valid = true; }
163+
if str::ends_with(name, *ext) { valid = true; }
164164
}
165165

166166
for invalid_prefixes.each |pre| {
167-
if str::starts_with(name, pre) { valid = false; }
167+
if str::starts_with(name, *pre) { valid = false; }
168168
}
169169

170170
return valid;

src/compiletest/runtest.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn check_error_patterns(props: test_props,
219219
let mut next_err_pat = props.error_patterns[next_err_idx];
220220
let mut done = false;
221221
for str::split_char(procres.stderr, '\n').each |line| {
222-
if str::contains(line, next_err_pat) {
222+
if str::contains(*line, next_err_pat) {
223223
debug!("found error pattern %s", next_err_pat);
224224
next_err_idx += 1u;
225225
if next_err_idx == vec::len(props.error_patterns) {
@@ -240,7 +240,7 @@ fn check_error_patterns(props: test_props,
240240
missing_patterns[0]), procres);
241241
} else {
242242
for missing_patterns.each |pattern| {
243-
error(fmt!("error pattern '%s' not found!", pattern));
243+
error(fmt!("error pattern '%s' not found!", *pattern));
244244
}
245245
fatal_procres(~"multiple error patterns not found", procres);
246246
}
@@ -273,10 +273,10 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
273273
for vec::eachi(expected_errors) |i, ee| {
274274
if !found_flags[i] {
275275
debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s",
276-
prefixes[i], ee.kind, ee.msg, line);
277-
if (str::starts_with(line, prefixes[i]) &&
278-
str::contains(line, ee.kind) &&
279-
str::contains(line, ee.msg)) {
276+
prefixes[i], ee.kind, ee.msg, *line);
277+
if (str::starts_with(*line, prefixes[i]) &&
278+
str::contains(*line, ee.kind) &&
279+
str::contains(*line, ee.msg)) {
280280
found_flags[i] = true;
281281
was_expected = true;
282282
break;
@@ -285,13 +285,13 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
285285
}
286286

287287
// ignore this msg which gets printed at the end
288-
if str::contains(line, ~"aborting due to") {
288+
if str::contains(*line, ~"aborting due to") {
289289
was_expected = true;
290290
}
291291

292-
if !was_expected && is_compiler_error_or_warning(line) {
292+
if !was_expected && is_compiler_error_or_warning(*line) {
293293
fatal_procres(fmt!("unexpected compiler error or warning: '%s'",
294-
line),
294+
*line),
295295
procres);
296296
}
297297
}

src/fuzzer/fuzzer.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn find_rust_files(files: &mut ~[Path], path: &Path) {
3333
&& !contains(path.to_str(), ~"compile-fail")
3434
&& !contains(path.to_str(), ~"build") {
3535
for os::list_dir_path(path).each |p| {
36-
find_rust_files(files, p);
36+
find_rust_files(files, *p);
3737
}
3838
}
3939
}
@@ -463,15 +463,15 @@ fn content_is_dangerous_to_run(code: ~str) -> bool {
463463
~"unsafe",
464464
~"log"]; // python --> rust pipe deadlock?
465465

466-
for dangerous_patterns.each |p| { if contains(code, p) { return true; } }
466+
for dangerous_patterns.each |p| { if contains(code, *p) { return true; } }
467467
return false;
468468
}
469469

470470
fn content_is_dangerous_to_compile(code: ~str) -> bool {
471471
let dangerous_patterns =
472472
~[~"xfail-test"];
473473

474-
for dangerous_patterns.each |p| { if contains(code, p) { return true; } }
474+
for dangerous_patterns.each |p| { if contains(code, *p) { return true; } }
475475
return false;
476476
}
477477

@@ -487,7 +487,7 @@ fn content_might_not_converge(code: ~str) -> bool {
487487
~"\n\n\n\n\n" // https://github.com/mozilla/rust/issues/850
488488
];
489489

490-
for confusing_patterns.each |p| { if contains(code, p) { return true; } }
490+
for confusing_patterns.each |p| { if contains(code, *p) { return true; } }
491491
return false;
492492
}
493493

@@ -502,7 +502,7 @@ fn file_might_not_converge(filename: &Path) -> bool {
502502

503503

504504
for confusing_files.each |f| {
505-
if contains(filename.to_str(), f) {
505+
if contains(filename.to_str(), *f) {
506506
return true;
507507
}
508508
}
@@ -540,8 +540,8 @@ fn check_roundtrip_convergence(code: @~str, maxIters: uint) {
540540
fn check_convergence(files: &[Path]) {
541541
error!("pp convergence tests: %u files", vec::len(files));
542542
for files.each |file| {
543-
if !file_might_not_converge(&file) {
544-
let s = @result::get(io::read_whole_file_str(&file));
543+
if !file_might_not_converge(file) {
544+
let s = @result::get(io::read_whole_file_str(file));
545545
if !content_might_not_converge(*s) {
546546
error!("pp converge: %s", file.to_str());
547547
// Change from 7u to 2u once
@@ -555,13 +555,13 @@ fn check_convergence(files: &[Path]) {
555555
fn check_variants(files: &[Path], cx: context) {
556556
for files.each |file| {
557557
if cx.mode == tm_converge &&
558-
file_might_not_converge(&file) {
558+
file_might_not_converge(file) {
559559
error!("Skipping convergence test based on\
560560
file_might_not_converge");
561561
loop;
562562
}
563563

564-
let s = @result::get(io::read_whole_file_str(&file));
564+
let s = @result::get(io::read_whole_file_str(file));
565565
if contains(*s, ~"#") {
566566
loop; // Macros are confusing
567567
}
@@ -572,11 +572,13 @@ fn check_variants(files: &[Path], cx: context) {
572572
loop;
573573
}
574574
575-
log(error, ~"check_variants: " + file.to_str());
575+
let file_str = file.to_str();
576+
577+
log(error, ~"check_variants: " + file_str);
576578
let sess = parse::new_parse_sess(option::None);
577579
let crate =
578580
parse::parse_crate_from_source_str(
579-
file.to_str(),
581+
file_str,
580582
s, ~[], sess);
581583
io::with_str_reader(*s, |rdr| {
582584
error!("%s",
@@ -586,12 +588,12 @@ fn check_variants(files: &[Path], cx: context) {
586588
syntax::parse::token::mk_fake_ident_interner(),
587589
sess.span_diagnostic,
588590
crate,
589-
file.to_str(),
591+
file_str,
590592
rdr, a,
591593
pprust::no_ann(),
592-
false) ))
594+
false)))
593595
});
594-
check_variants_of_ast(*crate, sess.cm, &file, cx);
596+
check_variants_of_ast(*crate, sess.cm, file, cx);
595597
}
596598
}
597599

src/libcore/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ mod tests {
678678
let mut x = 0;
679679
for l.each |i| {
680680
x += 1;
681-
if (i == 3) { break; }
681+
if (*i == 3) { break; }
682682
}
683683
assert x == 3;
684684
}

src/libcore/dvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<A: Copy> DVec<A> {
272272
}
273273
};
274274
275-
for ts.each |t| { vec::push(v, t) };
275+
for ts.each |t| { vec::push(v, *t) };
276276
v
277277
}
278278
}

src/libcore/iter-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use inst::{IMPL_T, EACH, SIZE_HINT};
77
export extensions;
88

99
impl<A> IMPL_T<A>: iter::BaseIter<A> {
10-
pure fn each(blk: fn(A) -> bool) { EACH(self, blk) }
10+
pure fn each(blk: fn(v: &A) -> bool) { EACH(self, blk) }
1111
pure fn size_hint() -> Option<uint> { SIZE_HINT(self) }
1212
}
1313

src/libcore/iter-trait/dlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ type IMPL_T<A> = dlist::DList<A>;
88
* e.g. breadth-first search with in-place enqueues), but removing the current
99
* node is forbidden.
1010
*/
11-
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
11+
pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
1212
let mut link = self.peek_n();
1313
while option::is_some(link) {
1414
let nobe = option::get(link);
1515
assert nobe.linked;
16-
if !f(nobe.data) { break; }
16+
if !f(&nobe.data) { break; }
1717
// Check (weakly) that the user didn't do a remove.
1818
if self.size == 0 {
1919
fail ~"The dlist became empty during iteration??"

src/libcore/iter-trait/dvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type IMPL_T<A> = dvec::DVec<A>;
66
*
77
* Attempts to access this dvec during iteration will fail.
88
*/
9-
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
9+
pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
1010
unsafe {
1111
do self.swap |v| {
1212
v.each(f);

src/libcore/iter-trait/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#[allow(non_camel_case_types)]
22
type IMPL_T<A> = Option<A>;
33

4-
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
4+
pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
55
match self {
66
None => (),
7-
Some(a) => { f(a); }
7+
Some(ref a) => { f(a); }
88
}
99
}
1010

0 commit comments

Comments
 (0)