From 2c9922aa491f406d0a17631ef2f0bfc0bbf85346 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 7 Aug 2013 14:29:29 +0200 Subject: [PATCH 01/23] Enable privacy check for enum methods. --- src/librustc/middle/privacy.rs | 1 + src/libsyntax/ext/base.rs | 20 +++++++------- src/libsyntax/opt_vec.rs | 24 ++++++++--------- src/test/auxiliary/xc_private_method_lib.rs | 30 ++++++++++++++++++--- src/test/compile-fail/xc-private-method.rs | 10 ++++++- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 9ffeb99ac3559..a4b88870b9739 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -403,6 +403,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, // Ditto match ty::get(ty::type_autoderef(tcx, ty::expr_ty(tcx, base))).sty { + ty_enum(id, _) | ty_struct(id, _) if id.crate != LOCAL_CRATE || !privileged_items.iter().any(|x| x == &(id.node)) => { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 6ed5ca3e402a8..6b27d23dffd4b 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -417,12 +417,12 @@ pub enum MapChain { // get the map from an env frame impl MapChain{ // Constructor. I don't think we need a zero-arg one. - fn new(init: ~HashMap) -> @mut MapChain { + pub fn new(init: ~HashMap) -> @mut MapChain { @mut BaseMapChain(init) } // add a new frame to the environment (functionally) - fn push_frame (@mut self) -> @mut MapChain { + pub fn push_frame (@mut self) -> @mut MapChain { @mut ConsMapChain(~HashMap::new() ,self) } @@ -432,7 +432,7 @@ impl MapChain{ // ugh: can't get this to compile with mut because of the // lack of flow sensitivity. - fn get_map<'a>(&'a self) -> &'a HashMap { + pub fn get_map<'a>(&'a self) -> &'a HashMap { match *self { BaseMapChain (~ref map) => map, ConsMapChain (~ref map,_) => map @@ -442,7 +442,7 @@ impl MapChain{ // traits just don't work anywhere...? //impl Map for MapChain { - fn contains_key (&self, key: &K) -> bool { + pub fn contains_key (&self, key: &K) -> bool { match *self { BaseMapChain (ref map) => map.contains_key(key), ConsMapChain (ref map,ref rest) => @@ -453,17 +453,17 @@ impl MapChain{ // should each_key and each_value operate on shadowed // names? I think not. // delaying implementing this.... - fn each_key (&self, _f: &fn (&K)->bool) { + pub fn each_key (&self, _f: &fn (&K)->bool) { fail!("unimplemented 2013-02-15T10:01"); } - fn each_value (&self, _f: &fn (&V) -> bool) { + pub fn each_value (&self, _f: &fn (&V) -> bool) { fail!("unimplemented 2013-02-15T10:02"); } // Returns a copy of the value that the name maps to. // Goes down the chain 'til it finds one (or bottom out). - fn find (&self, key: &K) -> Option<@V> { + pub fn find (&self, key: &K) -> Option<@V> { match self.get_map().find (key) { Some(ref v) => Some(**v), None => match *self { @@ -473,7 +473,7 @@ impl MapChain{ } } - fn find_in_topmost_frame(&self, key: &K) -> Option<@V> { + pub fn find_in_topmost_frame(&self, key: &K) -> Option<@V> { let map = match *self { BaseMapChain(ref map) => map, ConsMapChain(ref map,_) => map @@ -483,7 +483,7 @@ impl MapChain{ } // insert the binding into the top-level map - fn insert (&mut self, key: K, ext: @V) -> bool { + pub fn insert (&mut self, key: K, ext: @V) -> bool { // can't abstract over get_map because of flow sensitivity... match *self { BaseMapChain (~ref mut map) => map.insert(key, ext), @@ -495,7 +495,7 @@ impl MapChain{ // ... there are definitely some opportunities for abstraction // here that I'm ignoring. (e.g., manufacturing a predicate on // the maps in the chain, and using an abstract "find". - fn insert_into_frame(&mut self, key: K, ext: @V, n: K, pred: &fn(&@V)->bool) { + pub fn insert_into_frame(&mut self, key: K, ext: @V, n: K, pred: &fn(&@V)->bool) { match *self { BaseMapChain (~ref mut map) => { if satisfies_pred(map,&n,pred) { diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index 10603751a06d1..a6f6b9d48e2b7 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -36,7 +36,7 @@ pub fn from(t: ~[T]) -> OptVec { } impl OptVec { - fn push(&mut self, t: T) { + pub fn push(&mut self, t: T) { match *self { Vec(ref mut v) => { v.push(t); @@ -50,32 +50,32 @@ impl OptVec { *self = Vec(~[t]); } - fn map(&self, op: &fn(&T) -> U) -> OptVec { + pub fn map(&self, op: &fn(&T) -> U) -> OptVec { match *self { Empty => Empty, Vec(ref v) => Vec(v.map(op)) } } - fn map_consume(self, op: &fn(T) -> U) -> OptVec { + pub fn map_consume(self, op: &fn(T) -> U) -> OptVec { match self { Empty => Empty, Vec(v) => Vec(v.consume_iter().transform(op).collect()) } } - fn get<'a>(&'a self, i: uint) -> &'a T { + pub fn get<'a>(&'a self, i: uint) -> &'a T { match *self { Empty => fail!("Invalid index %u", i), Vec(ref v) => &v[i] } } - fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.len() == 0 } - fn len(&self) -> uint { + pub fn len(&self) -> uint { match *self { Empty => 0, Vec(ref v) => v.len() @@ -83,7 +83,7 @@ impl OptVec { } #[inline] - fn iter<'r>(&'r self) -> OptVecIterator<'r, T> { + pub fn iter<'r>(&'r self) -> OptVecIterator<'r, T> { match *self { Empty => OptVecIterator{iter: None}, Vec(ref v) => OptVecIterator{iter: Some(v.iter())} @@ -91,11 +91,11 @@ impl OptVec { } #[inline] - fn map_to_vec(&self, op: &fn(&T) -> B) -> ~[B] { + pub fn map_to_vec(&self, op: &fn(&T) -> B) -> ~[B] { self.iter().transform(op).collect() } - fn mapi_to_vec(&self, op: &fn(uint, &T) -> B) -> ~[B] { + pub fn mapi_to_vec(&self, op: &fn(uint, &T) -> B) -> ~[B] { let mut index = 0; self.map_to_vec(|a| { let i = index; @@ -113,7 +113,7 @@ pub fn take_vec(v: OptVec) -> ~[T] { } impl OptVec { - fn prepend(&self, t: T) -> OptVec { + pub fn prepend(&self, t: T) -> OptVec { let mut v0 = ~[t]; match *self { Empty => {} @@ -124,7 +124,7 @@ impl OptVec { } impl Eq for OptVec { - fn eq(&self, other: &OptVec) -> bool { + pub fn eq(&self, other: &OptVec) -> bool { // Note: cannot use #[deriving(Eq)] here because // (Empty, Vec(~[])) ought to be equal. match (self, other) { @@ -135,7 +135,7 @@ impl Eq for OptVec { } } - fn ne(&self, other: &OptVec) -> bool { + pub fn ne(&self, other: &OptVec) -> bool { !self.eq(other) } } diff --git a/src/test/auxiliary/xc_private_method_lib.rs b/src/test/auxiliary/xc_private_method_lib.rs index 05325c3b935c4..8290f62bada26 100644 --- a/src/test/auxiliary/xc_private_method_lib.rs +++ b/src/test/auxiliary/xc_private_method_lib.rs @@ -1,9 +1,33 @@ #[crate_type="lib"]; -pub struct Foo { +pub struct Struct { x: int } -impl Foo { - fn new() -> Foo { Foo { x: 1 } } +impl Struct { + fn static_meth_struct() -> Struct { + Struct { x: 1 } + } + + fn meth_struct(&self) -> int { + self.x + } +} + +pub enum Enum { + Variant1(int), + Variant2(int) +} + +impl Enum { + fn static_meth_enum() -> Enum { + Variant2(10) + } + + fn meth_enum(&self) -> int { + match *self { + Variant1(x) | + Variant2(x) => x + } + } } diff --git a/src/test/compile-fail/xc-private-method.rs b/src/test/compile-fail/xc-private-method.rs index e8777a0a9f256..8314755af3b3d 100644 --- a/src/test/compile-fail/xc-private-method.rs +++ b/src/test/compile-fail/xc-private-method.rs @@ -4,5 +4,13 @@ extern mod xc_private_method_lib; fn main() { - let _ = xc_private_method_lib::Foo::new(); //~ ERROR function `new` is private + // normal method on struct + let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~ ERROR method `meth_struct` is private + // static method on struct + let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR function `static_meth_struct` is private + + // normal method on enum + let _ = xc_private_method_lib::Variant1(20).meth_enum(); //~ ERROR method `meth_enum` is private + // static method on enum + let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR function `static_meth_enum` is private } From 828bfb2c61aaac93325b00737362769d045b6438 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Wed, 7 Aug 2013 22:07:24 +0400 Subject: [PATCH 02/23] Fix incorrect non-exhaustive matching for fixed length vecs Code like this is fixed now: ``` fn foo(p: [u8, ..4]) { match p { [a, b, c, d] => {} }; } ``` Invalid constructors are not reported as errors yet: ``` fn foo(p: [u8, ..4]) { match p { [_, _, _] => {} // this should be error [_, _, _, _, _, .._] => {} // and this _ => {} } } ``` Issue #8311 is partially fixed by this commit. Fixed-length arrays in let statement are not yet allowed: ``` let [a, b, c] = [1, 2, 3]; // still fails ``` --- doc/tutorial.md | 2 +- src/librustc/middle/check_match.rs | 26 +++++++++++++++++ .../borrowck-move-out-of-vec-tail.rs | 2 +- .../borrowck-vec-pattern-element-loan.rs | 6 ++-- .../borrowck-vec-pattern-nesting.rs | 14 +++++----- .../borrowck-vec-pattern-tail-element-loan.rs | 2 +- src/test/compile-fail/match-vec-fixed.rs | 16 +++++++++++ .../compile-fail/match-vec-unreachable.rs | 4 +-- src/test/run-pass/vec-matching-fixed.rs | 28 +++++++++++++++++++ src/test/run-pass/vec-matching.rs | 4 +-- src/test/run-pass/vec-tail-matching.rs | 2 +- 11 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 src/test/compile-fail/match-vec-fixed.rs create mode 100644 src/test/run-pass/vec-matching-fixed.rs diff --git a/doc/tutorial.md b/doc/tutorial.md index a5f2001eaf515..b721a3628c9b8 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1305,7 +1305,7 @@ match crayons[0] { A vector can be destructured using pattern matching: ~~~~ -let numbers: [int, ..3] = [1, 2, 3]; +let numbers: &[int] = &[1, 2, 3]; let score = match numbers { [] => 0, [a] => a * 10, diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 1b420b9c06a55..1422e17b059fd 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -255,6 +255,9 @@ pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful { } not_useful } + ty::ty_evec(_, ty::vstore_fixed(n)) => { + is_useful_specialized(cx, m, v, vec(n), n, left_ty) + } ty::ty_unboxed_vec(*) | ty::ty_evec(*) => { let max_len = do m.rev_iter().fold(0) |max_len, r| { match r[0].node { @@ -409,6 +412,29 @@ pub fn missing_ctor(cx: &MatchCheckCtxt, else if true_found { Some(val(const_bool(false))) } else { Some(val(const_bool(true))) } } + ty::ty_evec(_, ty::vstore_fixed(n)) => { + let mut missing = true; + let mut wrong = false; + for r in m.iter() { + match r[0].node { + pat_vec(ref before, ref slice, ref after) => { + let count = before.len() + after.len(); + if (count < n && slice.is_none()) || count > n { + wrong = true; + } + if count == n || (count < n && slice.is_some()) { + missing = false; + } + } + _ => {} + } + } + match (wrong, missing) { + (true, _) => Some(vec(n)), // should be compile-time error + (_, true) => Some(vec(n)), + _ => None + } + } ty::ty_unboxed_vec(*) | ty::ty_evec(*) => { // Find the lengths and slices of all vector patterns. diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs index 39a0e585ad2db..0f67d8a6d0c4b 100644 --- a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs @@ -6,7 +6,7 @@ struct Foo { } pub fn main() { - let x = [ + let x = ~[ Foo { string: ~"foo" }, Foo { string: ~"bar" }, Foo { string: ~"baz" } diff --git a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs index 7f98eba599654..ca20d68e4cdcb 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs @@ -1,5 +1,5 @@ fn a() -> &[int] { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let tail = match vec { [_, ..tail] => tail, //~ ERROR does not live long enough _ => fail!("a") @@ -8,7 +8,7 @@ fn a() -> &[int] { } fn b() -> &[int] { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let init = match vec { [..init, _] => init, //~ ERROR does not live long enough _ => fail!("b") @@ -17,7 +17,7 @@ fn b() -> &[int] { } fn c() -> &[int] { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let slice = match vec { [_, ..slice, _] => slice, //~ ERROR does not live long enough _ => fail!("c") diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index 36ae5f8820892..02ba1b9d2fffb 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -1,24 +1,24 @@ fn a() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [~ref _a] => { - vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed + vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed } _ => fail!("foo") } } fn b() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [.._b] => { - vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed + vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed } } } fn c() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [_a, .._b] => { //~^ ERROR cannot move out @@ -35,7 +35,7 @@ fn c() { } fn d() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [.._a, _b] => { //~^ ERROR cannot move out @@ -46,7 +46,7 @@ fn d() { } fn e() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [_a, _b, _c] => {} _ => {} diff --git a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs index e3e12a4a4168b..87511c34172cd 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs @@ -1,5 +1,5 @@ fn a() -> &int { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let tail = match vec { [_a, ..tail] => &tail[0], //~ ERROR borrowed value does not live long enough _ => fail!("foo") diff --git a/src/test/compile-fail/match-vec-fixed.rs b/src/test/compile-fail/match-vec-fixed.rs new file mode 100644 index 0000000000000..b3e139805a0d9 --- /dev/null +++ b/src/test/compile-fail/match-vec-fixed.rs @@ -0,0 +1,16 @@ +fn a() { + let v = [1, 2, 3]; + match v { + [_, _, _] => {} + [_, _, _] => {} //~ ERROR unreachable pattern + } + match v { + [_, 1, _] => {} + [_, 1, _] => {} //~ ERROR unreachable pattern + _ => {} + } +} + +fn main() { + a(); +} diff --git a/src/test/compile-fail/match-vec-unreachable.rs b/src/test/compile-fail/match-vec-unreachable.rs index 3930e7d219201..b557242af44c1 100644 --- a/src/test/compile-fail/match-vec-unreachable.rs +++ b/src/test/compile-fail/match-vec-unreachable.rs @@ -6,13 +6,13 @@ fn main() { _ => () } - match [~"foo", ~"bar", ~"baz"] { + match ~[~"foo", ~"bar", ~"baz"] { [a, _, _, .._] => { println(a); } [~"foo", ~"bar", ~"baz", ~"foo", ~"bar"] => { } //~ ERROR unreachable pattern _ => { } } - match ['a', 'b', 'c'] { + match ~['a', 'b', 'c'] { ['a', 'b', 'c', .._tail] => {} ['a', 'b', 'c'] => {} //~ ERROR unreachable pattern _ => {} diff --git a/src/test/run-pass/vec-matching-fixed.rs b/src/test/run-pass/vec-matching-fixed.rs new file mode 100644 index 0000000000000..234311dec3315 --- /dev/null +++ b/src/test/run-pass/vec-matching-fixed.rs @@ -0,0 +1,28 @@ +fn a() { + let x = [1, 2, 3]; + match x { + [1, 2, 4] => ::std::util::unreachable(), + [0, 2, 3, .._] => ::std::util::unreachable(), + [0, .._, 3] => ::std::util::unreachable(), + [0, .._] => ::std::util::unreachable(), + [1, 2, 3] => (), + [_, _, _] => ::std::util::unreachable(), + } + match x { + [.._] => (), + } + match x { + [_, _, _, .._] => (), + } + match x { + [a, b, c] => { + assert_eq!(1, a); + assert_eq!(2, b); + assert_eq!(3, c); + } + } +} + +pub fn main() { + a(); +} diff --git a/src/test/run-pass/vec-matching.rs b/src/test/run-pass/vec-matching.rs index 5e906fa265994..fb73c7e097dcf 100644 --- a/src/test/run-pass/vec-matching.rs +++ b/src/test/run-pass/vec-matching.rs @@ -1,5 +1,5 @@ fn a() { - let x = [1]; + let x = ~[1]; match x { [_, _, _, _, _, .._] => ::std::util::unreachable(), [.._, _, _, _, _] => ::std::util::unreachable(), @@ -13,7 +13,7 @@ fn a() { } fn b() { - let x = [1, 2, 3]; + let x = ~[1, 2, 3]; match x { [a, b, ..c] => { assert_eq!(a, 1); diff --git a/src/test/run-pass/vec-tail-matching.rs b/src/test/run-pass/vec-tail-matching.rs index 27f4fc833511a..6a60308f2e70f 100644 --- a/src/test/run-pass/vec-tail-matching.rs +++ b/src/test/run-pass/vec-tail-matching.rs @@ -3,7 +3,7 @@ struct Foo { } pub fn main() { - let x = [ + let x = ~[ Foo { string: ~"foo" }, Foo { string: ~"bar" }, Foo { string: ~"baz" } From 3596f666bb0255d249dbfa0a4ef0d273b63c5666 Mon Sep 17 00:00:00 2001 From: Paul Collins Date: Thu, 8 Aug 2013 18:48:04 +1200 Subject: [PATCH 03/23] rust-mode: make indentation customizable Add new variable rust-indent-offset, defaulting to the old value, and use it. --- src/etc/emacs/rust-mode.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index 87c505e69d0b9..ecb223f896c37 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -29,6 +29,11 @@ table)) +(defcustom rust-indent-offset default-tab-width + "*Indent Rust code by this number of spaces. + +The initializer is `DEFAULT-TAB-WIDTH'.") + (defun rust-paren-level () (nth 0 (syntax-ppss))) (defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss))) (defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss)))) @@ -49,10 +54,10 @@ (let ((level (rust-paren-level))) (cond ;; A function return type is 1 level indented - ((looking-at "->") (* default-tab-width (+ level 1))) + ((looking-at "->") (* rust-indent-offset (+ level 1))) ;; A closing brace is 1 level unindended - ((looking-at "}") (* default-tab-width (- level 1))) + ((looking-at "}") (* rust-indent-offset (- level 1))) ;; If we're in any other token-tree / sexp, then: ;; - [ or ( means line up with the opening token @@ -70,18 +75,18 @@ (goto-char pt) (back-to-indentation) (if (looking-at "\\") - (* default-tab-width (+ 1 level)) + (* rust-indent-offset (+ 1 level)) (progn (goto-char pt) (beginning-of-line) (rust-rewind-irrelevant) (end-of-line) (if (looking-back "[{};,]") - (* default-tab-width level) + (* rust-indent-offset level) (back-to-indentation) (if (looking-at "#") - (* default-tab-width level) - (* default-tab-width (+ 1 level)))))))))) + (* rust-indent-offset level) + (* rust-indent-offset (+ 1 level)))))))))) ;; Otherwise we're in a column-zero definition (t 0)))))) From b4fe85664536401e5ea68e6e7d1490b223843caa Mon Sep 17 00:00:00 2001 From: Maxim Kolganov Date: Fri, 9 Aug 2013 01:43:44 +0400 Subject: [PATCH 04/23] typo in tutorial --- doc/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 6e6b804aa9d34..dc481d714388b 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2195,7 +2195,7 @@ use std::float::consts::pi; # impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } } let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f}; -let mycircle: Circle = concrete as @Circle; +let mycircle: @Circle = concrete as @Circle; let nonsense = mycircle.radius() * mycircle.area(); ~~~ From 33c6d3fd7880df371151ec3e9a053b7169a181e5 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Aug 2013 13:28:06 -0400 Subject: [PATCH 05/23] Allow attributes to appear as macro arguments Fixes #8393 --- src/libsyntax/ext/tt/macro_parser.rs | 2 + src/libsyntax/parse/attr.rs | 131 ++++++++++-------- src/libsyntax/parse/lexer.rs | 6 +- src/libsyntax/parse/parser.rs | 14 +- src/libsyntax/parse/token.rs | 3 + .../compile-fail/macro-inner-attributes.rs | 21 +++ .../compile-fail/macro-outer-attributes.rs | 19 +++ 7 files changed, 137 insertions(+), 59 deletions(-) create mode 100644 src/test/compile-fail/macro-inner-attributes.rs create mode 100644 src/test/compile-fail/macro-outer-attributes.rs diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 5a1317034b221..918949113ad0c 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -17,6 +17,7 @@ use codemap; use parse::lexer::*; //resolve bug? use parse::ParseSess; use parse::parser::Parser; +use parse::attr::parser_attr; use parse::token::{Token, EOF, to_str, nonterminal, get_ident_interner, ident_to_str}; use parse::token; @@ -430,6 +431,7 @@ pub fn parse_nt(p: &Parser, name: &str) -> nonterminal { + token::to_str(get_ident_interner(), p.token)) }, "path" => token::nt_path(p.parse_path_with_tps(false)), + "attr" => token::nt_attr(@p.parse_attribute(false)), "tt" => { *p.quote_depth += 1u; //but in theory, non-quoted tts might be useful let res = token::nt_tt(@p.parse_token_tree()); diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 8cce5f15e67a8..f2489d80e1e69 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -9,21 +9,17 @@ // except according to those terms. use ast; -use codemap::spanned; +use codemap::{spanned, mk_sp}; use codemap::BytePos; use parse::common::*; //resolve bug? use parse::token; use parse::parser::Parser; +use parse::token::INTERPOLATED; // a parser that can parse attributes. pub trait parser_attr { fn parse_outer_attributes(&self) -> ~[ast::Attribute]; - fn parse_attribute(&self, style: ast::AttrStyle) -> ast::Attribute; - fn parse_attribute_naked( - &self, - style: ast::AttrStyle, - lo: BytePos - ) -> ast::Attribute; + fn parse_attribute(&self, permit_inner: bool) -> ast::Attribute; fn parse_inner_attrs_and_next(&self) -> (~[ast::Attribute], ~[ast::Attribute]); fn parse_meta_item(&self) -> @ast::MetaItem; @@ -37,12 +33,17 @@ impl parser_attr for Parser { fn parse_outer_attributes(&self) -> ~[ast::Attribute] { let mut attrs: ~[ast::Attribute] = ~[]; loop { + debug!("parse_outer_attributes: self.token=%?", + self.token); match *self.token { + token::INTERPOLATED(token::nt_attr(*)) => { + attrs.push(self.parse_attribute(false)); + } token::POUND => { if self.look_ahead(1, |t| *t != token::LBRACKET) { break; } - attrs.push(self.parse_attribute(ast::AttrOuter)); + attrs.push(self.parse_attribute(false)); } token::DOC_COMMENT(s) => { let attr = ::attr::mk_sugared_doc_attr( @@ -62,23 +63,49 @@ impl parser_attr for Parser { return attrs; } - // matches attribute = # attribute_naked - fn parse_attribute(&self, style: ast::AttrStyle) -> ast::Attribute { - let lo = self.span.lo; - self.expect(&token::POUND); - return self.parse_attribute_naked(style, lo); + // matches attribute = # [ meta_item ] + // + // if permit_inner is true, then a trailing `;` indicates an inner + // attribute + fn parse_attribute(&self, permit_inner: bool) -> ast::Attribute { + debug!("parse_attributes: permit_inner=%? self.token=%?", + permit_inner, self.token); + let (span, value) = match *self.token { + INTERPOLATED(token::nt_attr(attr)) => { + assert!(attr.node.style == ast::AttrOuter); + self.bump(); + (attr.span, attr.node.value) + } + token::POUND => { + let lo = self.span.lo; + self.bump(); + self.expect(&token::LBRACKET); + let meta_item = self.parse_meta_item(); + self.expect(&token::RBRACKET); + let hi = self.span.hi; + (mk_sp(lo, hi), meta_item) + } + _ => { + self.fatal(fmt!("expected `#` but found `%s`", + self.this_token_to_str())); + } + }; + let style = if permit_inner && *self.token == token::SEMI { + self.bump(); + ast::AttrInner + } else { + ast::AttrOuter + }; + return spanned { + span: span, + node: ast::Attribute_ { + style: style, + value: value, + is_sugared_doc: false + } + }; } - // matches attribute_naked = [ meta_item ] - fn parse_attribute_naked(&self, style: ast::AttrStyle, lo: BytePos) -> - ast::Attribute { - self.expect(&token::LBRACKET); - let meta_item = self.parse_meta_item(); - self.expect(&token::RBRACKET); - let hi = self.span.hi; - return spanned(lo, hi, ast::Attribute_ { style: style, - 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, // this function also returns a vector that may contain the first outer @@ -89,47 +116,37 @@ impl parser_attr for Parser { // matches inner_attrs* outer_attr? // you can make the 'next' field an Option, but the result is going to be // more useful as a vector. - fn parse_inner_attrs_and_next(&self) -> - (~[ast::Attribute], ~[ast::Attribute]) { + fn parse_inner_attrs_and_next(&self) + -> (~[ast::Attribute], ~[ast::Attribute]) { let mut inner_attrs: ~[ast::Attribute] = ~[]; let mut next_outer_attrs: ~[ast::Attribute] = ~[]; loop { - match *self.token { - token::POUND => { - if self.look_ahead(1, |t| *t != token::LBRACKET) { - // This is an extension - break; + let attr = match *self.token { + token::INTERPOLATED(token::nt_attr(*)) => { + self.parse_attribute(true) + } + token::POUND => { + if self.look_ahead(1, |t| *t != token::LBRACKET) { + // This is an extension + break; + } + self.parse_attribute(true) } - let attr = self.parse_attribute(ast::AttrInner); - if *self.token == token::SEMI { + token::DOC_COMMENT(s) => { self.bump(); - inner_attrs.push(attr); - } else { - // It's not really an inner attribute - let outer_attr = - spanned(attr.span.lo, attr.span.hi, - ast::Attribute_ { style: ast::AttrOuter, - value: attr.node.value, - is_sugared_doc: false }); - next_outer_attrs.push(outer_attr); - break; + ::attr::mk_sugared_doc_attr(self.id_to_str(s), + self.span.lo, + self.span.hi) } - } - token::DOC_COMMENT(s) => { - let attr = ::attr::mk_sugared_doc_attr( - self.id_to_str(s), - self.span.lo, - self.span.hi - ); - self.bump(); - if attr.node.style == ast::AttrInner { - inner_attrs.push(attr); - } else { - next_outer_attrs.push(attr); - break; + _ => { + break; } - } - _ => break + }; + if attr.node.style == ast::AttrInner { + inner_attrs.push(attr); + } else { + next_outer_attrs.push(attr); + break; } } (inner_attrs, next_outer_attrs) diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 49deafeda40bb..bde568b2610c2 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -129,7 +129,11 @@ impl reader for StringReader { impl reader for TtReader { fn is_eof(@mut self) -> bool { self.cur_tok == token::EOF } - fn next_token(@mut self) -> TokenAndSpan { tt_next_token(self) } + fn next_token(@mut self) -> TokenAndSpan { + let r = tt_next_token(self); + debug!("TtReader: r=%?", r); + return r; + } fn fatal(@mut self, m: ~str) -> ! { self.sp_diag.span_fatal(self.cur_span, m); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7d6dce22fb7b4..dcab89930dc56 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[macro_escape]; + use abi; use abi::AbiSet; use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil}; @@ -4452,7 +4454,17 @@ impl Parser { attrs: ~[Attribute], macros_allowed: bool) -> item_or_view_item { - maybe_whole!(iovi self, nt_item); + match *self.token { + INTERPOLATED(token::nt_item(item)) => { + self.bump(); + let new_attrs = vec::append(attrs, item.attrs); + return iovi_item(@ast::item { + attrs: new_attrs, + ..(*item).clone()}); + } + _ => {} + } + let lo = self.span.lo; let visibility = self.parse_non_priv_visibility(); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index fd491c1e890a0..c554f111bf9a0 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -105,6 +105,7 @@ pub enum nonterminal { nt_expr(@ast::expr), nt_ty( ast::Ty), nt_ident(ast::ident, bool), + nt_attr(@ast::Attribute), // #[foo] nt_path( ast::Path), nt_tt( @ast::token_tree), //needs @ed to break a circularity nt_matchers(~[ast::matcher]) @@ -205,6 +206,7 @@ pub fn to_str(input: @ident_interner, t: &Token) -> ~str { INTERPOLATED(ref nt) => { match nt { &nt_expr(e) => ::print::pprust::expr_to_str(e, input), + &nt_attr(e) => ::print::pprust::attribute_to_str(e, input), _ => { ~"an interpolated " + match (*nt) { @@ -212,6 +214,7 @@ pub fn to_str(input: @ident_interner, t: &Token) -> ~str { nt_block(*) => ~"block", nt_stmt(*) => ~"statement", nt_pat(*) => ~"pattern", + nt_attr(*) => fail!("should have been handled"), nt_expr(*) => fail!("should have been handled above"), nt_ty(*) => ~"type", nt_ident(*) => ~"identifier", diff --git a/src/test/compile-fail/macro-inner-attributes.rs b/src/test/compile-fail/macro-inner-attributes.rs new file mode 100644 index 0000000000000..95000f4aa229d --- /dev/null +++ b/src/test/compile-fail/macro-inner-attributes.rs @@ -0,0 +1,21 @@ +macro_rules! test ( ($nm:ident, + $a:attr, + $i:item) => (mod $nm { $a; $i }); ) + +test!(a, + #[cfg(qux)], + pub fn bar() { }) + +test!(b, + #[cfg(not(qux))], + pub fn bar() { }) + +#[qux] +fn main() { + a::bar(); + //~^ ERROR use of undeclared module `a` + //~^^ ERROR unresolved name + //~^^^ ERROR unresolved name `a::bar` + b::bar(); +} + diff --git a/src/test/compile-fail/macro-outer-attributes.rs b/src/test/compile-fail/macro-outer-attributes.rs new file mode 100644 index 0000000000000..23c3e80cd3b2b --- /dev/null +++ b/src/test/compile-fail/macro-outer-attributes.rs @@ -0,0 +1,19 @@ +macro_rules! test ( ($nm:ident, + $a:attr, + $i:item) => (mod $nm { $a $i }); ) + +test!(a, + #[cfg(qux)], + pub fn bar() { }) + +test!(b, + #[cfg(not(qux))], + pub fn bar() { }) + +// test1!(#[bar]) +#[qux] +fn main() { + a::bar(); //~ ERROR unresolved name `a::bar` + b::bar(); +} + From 2a2ea5e276cefa014e096f7fcefc9d98f944bbc5 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolov Date: Thu, 8 Aug 2013 02:37:13 +0400 Subject: [PATCH 06/23] Implement `lower_bound_iter`/`upper_bound_iter` for TrieMap/TrieSet --- src/libstd/trie.rs | 102 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 5ef5526e5162d..6c9221915179a 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -156,6 +156,53 @@ impl TrieMap { remaining_max: self.length } } + + // If `upper` is true then returns upper_bound else returns lower_bound. + #[inline] + fn bound_iter<'a>(&'a self, key: uint, upper: bool) -> TrieMapIterator<'a, T> { + let mut node: &'a TrieNode = &self.root; + let mut idx = 0; + let mut it = TrieMapIterator { + stack: ~[], + remaining_min: 0, + remaining_max: self.length + }; + loop { + let children = &node.children; + let child_id = chunk(key, idx); + match children[child_id] { + Internal(ref n) => { + node = &**n; + it.stack.push(children.slice_from(child_id + 1).iter()); + } + External(stored, _) => { + if stored < key || (upper && stored == key) { + it.stack.push(children.slice_from(child_id + 1).iter()); + } else { + it.stack.push(children.slice_from(child_id).iter()); + } + return it; + } + Nothing => { + it.stack.push(children.slice_from(child_id + 1).iter()); + return it + } + } + idx += 1; + } + } + + /// Get an iterator pointing to the first key-value pair whose key is not less than `key`. + /// If all keys in the map are less than `key` an empty iterator is returned. + pub fn lower_bound_iter<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> { + self.bound_iter(key, false) + } + + /// Get an iterator pointing to the first key-value pair whose key is greater than `key`. + /// If all keys in the map are not greater than `key` an empty iterator is returned. + pub fn upper_bound_iter<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> { + self.bound_iter(key, true) + } } impl> FromIterator<(uint, T), Iter> for TrieMap { @@ -233,6 +280,18 @@ impl TrieSet { pub fn iter<'a>(&'a self) -> TrieSetIterator<'a> { TrieSetIterator{iter: self.map.iter()} } + + /// Get an iterator pointing to the first value that is not less than `val`. + /// If all values in the set are less than `val` an empty iterator is returned. + pub fn lower_bound_iter<'a>(&'a self, val: uint) -> TrieSetIterator<'a> { + TrieSetIterator{iter: self.map.lower_bound_iter(val)} + } + + /// Get an iterator pointing to the first value that key is greater than `val`. + /// If all values in the set are not greater than `val` an empty iterator is returned. + pub fn upper_bound_iter<'a>(&'a self, val: uint) -> TrieSetIterator<'a> { + TrieSetIterator{iter: self.map.upper_bound_iter(val)} + } } impl> FromIterator for TrieSet { @@ -645,6 +704,49 @@ mod test_map { } assert_eq!(i, last - first); } + + #[test] + fn test_bound_iter() { + let empty_map : TrieMap = TrieMap::new(); + assert_eq!(empty_map.lower_bound_iter(0).next(), None); + assert_eq!(empty_map.upper_bound_iter(0).next(), None); + + let last = 999u; + let step = 3u; + let value = 42u; + + let mut map : TrieMap = TrieMap::new(); + do uint::range_step(0u, last, step as int) |x| { + assert!(x % step == 0); + map.insert(x, value); + true + }; + + for i in range(0u, last - step) { + let mut lb = map.lower_bound_iter(i); + let mut ub = map.upper_bound_iter(i); + let next_key = i - i % step + step; + let next_pair = (next_key, &value); + if (i % step == 0) { + assert_eq!(lb.next(), Some((i, &value))); + } else { + assert_eq!(lb.next(), Some(next_pair)); + } + assert_eq!(ub.next(), Some(next_pair)); + } + + let mut lb = map.lower_bound_iter(last - step); + assert_eq!(lb.next(), Some((last - step, &value))); + let mut ub = map.upper_bound_iter(last - step); + assert_eq!(ub.next(), None); + + for i in range(last - step + 1, last) { + let mut lb = map.lower_bound_iter(i); + assert_eq!(lb.next(), None); + let mut ub = map.upper_bound_iter(i); + assert_eq!(ub.next(), None); + } + } } #[cfg(test)] From 6362c3ad6b03ad20929313eee7613bf548d8c255 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 6 Aug 2013 16:50:58 -0700 Subject: [PATCH 07/23] Switch to using .enumerate() some places in _match. --- src/librustc/middle/trans/_match.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 327d2e698c1e1..6b7361f186cc4 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1075,13 +1075,13 @@ fn pick_col(m: &[Match]) -> uint { } let mut scores = vec::from_elem(m[0].pats.len(), 0u); for br in m.iter() { - let mut i = 0u; - for p in br.pats.iter() { scores[i] += score(*p); i += 1u; } + for (i, p) in br.pats.iter().enumerate() { + scores[i] += score(*p); + } } let mut max_score = 0u; let mut best_col = 0u; - let mut i = 0u; - for score in scores.iter() { + for (i, score) in scores.iter().enumerate() { let score = *score; // Irrefutable columns always go first, they'd only be duplicated in @@ -1090,7 +1090,6 @@ fn pick_col(m: &[Match]) -> uint { // If no irrefutable ones are found, we pick the one with the biggest // branching factor. if score > max_score { max_score = score; best_col = i; } - i += 1u; } return best_col; } @@ -1490,13 +1489,11 @@ fn compile_submatch_continue(mut bcx: @mut Block, let defaults = enter_default(else_cx, dm, m, col, val); let exhaustive = chk.is_none() && defaults.len() == 0u; let len = opts.len(); - let mut i = 0u; // Compile subtrees for each option - for opt in opts.iter() { - i += 1u; + for (i, opt) in opts.iter().enumerate() { let mut opt_cx = else_cx; - if !exhaustive || i < len { + if !exhaustive || i+1 < len { opt_cx = sub_block(bcx, "match_case"); match kind { single => Br(bcx, opt_cx.llbb), From fb32ddf1a2a54f7bfc4485485ee87b40f02af2f1 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Thu, 8 Aug 2013 15:19:19 -0700 Subject: [PATCH 08/23] Fix vector pattern matching. Closes #6909. --- src/librustc/middle/trans/_match.rs | 162 ++++++++++++++++---- src/test/run-pass/vec-matching-autoslice.rs | 10 +- src/test/run-pass/vec-matching.rs | 31 +++- 3 files changed, 159 insertions(+), 44 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 6b7361f186cc4..9c2a77da149a4 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -145,6 +145,51 @@ * - `store_non_ref_bindings()` * - `insert_lllocals()` * + * + * ## Notes on vector pattern matching. + * + * Vector pattern matching is surprisingly tricky. The problem is that + * the structure of the vector isn't fully known, and slice matches + * can be done on subparts of it. + * + * The way that vector pattern matches are dealt with, then, is as + * follows. First, we make the actual condition associated with a + * vector pattern simply a vector length comparison. So the pattern + * [1, .. x] gets the condition "vec len >= 1", and the pattern + * [.. x] gets the condition "vec len >= 0". The problem here is that + * having the condition "vec len >= 1" hold clearly does not mean that + * only a pattern that has exactly that condition will match. This + * means that it may well be the case that a condition holds, but none + * of the patterns matching that condition match; to deal with this, + * when doing vector length matches, we have match failures proceed to + * the next condition to check. + * + * There are a couple more subtleties to deal with. While the "actual" + * condition associated with vector length tests is simply a test on + * the vector length, the actual vec_len Opt entry contains more + * information used to restrict which matches are associated with it. + * So that all matches in a submatch are matching against the same + * values from inside the vector, they are split up by how many + * elements they match at the front and at the back of the vector. In + * order to make sure that arms are properly checked in order, even + * with the overmatching conditions, each vec_len Opt entry is + * associated with a range of matches. + * Consider the following: + * + * match &[1, 2, 3] { + * [1, 1, .. _] => 0, + * [1, 2, 2, .. _] => 1, + * [1, 2, 3, .. _] => 2, + * [1, 2, .. _] => 3, + * _ => 4 + * } + * The proper arm to match is arm 2, but arms 0 and 3 both have the + * condition "len >= 2". If arm 3 was lumped in with arm 0, then the + * wrong branch would be taken. Instead, vec_len Opts are associated + * with a contiguous range of matches that have the same "shape". + * This is sort of ugly and requires a bunch of special handling of + * vec_len options. + * */ @@ -189,14 +234,19 @@ enum Lit { ConstLit(ast::def_id), // the def ID of the constant } +#[deriving(Eq)] +pub enum VecLenOpt { + vec_len_eq, + vec_len_ge(/* length of prefix */uint) +} + // An option identifying a branch (either a literal, a enum variant or a // range) enum Opt { lit(Lit), var(/* disr val */ uint, @adt::Repr), range(@ast::expr, @ast::expr), - vec_len_eq(uint), - vec_len_ge(uint, /* slice */uint) + vec_len(/* length */ uint, VecLenOpt, /*range of matches*/(uint, uint)) } fn opt_eq(tcx: ty::ctxt, a: &Opt, b: &Opt) -> bool { @@ -247,9 +297,9 @@ fn opt_eq(tcx: ty::ctxt, a: &Opt, b: &Opt) -> bool { } } (&var(a, _), &var(b, _)) => a == b, - (&vec_len_eq(a), &vec_len_eq(b)) => a == b, - (&vec_len_ge(a, _), &vec_len_ge(b, _)) => a == b, - _ => false + (&vec_len(a1, a2, _), &vec_len(b1, b2, _)) => + a1 == b1 && a2 == b2, + _ => false } } @@ -283,10 +333,10 @@ fn trans_opt(bcx: @mut Block, o: &Opt) -> opt_result { return range_result(rslt(bcx, consts::const_expr(ccx, l1)), rslt(bcx, consts::const_expr(ccx, l2))); } - vec_len_eq(n) => { + vec_len(n, vec_len_eq, _) => { return single_result(rslt(bcx, C_int(ccx, n as int))); } - vec_len_ge(n, _) => { + vec_len(n, vec_len_ge(_), _) => { return lower_bound(rslt(bcx, C_int(ccx, n as int))); } } @@ -523,17 +573,19 @@ fn enter_opt<'r>(bcx: @mut Block, variant_size: uint, val: ValueRef) -> ~[Match<'r>] { - debug!("enter_opt(bcx=%s, m=%s, col=%u, val=%s)", + debug!("enter_opt(bcx=%s, m=%s, opt=%?, col=%u, val=%s)", bcx.to_str(), m.repr(bcx.tcx()), + *opt, col, bcx.val_to_str(val)); let _indenter = indenter(); let tcx = bcx.tcx(); let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()}; + let mut i = 0; do enter_match(bcx, tcx.def_map, m, col, val) |p| { - match p.node { + let answer = match p.node { ast::pat_enum(*) | ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => { let const_def = tcx.def_map.get_copy(&p.id); @@ -599,32 +651,53 @@ fn enter_opt<'r>(bcx: @mut Block, } } ast::pat_vec(ref before, slice, ref after) => { + let (lo, hi) = match *opt { + vec_len(_, _, (lo, hi)) => (lo, hi), + _ => tcx.sess.span_bug(p.span, + "vec pattern but not vec opt") + }; + match slice { - Some(slice) => { + Some(slice) if i >= lo && i <= hi => { let n = before.len() + after.len(); - let i = before.len(); - if opt_eq(tcx, &vec_len_ge(n, i), opt) { + let this_opt = vec_len(n, vec_len_ge(before.len()), + (lo, hi)); + if opt_eq(tcx, &this_opt, opt) { Some(vec::append_one((*before).clone(), slice) + *after) } else { None } } - None => { + None if i >= lo && i <= hi => { let n = before.len(); - if opt_eq(tcx, &vec_len_eq(n), opt) { + if opt_eq(tcx, &vec_len(n, vec_len_eq, (lo,hi)), opt) { Some((*before).clone()) } else { None } } + _ => None } } _ => { assert_is_binding_or_wild(bcx, p); - Some(vec::from_elem(variant_size, dummy)) + // In most cases, a binding/wildcard match be + // considered to match against any Opt. However, when + // doing vector pattern matching, submatches are + // considered even if the eventual match might be from + // a different submatch. Thus, when a submatch fails + // when doing a vector match, we proceed to the next + // submatch. Thus, including a default match would + // cause the default match to fire spuriously. + match *opt { + vec_len(*) => None, + _ => Some(vec::from_elem(variant_size, dummy)) + } } - } + }; + i += 1; + answer } } @@ -805,9 +878,25 @@ fn get_options(bcx: @mut Block, m: &[Match], col: uint) -> ~[Opt] { if set.iter().any(|l| opt_eq(tcx, l, &val)) {return;} set.push(val); } + // Vector comparisions are special in that since the actual + // conditions over-match, we need to be careful about them. This + // means that in order to properly handle things in order, we need + // to not always merge conditions. + fn add_veclen_to_set(set: &mut ~[Opt], i: uint, + len: uint, vlo: VecLenOpt) { + match set.last_opt() { + // If the last condition in the list matches the one we want + // to add, then extend its range. Otherwise, make a new + // vec_len with a range just covering the new entry. + Some(&vec_len(len2, vlo2, (start, end))) + if len == len2 && vlo == vlo2 => + set[set.len() - 1] = vec_len(len, vlo, (start, end+1)), + _ => set.push(vec_len(len, vlo, (i, i))) + } + } let mut found = ~[]; - for br in m.iter() { + for (i, br) in m.iter().enumerate() { let cur = br.pats[col]; match cur.node { ast::pat_lit(l) => { @@ -852,12 +941,12 @@ fn get_options(bcx: @mut Block, m: &[Match], col: uint) -> ~[Opt] { add_to_set(ccx.tcx, &mut found, range(l1, l2)); } ast::pat_vec(ref before, slice, ref after) => { - let opt = match slice { - None => vec_len_eq(before.len()), - Some(_) => vec_len_ge(before.len() + after.len(), - before.len()) + let (len, vec_opt) = match slice { + None => (before.len(), vec_len_eq), + Some(_) => (before.len() + after.len(), + vec_len_ge(before.len())) }; - add_to_set(ccx.tcx, &mut found, opt); + add_veclen_to_set(&mut found, i, len, vec_opt); } _ => {} } @@ -1459,7 +1548,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, test_val = Load(bcx, val); kind = compare; }, - vec_len_eq(*) | vec_len_ge(*) => { + vec_len(*) => { let vt = tvec::vec_types(bcx, node_id_type(bcx, pat_id)); let unboxed = load_if_immediate(bcx, val, vt.vec_ty); let (_, len) = tvec::get_base_and_len( @@ -1492,6 +1581,11 @@ fn compile_submatch_continue(mut bcx: @mut Block, // Compile subtrees for each option for (i, opt) in opts.iter().enumerate() { + // In some cases in vector pattern matching, we need to override + // the failure case so that instead of failing, it proceeds to + // try more matching. branch_chk, then, is the proper failure case + // for the current conditional branch. + let mut branch_chk = chk; let mut opt_cx = else_cx; if !exhaustive || i+1 < len { opt_cx = sub_block(bcx, "match_case"); @@ -1583,6 +1677,10 @@ fn compile_submatch_continue(mut bcx: @mut Block, } }; bcx = sub_block(after_cx, "compare_vec_len_next"); + + // If none of these subcases match, move on to the + // next condition. + branch_chk = Some::(|| bcx.llbb); CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb); } _ => () @@ -1601,17 +1699,13 @@ fn compile_submatch_continue(mut bcx: @mut Block, unpacked = argvals; opt_cx = new_bcx; } - vec_len_eq(n) | vec_len_ge(n, _) => { - let n = match *opt { - vec_len_ge(*) => n + 1u, - _ => n - }; - let slice = match *opt { - vec_len_ge(_, i) => Some(i), - _ => None + vec_len(n, vt, _) => { + let (n, slice) = match vt { + vec_len_ge(i) => (n + 1u, Some(i)), + vec_len_eq => (n, None) }; - let args = extract_vec_elems(opt_cx, pat_span, pat_id, n, slice, - val, test_val); + let args = extract_vec_elems(opt_cx, pat_span, pat_id, n, + slice, val, test_val); size = args.vals.len(); unpacked = args.vals.clone(); opt_cx = args.bcx; @@ -1620,7 +1714,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, } let opt_ms = enter_opt(opt_cx, m, opt, col, size, val); let opt_vals = vec::append(unpacked, vals_left); - compile_submatch(opt_cx, opt_ms, opt_vals, chk); + compile_submatch(opt_cx, opt_ms, opt_vals, branch_chk); } // Compile the fall-through case, if any diff --git a/src/test/run-pass/vec-matching-autoslice.rs b/src/test/run-pass/vec-matching-autoslice.rs index d04deeac52e31..13a8e324d4306 100644 --- a/src/test/run-pass/vec-matching-autoslice.rs +++ b/src/test/run-pass/vec-matching-autoslice.rs @@ -1,22 +1,22 @@ pub fn main() { let x = @[1, 2, 3]; match x { - [2, .._] => ::std::util::unreachable(), + [2, .._] => fail!(), [1, ..tail] => { assert_eq!(tail, [2, 3]); } - [_] => ::std::util::unreachable(), - [] => ::std::util::unreachable() + [_] => fail!(), + [] => fail!() } let y = (~[(1, true), (2, false)], 0.5); match y { - ([_, _, _], 0.5) => ::std::util::unreachable(), + ([_, _, _], 0.5) => fail!(), ([(1, a), (b, false), ..tail], _) => { assert_eq!(a, true); assert_eq!(b, 2); assert!(tail.is_empty()); } - ([..tail], _) => ::std::util::unreachable() + ([..tail], _) => fail!() } } diff --git a/src/test/run-pass/vec-matching.rs b/src/test/run-pass/vec-matching.rs index 5e906fa265994..2651630c3600e 100644 --- a/src/test/run-pass/vec-matching.rs +++ b/src/test/run-pass/vec-matching.rs @@ -1,14 +1,14 @@ fn a() { let x = [1]; match x { - [_, _, _, _, _, .._] => ::std::util::unreachable(), - [.._, _, _, _, _] => ::std::util::unreachable(), - [_, .._, _, _] => ::std::util::unreachable(), - [_, _] => ::std::util::unreachable(), + [_, _, _, _, _, .._] => fail!(), + [.._, _, _, _, _] => fail!(), + [_, .._, _, _] => fail!(), + [_, _] => fail!(), [a] => { assert_eq!(a, 1); } - [] => ::std::util::unreachable() + [] => fail!() } } @@ -48,7 +48,28 @@ fn b() { } } +fn c() { + let x = [1]; + match x { + [2, .. _] => fail!(), + [.. _] => () + } +} + +fn d() { + let x = [1, 2, 3]; + let branch = match x { + [1, 1, .. _] => 0, + [1, 2, 3, .. _] => 1, + [1, 2, .. _] => 2, + _ => 3 + }; + assert_eq!(branch, 1); +} + pub fn main() { a(); b(); + c(); + d(); } From 8cefcc0ac595a21674b1b33211a2e3b53afe31ce Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Fri, 9 Aug 2013 16:07:26 -0700 Subject: [PATCH 09/23] Fix some warnings. --- src/librustpkg/tests.rs | 2 +- src/libsyntax/ext/ifmt.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 9fea866212975..0e15238f0434f 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -12,7 +12,7 @@ use context::Ctx; use std::hashmap::HashMap; -use std::{io, libc, os, result, run, str}; +use std::{io, libc, os, run, str}; use extra::tempfile::mkdtemp; use std::run::ProcessOutput; use installed_packages::list_installed_packages; diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index 5cf5fdba632f4..8549b5795b28b 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -685,7 +685,7 @@ pub fn expand_syntax_ext(ecx: @ExtCtxt, sp: span, }; cx.fmtsp = efmt.span; let fmt = expr_to_str(ecx, efmt, - ~"first argument to ifmt! must be a string literal."); + "first argument to ifmt! must be a string literal."); let mut err = false; do parse::parse_error::cond.trap(|m| { From 437a4c28a338767bab9d003a80bcea38c658791b Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Fri, 9 Aug 2013 17:39:21 -0700 Subject: [PATCH 10/23] Fix interaction between default matches and guards. Closes #3121. --- src/librustc/middle/trans/_match.rs | 38 +++++++++++++++++++++++------ src/test/run-pass/issue-3121.rs | 1 - 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 9c2a77da149a4..a3164c6a8489d 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -521,10 +521,11 @@ fn enter_match<'r>(bcx: @mut Block, } fn enter_default<'r>(bcx: @mut Block, - dm: DefMap, - m: &[Match<'r>], - col: uint, - val: ValueRef) + dm: DefMap, + m: &[Match<'r>], + col: uint, + val: ValueRef, + chk: Option) -> ~[Match<'r>] { debug!("enter_default(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), @@ -533,13 +534,36 @@ fn enter_default<'r>(bcx: @mut Block, bcx.val_to_str(val)); let _indenter = indenter(); - do enter_match(bcx, dm, m, col, val) |p| { + // Collect all of the matches that can match against anything. + let matches = do enter_match(bcx, dm, m, col, val) |p| { match p.node { ast::pat_wild | ast::pat_tup(_) => Some(~[]), ast::pat_ident(_, _, None) if pat_is_binding(dm, p) => Some(~[]), _ => None } - } + }; + + // Ok, now, this is pretty subtle. A "default" match is a match + // that needs to be considered if none of the actual checks on the + // value being considered succeed. The subtlety lies in that sometimes + // identifier/wildcard matches are *not* default matches. Consider: + // "match x { _ if something => foo, true => bar, false => baz }". + // There is a wildcard match, but it is *not* a default case. The boolean + // case on the value being considered is exhaustive. If the case is + // exhaustive, then there are no defaults. + // + // We detect whether the case is exhaustive in the following + // somewhat kludgy way: if the last wildcard/binding match has a + // guard, then by non-redundancy, we know that there aren't any + // non guarded matches, and thus by exhaustiveness, we know that + // we don't need any default cases. If the check *isn't* nonexhaustive + // (because chk is Some), then we need the defaults anyways. + let is_exhaustive = match matches.last_opt() { + Some(m) if m.data.arm.guard.is_some() && chk.is_none() => true, + _ => false + }; + + if is_exhaustive { ~[] } else { matches } } // nmatsakis: what does enter_opt do? @@ -1575,7 +1599,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, C_int(ccx, 0) // Placeholder for when not using a switch }; - let defaults = enter_default(else_cx, dm, m, col, val); + let defaults = enter_default(else_cx, dm, m, col, val, chk); let exhaustive = chk.is_none() && defaults.len() == 0u; let len = opts.len(); diff --git a/src/test/run-pass/issue-3121.rs b/src/test/run-pass/issue-3121.rs index 522a68856b636..206dc383cb3d5 100644 --- a/src/test/run-pass/issue-3121.rs +++ b/src/test/run-pass/issue-3121.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test enum side { mayo, catsup, vinegar } enum order { hamburger, fries(side), shake } enum meal { to_go(order), for_here(order) } From fad7857c7b2c42da6081e593ab92d03d88643c81 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 7 Aug 2013 19:21:36 -0700 Subject: [PATCH 11/23] Mass rename of .consume{,_iter}() to .move_iter() cc #7887 --- src/libextra/dlist.rs | 28 ++++++------- src/libextra/json.rs | 6 +-- src/libextra/par.rs | 2 +- src/libextra/smallintmap.rs | 10 ++--- src/libextra/sort.rs | 2 +- src/libextra/test.rs | 6 +-- src/libextra/treemap.rs | 8 ++-- src/librustc/back/link.rs | 2 +- src/librustc/driver/driver.rs | 4 +- src/librustc/middle/astencode.rs | 2 +- src/librustc/middle/lint.rs | 2 +- src/librustc/middle/resolve.rs | 2 +- src/librustc/rustc.rs | 4 +- src/librustdoc/attr_parser.rs | 2 +- src/librusti/program.rs | 6 +-- src/librustpkg/workspace.rs | 2 +- src/libstd/at_vec.rs | 16 ++++---- src/libstd/either.rs | 2 +- src/libstd/hashmap.rs | 40 +++++++++---------- src/libstd/option.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/path.rs | 4 +- src/libstd/result.rs | 4 +- src/libstd/rt/kill.rs | 2 +- src/libstd/rt/mod.rs | 2 +- src/libstd/rt/select.rs | 6 +-- src/libstd/rt/test.rs | 2 +- src/libstd/task/spawn.rs | 10 ++--- src/libstd/unstable/extfmt.rs | 2 +- src/libstd/vec.rs | 40 +++++++++---------- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/attr.rs | 2 +- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/fmt.rs | 2 +- src/libsyntax/ext/ifmt.rs | 4 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/opt_vec.rs | 4 +- src/libsyntax/parse/parser.rs | 2 +- src/test/bench/graph500-bfs.rs | 6 +-- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +- src/test/bench/task-perf-one-million.rs | 6 +-- 41 files changed, 129 insertions(+), 129 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index b0839a55795b7..2158a90963bc9 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -63,7 +63,7 @@ pub struct MutDListIterator<'self, T> { /// DList consuming iterator #[deriving(Clone)] -pub struct ConsumeIterator { +pub struct MoveIterator { priv list: DList } @@ -391,14 +391,14 @@ impl DList { /// Consume the list into an iterator yielding elements by value #[inline] - pub fn consume_iter(self) -> ConsumeIterator { - ConsumeIterator{list: self} + pub fn move_iter(self) -> MoveIterator { + MoveIterator{list: self} } /// Consume the list into an iterator yielding elements by value, in reverse #[inline] - pub fn consume_rev_iter(self) -> Invert> { - self.consume_iter().invert() + pub fn move_rev_iter(self) -> Invert> { + self.move_iter().invert() } } @@ -557,7 +557,7 @@ impl<'self, A> ListInsertion for MutDListIterator<'self, A> { } } -impl Iterator for ConsumeIterator { +impl Iterator for MoveIterator { #[inline] fn next(&mut self) -> Option { self.list.pop_front() } @@ -567,7 +567,7 @@ impl Iterator for ConsumeIterator { } } -impl DoubleEndedIterator for ConsumeIterator { +impl DoubleEndedIterator for MoveIterator { #[inline] fn next_back(&mut self) -> Option { self.list.pop_back() } } @@ -721,7 +721,7 @@ mod tests { check_links(&m); let sum = v + u; assert_eq!(sum.len(), m.len()); - for elt in sum.consume_iter() { + for elt in sum.move_iter() { assert_eq!(m.pop_front(), Some(elt)) } } @@ -745,7 +745,7 @@ mod tests { check_links(&m); let sum = u + v; assert_eq!(sum.len(), m.len()); - for elt in sum.consume_iter() { + for elt in sum.move_iter() { assert_eq!(m.pop_front(), Some(elt)) } } @@ -770,7 +770,7 @@ mod tests { m.rotate_backward(); check_links(&m); m.push_front(9); check_links(&m); m.rotate_forward(); check_links(&m); - assert_eq!(~[3,9,5,1,2], m.consume_iter().collect()); + assert_eq!(~[3,9,5,1,2], m.move_iter().collect()); } #[test] @@ -900,7 +900,7 @@ mod tests { } check_links(&m); assert_eq!(m.len(), 3 + len * 2); - assert_eq!(m.consume_iter().collect::<~[int]>(), ~[-2,0,1,2,3,4,5,6,7,8,9,0,1]); + assert_eq!(m.move_iter().collect::<~[int]>(), ~[-2,0,1,2,3,4,5,6,7,8,9,0,1]); } #[test] @@ -911,7 +911,7 @@ mod tests { m.merge(n, |a, b| a <= b); assert_eq!(m.len(), len); check_links(&m); - let res = m.consume_iter().collect::<~[int]>(); + let res = m.move_iter().collect::<~[int]>(); assert_eq!(res, ~[-1, 0, 0, 0, 1, 3, 5, 6, 7, 2, 7, 7, 9]); } @@ -927,7 +927,7 @@ mod tests { m.push_back(4); m.insert_ordered(3); check_links(&m); - assert_eq!(~[2,3,4], m.consume_iter().collect::<~[int]>()); + assert_eq!(~[2,3,4], m.move_iter().collect::<~[int]>()); } #[test] @@ -1003,7 +1003,7 @@ mod tests { check_links(&m); let mut i = 0u; - for (a, &b) in m.consume_iter().zip(v.iter()) { + for (a, &b) in m.move_iter().zip(v.iter()) { i += 1; assert_eq!(a, b); } diff --git a/src/libextra/json.rs b/src/libextra/json.rs index ec9cb902d3d29..2287384b53a0e 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -948,7 +948,7 @@ impl serialize::Decoder for Decoder { let name = match self.stack.pop() { String(s) => s, List(list) => { - for v in list.consume_rev_iter() { + for v in list.move_rev_iter() { self.stack.push(v); } match self.stack.pop() { @@ -1066,7 +1066,7 @@ impl serialize::Decoder for Decoder { let len = match self.stack.pop() { List(list) => { let len = list.len(); - for v in list.consume_rev_iter() { + for v in list.move_rev_iter() { self.stack.push(v); } len @@ -1086,7 +1086,7 @@ impl serialize::Decoder for Decoder { let len = match self.stack.pop() { Object(obj) => { let len = obj.len(); - for (key, value) in obj.consume_iter() { + for (key, value) in obj.move_iter() { self.stack.push(value); self.stack.push(String(key)); } diff --git a/src/libextra/par.rs b/src/libextra/par.rs index 4069c68e71c11..bb79b5c8b95df 100644 --- a/src/libextra/par.rs +++ b/src/libextra/par.rs @@ -77,7 +77,7 @@ fn map_slices( info!("num_tasks: %?", (num_tasks, futures.len())); assert_eq!(num_tasks, futures.len()); - do futures.consume_iter().transform |ys| { + do futures.move_iter().transform |ys| { let mut ys = ys; ys.get() }.collect() diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index a601270e8ece1..a1f3cd4f5487d 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -152,12 +152,12 @@ impl SmallIntMap { } /// Empties the hash map, moving all values into the specified closure - pub fn consume(&mut self) + pub fn move_iter(&mut self) -> FilterMap<(uint, Option), (uint, V), - Enumerate>>> + Enumerate>>> { let values = replace(&mut self.v, ~[]); - values.consume_iter().enumerate().filter_map(|(i, v)| { + values.move_iter().enumerate().filter_map(|(i, v)| { v.map_move(|v| (i, v)) }) } @@ -452,11 +452,11 @@ mod test_map { } #[test] - fn test_consume() { + fn test_move_iter() { let mut m = SmallIntMap::new(); m.insert(1, ~2); let mut called = false; - for (k, v) in m.consume() { + for (k, v) in m.move_iter() { assert!(!called); called = true; assert_eq!(k, 1); diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index daafdbc37182d..c7920e7270890 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -893,7 +893,7 @@ mod tests { fn ile(x: &(&'static str), y: &(&'static str)) -> bool { // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use - // to_ascii_consume and to_str_consume to not do a unnecessary clone. + // to_ascii_move and to_str_move to not do a unnecessary clone. // (Actually, could just remove the to_str_* call, but needs an deriving(Ord) on // Ascii) let x = x.to_ascii().to_lower().to_str_ascii(); diff --git a/src/libextra/test.rs b/src/libextra/test.rs index bd811aa0f90d7..6adef685d9599 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -698,7 +698,7 @@ fn run_tests(opts: &TestOpts, // All benchmarks run at the end, in serial. // (this includes metric fns) - for b in filtered_benchs_and_metrics.consume_iter() { + for b in filtered_benchs_and_metrics.move_iter() { callback(TeWait(b.desc.clone())); run_test(!opts.run_benchmarks, b, ch.clone()); let (test, result) = p.recv(); @@ -744,7 +744,7 @@ pub fn filter_tests( } } - filtered.consume_iter().filter_map(|x| filter_fn(x, filter_str)).collect() + filtered.move_iter().filter_map(|x| filter_fn(x, filter_str)).collect() }; // Maybe pull out the ignored test and unignore them @@ -762,7 +762,7 @@ pub fn filter_tests( None } }; - filtered.consume_iter().filter_map(|x| filter(x)).collect() + filtered.move_iter().filter_map(|x| filter(x)).collect() }; // Sort the tests alphabetically diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 4d898dfb2b4f0..6e63b74449f0a 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -213,13 +213,13 @@ impl TreeMap { } /// Get a lazy iterator that consumes the treemap. - pub fn consume_iter(self) -> TreeMapConsumeIterator { + pub fn move_iter(self) -> TreeMapMoveIterator { let TreeMap { root: root, length: length } = self; let stk = match root { None => ~[], Some(~tn) => ~[tn] }; - TreeMapConsumeIterator { + TreeMapMoveIterator { stack: stk, remaining: length } @@ -331,12 +331,12 @@ fn iter_traverse_complete<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) { } /// Lazy forward iterator over a map that consumes the map while iterating -pub struct TreeMapConsumeIterator { +pub struct TreeMapMoveIterator { priv stack: ~[TreeNode], priv remaining: uint } -impl Iterator<(K, V)> for TreeMapConsumeIterator { +impl Iterator<(K, V)> for TreeMapMoveIterator { #[inline] fn next(&mut self) -> Option<(K, V)> { while !self.stack.is_empty() { diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index fbe17fb0d1c9e..5da769a60d75c 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -935,7 +935,7 @@ pub fn link_args(sess: Session, // Add all the link args for external crates. do cstore::iter_crate_data(cstore) |crate_num, _| { let link_args = csearch::get_link_args_for_crate(cstore, crate_num); - for link_arg in link_args.consume_iter() { + for link_arg in link_args.move_iter() { args.push(link_arg); } } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index e349502d143c0..dce632bd9d6bb 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -120,7 +120,7 @@ pub fn build_configuration(sess: Session, argv0: @str, input: &input) -> // Convert strings provided as --cfg [cfgspec] into a crate_cfg fn parse_cfgspecs(cfgspecs: ~[~str], demitter: diagnostic::Emitter) -> ast::CrateConfig { - do cfgspecs.consume_iter().transform |s| { + do cfgspecs.move_iter().transform |s| { let sess = parse::new_parse_sess(Some(demitter)); parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess) }.collect::() @@ -631,7 +631,7 @@ pub fn build_session_options(binary: @str, let level_name = lint::level_to_str(*level); // 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. + // to_ascii_move and to_str_move to not do a unnecessary copy. let level_short = level_name.slice_chars(0, 1); let level_short = level_short.to_ascii().to_upper().to_str_ascii(); let flags = vec::append(getopts::opt_strs(matches, level_short), diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index b909f70440a82..8a7894efb915d 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1204,7 +1204,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, } c::tag_table_capture_map => { let cvars = - at_vec::to_managed_consume( + at_vec::to_managed_move( val_dsr.read_to_vec( |val_dsr| val_dsr.read_capture_var(xcx))); dcx.maps.capture_map.insert(id, cvars); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index bbcb40df77528..3a15cbe0f5221 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -994,7 +994,7 @@ fn lint_session(cx: @mut Context) -> @visit::Visitor<()> { match cx.tcx.sess.lints.pop(&id) { None => {}, Some(l) => { - for (lint, span, msg) in l.consume_iter() { + for (lint, span, msg) in l.move_iter() { cx.span_lint(lint, span, msg) } } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 7d892d976769f..4d95909404e18 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -5366,7 +5366,7 @@ impl Resolver { if idents.len() == 0 { return ~"???"; } - return self.idents_to_str(idents.consume_rev_iter().collect::<~[ast::ident]>()); + return self.idents_to_str(idents.move_rev_iter().collect::<~[ast::ident]>()); } pub fn dump_module(@mut self, module_: @mut Module) { diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 0c476686af95d..668aaff35bb88 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -156,7 +156,7 @@ Available lint options: "); let lint_dict = lint::get_lint_dict(); - let mut lint_dict = lint_dict.consume() + let mut lint_dict = lint_dict.move_iter() .transform(|(k, v)| (v, k)) .collect::<~[(lint::LintSpec, &'static str)]>(); lint_dict.qsort(); @@ -173,7 +173,7 @@ Available lint options: padded(max_key, "name"), "default", "meaning"); printfln!(" %s %7.7s %s\n", padded(max_key, "----"), "-------", "-------"); - for (spec, name) in lint_dict.consume_iter() { + for (spec, name) in lint_dict.move_iter() { let name = name.replace("_", "-"); printfln!(" %s %7.7s %s", padded(max_key, name), diff --git a/src/librustdoc/attr_parser.rs b/src/librustdoc/attr_parser.rs index f8eff69cc8f3e..f1d6b7285e88f 100644 --- a/src/librustdoc/attr_parser.rs +++ b/src/librustdoc/attr_parser.rs @@ -41,7 +41,7 @@ pub fn parse_crate(attrs: ~[ast::Attribute]) -> CrateAttrs { } pub fn parse_desc(attrs: ~[ast::Attribute]) -> Option<~str> { - let doc_strs = do doc_metas(attrs).consume_iter().filter_map |meta| { + let doc_strs = do doc_metas(attrs).move_iter().filter_map |meta| { meta.value_str() }.collect::<~[@str]>(); if doc_strs.is_empty() { diff --git a/src/librusti/program.rs b/src/librusti/program.rs index d8a640bc19cf9..07af301260148 100644 --- a/src/librusti/program.rs +++ b/src/librusti/program.rs @@ -167,7 +167,7 @@ impl Program { } let newvars = util::replace(&mut self.newvars, HashMap::new()); - for (name, var) in newvars.consume() { + for (name, var) in newvars.move_iter() { self.local_vars.insert(name, var); } @@ -233,7 +233,7 @@ impl Program { pub fn consume_cache(&mut self) { let map = local_data::pop(tls_key).expect("tls is empty"); let cons_map = util::replace(map, HashMap::new()); - for (name, value) in cons_map.consume() { + for (name, value) in cons_map.move_iter() { match self.local_vars.find_mut(&name) { Some(v) => { v.data = (*value).clone(); } None => { fail!("unknown variable %s", name) } @@ -345,7 +345,7 @@ impl Program { // I'm not an @ pointer, so this has to be done outside. let cons_newvars = util::replace(newvars, HashMap::new()); - for (k, v) in cons_newvars.consume() { + for (k, v) in cons_newvars.move_iter() { self.newvars.insert(k, v); } diff --git a/src/librustpkg/workspace.rs b/src/librustpkg/workspace.rs index 3e0e08dfe2d7c..6ac959e4a3260 100644 --- a/src/librustpkg/workspace.rs +++ b/src/librustpkg/workspace.rs @@ -37,7 +37,7 @@ pub fn each_pkg_parent_workspace(pkgid: &PkgId, action: &fn(&Path) -> bool) -> b } pub fn pkg_parent_workspaces(pkgid: &PkgId) -> ~[Path] { - rust_path().consume_iter() + rust_path().move_iter() .filter(|ws| workspace_contains_package_id(pkgid, ws)) .collect() } diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 786548c064234..c948074990a36 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -141,11 +141,11 @@ pub fn from_elem(n_elts: uint, t: T) -> @[T] { * Creates and initializes an immutable managed vector by moving all the * elements from an owned vector. */ -pub fn to_managed_consume(v: ~[T]) -> @[T] { +pub fn to_managed_move(v: ~[T]) -> @[T] { let mut av = @[]; unsafe { raw::reserve(&mut av, v.len()); - for x in v.consume_iter() { + for x in v.move_iter() { raw::push(&mut av, x); } av @@ -331,12 +331,12 @@ mod test { } #[test] - fn test_to_managed_consume() { - assert_eq!(to_managed_consume::(~[]), @[]); - assert_eq!(to_managed_consume(~[true]), @[true]); - assert_eq!(to_managed_consume(~[1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); - assert_eq!(to_managed_consume(~[~"abc", ~"123"]), @[~"abc", ~"123"]); - assert_eq!(to_managed_consume(~[~[42]]), @[~[42]]); + fn test_to_managed_move() { + assert_eq!(to_managed_move::(~[]), @[]); + assert_eq!(to_managed_move(~[true]), @[true]); + assert_eq!(to_managed_move(~[1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); + assert_eq!(to_managed_move(~[~"abc", ~"123"]), @[~"abc", ~"123"]); + assert_eq!(to_managed_move(~[~[42]]), @[~[42]]); } #[test] diff --git a/src/libstd/either.rs b/src/libstd/either.rs index bb74d9b3ec484..132ebc7296011 100644 --- a/src/libstd/either.rs +++ b/src/libstd/either.rs @@ -150,7 +150,7 @@ pub fn rights(eithers: &[Either]) -> ~[R] { pub fn partition(eithers: ~[Either]) -> (~[L], ~[R]) { let mut lefts: ~[L] = ~[]; let mut rights: ~[R] = ~[]; - for elt in eithers.consume_iter() { + for elt in eithers.move_iter() { match elt { Left(l) => lefts.push(l), Right(r) => rights.push(r) diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 84cba254dcf23..e7b33ce80fa9c 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -159,8 +159,8 @@ impl HashMap { vec::from_fn(new_capacity, |_| None)); self.size = 0; - // consume_rev_iter is more efficient - for bucket in old_buckets.consume_rev_iter() { + // move_rev_iter is more efficient + for bucket in old_buckets.move_rev_iter() { self.insert_opt_bucket(bucket); } } @@ -470,9 +470,9 @@ impl HashMap { /// Creates a consuming iterator, that is, one that moves each key-value /// pair out of the map in arbitrary order. The map cannot be used after /// calling this. - pub fn consume(self) -> HashMapConsumeIterator { - // `consume_rev_iter` is more efficient than `consume_iter` for vectors - HashMapConsumeIterator {iter: self.buckets.consume_rev_iter()} + pub fn move_iter(self) -> HashMapMoveIterator { + // `move_rev_iter` is more efficient than `move_iter` for vectors + HashMapMoveIterator {iter: self.buckets.move_rev_iter()} } } @@ -524,9 +524,9 @@ pub struct HashMapMutIterator<'self, K, V> { priv iter: vec::VecMutIterator<'self, Option>>, } -/// HashMap consume iterator -pub struct HashMapConsumeIterator { - priv iter: vec::ConsumeRevIterator>>, +/// HashMap move iterator +pub struct HashMapMoveIterator { + priv iter: vec::MoveRevIterator>>, } /// HashSet iterator @@ -535,9 +535,9 @@ pub struct HashSetIterator<'self, K> { priv iter: vec::VecIterator<'self, Option>>, } -/// HashSet consume iterator -pub struct HashSetConsumeIterator { - priv iter: vec::ConsumeRevIterator>>, +/// HashSet move iterator +pub struct HashSetMoveIterator { + priv iter: vec::MoveRevIterator>>, } impl<'self, K, V> Iterator<(&'self K, &'self V)> for HashMapIterator<'self, K, V> { @@ -566,7 +566,7 @@ impl<'self, K, V> Iterator<(&'self K, &'self mut V)> for HashMapMutIterator<'sel } } -impl Iterator<(K, V)> for HashMapConsumeIterator { +impl Iterator<(K, V)> for HashMapMoveIterator { #[inline] fn next(&mut self) -> Option<(K, V)> { for elt in self.iter { @@ -592,7 +592,7 @@ impl<'self, K> Iterator<&'self K> for HashSetIterator<'self, K> { } } -impl Iterator for HashSetConsumeIterator { +impl Iterator for HashSetMoveIterator { #[inline] fn next(&mut self) -> Option { for elt in self.iter { @@ -707,9 +707,9 @@ impl HashSet { /// Creates a consuming iterator, that is, one that moves each value out /// of the set in arbitrary order. The set cannot be used after calling /// this. - pub fn consume(self) -> HashSetConsumeIterator { - // `consume_rev_iter` is more efficient than `consume_iter` for vectors - HashSetConsumeIterator {iter: self.map.buckets.consume_rev_iter()} + pub fn move_iter(self) -> HashSetMoveIterator { + // `move_rev_iter` is more efficient than `move_iter` for vectors + HashSetMoveIterator {iter: self.map.buckets.move_rev_iter()} } /// Visit the values representing the difference @@ -881,7 +881,7 @@ mod test_map { } #[test] - fn test_consume() { + fn test_move_iter() { let hm = { let mut hm = HashMap::new(); @@ -891,7 +891,7 @@ mod test_map { hm }; - let v = hm.consume().collect::<~[(char, int)]>(); + let v = hm.move_iter().collect::<~[(char, int)]>(); assert!([('a', 1), ('b', 2)] == v || [('b', 2), ('a', 1)] == v); } @@ -1177,7 +1177,7 @@ mod test_set { } #[test] - fn test_consume() { + fn test_move_iter() { let hs = { let mut hs = HashSet::new(); @@ -1187,7 +1187,7 @@ mod test_set { hs }; - let v = hs.consume().collect::<~[char]>(); + let v = hs.move_iter().collect::<~[char]>(); assert!(['a', 'b'] == v || ['b', 'a'] == v); } } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 66b30d8dd031c..c1999ae47d61a 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -134,7 +134,7 @@ impl Option { /// Return a consuming iterator over the possibly contained value #[inline] - pub fn consume(self) -> OptionIterator { + pub fn move_iter(self) -> OptionIterator { OptionIterator{opt: self} } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 008d59d537677..9ade21a4ede07 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -765,7 +765,7 @@ pub fn list_dir(p: &Path) -> ~[~str] { strings } } - do get_list(p).consume_iter().filter |filename| { + do get_list(p).move_iter().filter |filename| { "." != *filename && ".." != *filename }.collect() } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 14844e24006c5..fb8f8fc7b67d5 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -961,7 +961,7 @@ impl GenericPath for WindowsPath { match self.filestem() { Some(stem) => { // 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. + // to_ascii_move and to_str_move to not do a unnecessary copy. match stem.to_ascii().to_lower().to_str_ascii() { ~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" | ~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true, @@ -1020,7 +1020,7 @@ impl GenericPath for WindowsPath { None => None, // 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. + // to_ascii_move and to_str_move to not do a unnecessary copy. Some(ref device) => Some(device.to_ascii().to_upper().to_str_ascii()) }, is_absolute: self.is_absolute, diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 3e429c6116d4c..9de5e69148ae9 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -94,7 +94,7 @@ impl Result { match *self { Ok(ref t) => Some(t), Err(*) => None, - }.consume() + }.move_iter() } /// Call a method based on a previous result @@ -108,7 +108,7 @@ impl Result { match *self { Ok(*) => None, Err(ref t) => Some(t), - }.consume() + }.move_iter() } /// Unwraps a result, yielding the content of an `Ok`. diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index e07cb1425bf75..26c6c9119a17b 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -239,7 +239,7 @@ impl BlockedTask { }; // Even if the task was unkillable before, we use 'Killable' because // multiple pipes will have handles. It does not really mean killable. - handles.consume_iter().transform(|x| Killable(x)).collect() + handles.move_iter().transform(|x| Killable(x)).collect() } // This assertion has two flavours because the wake involves an atomic op. diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 348345f61fcd7..91297af5c935c 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -391,7 +391,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { rtdebug!("waiting for threads"); // Wait for schedulers - for thread in threads.consume_iter() { + for thread in threads.move_iter() { thread.join(); } diff --git a/src/libstd/rt/select.rs b/src/libstd/rt/select.rs index 0e8d26e9482ba..bde703af31580 100644 --- a/src/libstd/rt/select.rs +++ b/src/libstd/rt/select.rs @@ -54,7 +54,7 @@ pub fn select(ports: &mut [A]) -> uint { let task_handles = task.make_selectable(ports.len()); for (index, (port, task_handle)) in - ports.mut_iter().zip(task_handles.consume_iter()).enumerate() { + ports.mut_iter().zip(task_handles.move_iter()).enumerate() { // If one of the ports has data by now, it will wake the handle. if port.block_on(sched, task_handle) { ready_index = index; @@ -128,7 +128,7 @@ mod test { let (ports, chans) = unzip(from_fn(num_ports, |_| oneshot::<()>())); let mut dead_chans = ~[]; let mut ports = ports; - for (i, chan) in chans.consume_iter().enumerate() { + for (i, chan) in chans.move_iter().enumerate() { if send_on_chans.contains(&i) { chan.send(()); } else { @@ -145,7 +145,7 @@ mod test { let (ports, chans) = unzip(from_fn(num_ports, |_| stream::<()>())); let mut dead_chans = ~[]; let mut ports = ports; - for (i, chan) in chans.consume_iter().enumerate() { + for (i, chan) in chans.move_iter().enumerate() { if send_on_chans.contains(&i) { chan.send(()); } else { diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 92366d5187fe2..ca94468e1adae 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -232,7 +232,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { } // Wait for schedulers - for thread in threads.consume_iter() { + for thread in threads.move_iter() { thread.join(); } } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 1a38dfc3d8888..10bac9325ab43 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -79,7 +79,7 @@ use cast; use cell::Cell; use container::MutableMap; use comm::{Chan, GenericChan, oneshot}; -use hashmap::{HashSet, HashSetConsumeIterator}; +use hashmap::{HashSet, HashSetMoveIterator}; use local_data; use task::{Failure, SingleThreaded}; use task::{Success, TaskOpts, TaskResult}; @@ -141,8 +141,8 @@ impl TaskSet { assert!(was_present); } #[inline] - fn consume(self) -> HashSetConsumeIterator { - (*self).consume() + fn move_iter(self) -> HashSetMoveIterator { + (*self).move_iter() } } @@ -460,13 +460,13 @@ fn kill_taskgroup(state: TaskGroupInner, me: &TaskHandle, is_main: bool) { if newstate.is_some() { let TaskGroupData { members: members, descendants: descendants } = newstate.unwrap(); - for sibling in members.consume() { + for sibling in members.move_iter() { // Skip self - killing ourself won't do much good. if &sibling != me { RuntimeGlue::kill_task(sibling); } } - for child in descendants.consume() { + for child in descendants.move_iter() { assert!(&child != me); RuntimeGlue::kill_task(child); } diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs index d63f914bc7386..7b1f0e8ced8f2 100644 --- a/src/libstd/unstable/extfmt.rs +++ b/src/libstd/unstable/extfmt.rs @@ -526,7 +526,7 @@ pub mod rt { TyHexLower => uint_to_str_prec(u, 16, prec), // 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. + // to_ascii_move and to_str_move to not do a unnecessary copy. TyHexUpper => { let s = uint_to_str_prec(u, 16, prec); s.to_ascii().to_upper().to_str_ascii() diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 0f6d94bb77107..60abe65f94dfe 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -382,7 +382,7 @@ pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { pub fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { let mut ts = ~[]; let mut us = ~[]; - for p in v.consume_iter() { + for p in v.move_iter() { let (t, u) = p; ts.push(t); us.push(u); @@ -1174,8 +1174,8 @@ impl<'self,T:Clone> ImmutableCopyableVector for &'self [T] { #[allow(missing_doc)] pub trait OwnedVector { - fn consume_iter(self) -> ConsumeIterator; - fn consume_rev_iter(self) -> ConsumeRevIterator; + fn move_iter(self) -> MoveIterator; + fn move_rev_iter(self) -> MoveRevIterator; fn reserve(&mut self, n: uint); fn reserve_at_least(&mut self, n: uint); @@ -1204,26 +1204,26 @@ impl OwnedVector for ~[T] { /// value out of the vector (from start to end). The vector cannot /// be used after calling this. /// - /// Note that this performs O(n) swaps, and so `consume_rev_iter` + /// Note that this performs O(n) swaps, and so `move_rev_iter` /// (which just calls `pop` repeatedly) is more efficient. /// /// # Examples /// /// ~~~ {.rust} /// let v = ~[~"a", ~"b"]; - /// for s in v.consume_iter() { + /// for s in v.move_iter() { /// // s has type ~str, not &~str /// println(s); /// } /// ~~~ - fn consume_iter(self) -> ConsumeIterator { - ConsumeIterator { v: self, idx: 0 } + fn move_iter(self) -> MoveIterator { + MoveIterator { v: self, idx: 0 } } /// Creates a consuming iterator that moves out of the vector in - /// reverse order. Also see `consume_iter`, however note that this + /// reverse order. Also see `move_iter`, however note that this /// is more efficient. - fn consume_rev_iter(self) -> ConsumeRevIterator { - ConsumeRevIterator { v: self } + fn move_rev_iter(self) -> MoveRevIterator { + MoveRevIterator { v: self } } /** @@ -1540,7 +1540,7 @@ impl OwnedVector for ~[T] { let mut lefts = ~[]; let mut rights = ~[]; - for elt in self.consume_iter() { + for elt in self.move_iter() { if f(&elt) { lefts.push(elt); } else { @@ -2281,12 +2281,12 @@ pub type MutRevIterator<'self, T> = Invert>; /// An iterator that moves out of a vector. #[deriving(Clone)] -pub struct ConsumeIterator { +pub struct MoveIterator { priv v: ~[T], priv idx: uint, } -impl Iterator for ConsumeIterator { +impl Iterator for MoveIterator { fn next(&mut self) -> Option { // this is peculiar, but is required for safety with respect // to dtors. It traverses the first half of the vec, and @@ -2308,11 +2308,11 @@ impl Iterator for ConsumeIterator { /// An iterator that moves out of a vector in reverse order. #[deriving(Clone)] -pub struct ConsumeRevIterator { +pub struct MoveRevIterator { priv v: ~[T] } -impl Iterator for ConsumeRevIterator { +impl Iterator for MoveRevIterator { fn next(&mut self) -> Option { self.v.pop_opt() } @@ -3323,17 +3323,17 @@ mod tests { } #[test] - fn test_consume_iterator() { + fn test_move_iterator() { use iterator::*; let xs = ~[1u,2,3,4,5]; - assert_eq!(xs.consume_iter().fold(0, |a: uint, b: uint| 10*a + b), 12345); + assert_eq!(xs.move_iter().fold(0, |a: uint, b: uint| 10*a + b), 12345); } #[test] - fn test_consume_rev_iterator() { + fn test_move_rev_iterator() { use iterator::*; let xs = ~[1u,2,3,4,5]; - assert_eq!(xs.consume_rev_iter().fold(0, |a: uint, b: uint| 10*a + b), 54321); + assert_eq!(xs.move_rev_iter().fold(0, |a: uint, b: uint| 10*a + b), 54321); } #[test] @@ -3608,7 +3608,7 @@ mod tests { } assert_eq!(cnt, 8); - for f in v.consume_iter() { + for f in v.move_iter() { assert!(f == Foo); cnt += 1; } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 9a8a3bc25d8a3..0005180ef50ff 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -247,7 +247,7 @@ pub fn unguarded_pat(a: &arm) -> Option<~[@pat]> { } pub fn public_methods(ms: ~[@method]) -> ~[@method] { - do ms.consume_iter().filter |m| { + do ms.move_iter().filter |m| { match m.vis { public => true, _ => false diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 9edd41152f7f2..d5150cd2ace93 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -209,7 +209,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] { } // There doesn't seem to be a more optimal way to do this - do v.consume_iter().transform |(_, m)| { + do v.move_iter().transform |(_, m)| { match m.node { MetaList(n, ref mis) => { @spanned { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index d81dca005b0a4..1902e510935a7 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -702,7 +702,7 @@ impl AstBuilder for @ExtCtxt { } fn variant(&self, span: span, name: ident, tys: ~[ast::Ty]) -> ast::variant { - let args = tys.consume_iter().transform(|ty| { + let args = tys.move_iter().transform(|ty| { ast::variant_arg { ty: ty, id: self.next_id() } }).collect(); diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 008545c9729b1..10f2055b5fbba 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -269,7 +269,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, corresponding function in std::unstable::extfmt. Each function takes a buffer to insert data into along with the data being formatted. */ let npieces = pieces.len(); - for (i, pc) in pieces.consume_iter().enumerate() { + for (i, pc) in pieces.move_iter().enumerate() { match pc { /* Raw strings get appended via str::push_str */ PieceString(s) => { diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index 5cf5fdba632f4..de700466d9e6d 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -575,8 +575,8 @@ impl Context { Some(self.format_arg(e.span, Right(name), lname)); } - let args = names.consume_iter().transform(|a| a.unwrap()); - let mut args = locals.consume_iter().chain_(args); + let args = names.move_iter().transform(|a| a.unwrap()); + let mut args = locals.move_iter().chain_(args); // Next, build up the actual call to the sprintf function. let result = self.ecx.expr_call_global(self.fmtsp, ~[ diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0a5bc00072034..c1c63466221ea 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -176,7 +176,7 @@ pub fn fold_ty_param(tp: TyParam, pub fn fold_ty_params(tps: &OptVec, fld: @ast_fold) -> OptVec { let tps = /*bad*/ (*tps).clone(); - tps.map_consume(|tp| fold_ty_param(tp, fld)) + tps.map_move(|tp| fold_ty_param(tp, fld)) } pub fn fold_lifetime(l: &Lifetime, diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index 10603751a06d1..3758a8db62a9e 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -57,10 +57,10 @@ impl OptVec { } } - fn map_consume(self, op: &fn(T) -> U) -> OptVec { + fn map_move(self, op: &fn(T) -> U) -> OptVec { match self { Empty => Empty, - Vec(v) => Vec(v.consume_iter().transform(op).collect()) + Vec(v) => Vec(v.move_iter().transform(op).collect()) } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ddb0e3bfa689f..d1916088a412a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4310,7 +4310,7 @@ impl Parser { seq_sep_trailing_disallowed(token::COMMA), |p| p.parse_ty(false) ); - for ty in arg_tys.consume_iter() { + for ty in arg_tys.move_iter() { args.push(ast::variant_arg { ty: ty, id: self.get_id(), diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 2f4d763b84d77..02aa5eae50691 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -96,9 +96,9 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph { } } - do graph.consume_iter().transform |v| { + do graph.move_iter().transform |v| { let mut vec = ~[]; - for i in v.consume() { + for i in v.move_iter() { vec.push(i); } vec @@ -119,7 +119,7 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] { } } let mut vec = ~[]; - for i in keys.consume() { + for i in keys.move_iter() { vec.push(i); } return vec; diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 8c4e9092ce0a6..49120eb789e1c 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -75,7 +75,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { unsafe { 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. + // to_ascii_move and to_str_move to not do a unnecessary copy. buffer.push_str(fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v)); } } @@ -86,7 +86,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { // given a map, search for the frequency of a pattern fn find(mm: &HashMap<~[u8], uint>, key: ~str) -> uint { // 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. + // to_ascii_move and to_str_move to not do a unnecessary copy. let key = key.to_ascii().to_lower().to_str_ascii(); match mm.find_equiv(&key.as_bytes()) { option::None => { return 0u; } diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index 7f986eab78938..e0292aed168b5 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -28,20 +28,20 @@ fn calc(children: uint, parent_wait_chan: &Chan>>) { }; let child_start_chans: ~[Chan>] = - wait_ports.consume_iter().transform(|port| port.recv()).collect(); + wait_ports.move_iter().transform(|port| port.recv()).collect(); let (start_port, start_chan) = stream::>(); parent_wait_chan.send(start_chan); let parent_result_chan: Chan = start_port.recv(); let child_sum_ports: ~[Port] = - do child_start_chans.consume_iter().transform |child_start_chan| { + do child_start_chans.move_iter().transform |child_start_chan| { let (child_sum_port, child_sum_chan) = stream::(); child_start_chan.send(child_sum_chan); child_sum_port }.collect(); - let sum = child_sum_ports.consume_iter().fold(0, |sum, sum_port| sum + sum_port.recv() ); + let sum = child_sum_ports.move_iter().fold(0, |sum, sum_port| sum + sum_port.recv() ); parent_result_chan.send(sum + 1); } From 229eeda4cd3f8013538edfa0c82f6779555012f6 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 8 Aug 2013 06:48:20 -0700 Subject: [PATCH 12/23] Clean up some unused imports in tests --- src/libsyntax/ext/expand.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a928680e09392..1963f3aef49c1 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1075,7 +1075,6 @@ mod test { use parse::token::{intern, get_ident_interner}; use print::pprust; use util::parser_testing::{string_to_item, string_to_pat, strs_to_idents}; - use oldvisit::{mk_vt}; // make sure that fail! is present #[test] fn fail_exists_test () { From a6614621afbbcc04c503a4828adbb0acc4e0fe20 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 8 Aug 2013 20:33:28 -0700 Subject: [PATCH 13/23] std: merge iterator::DoubleEndedIterator and DoubleEndedIteratorUtil --- src/libstd/iterator.rs | 39 +++++++++++++-------------------------- src/libstd/prelude.rs | 2 +- src/libstd/str.rs | 2 +- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index d10a5541e41a6..3e0f934460091 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -55,32 +55,7 @@ pub trait Iterator { pub trait DoubleEndedIterator: Iterator { /// Yield an element from the end of the range, returning `None` if the range is empty. fn next_back(&mut self) -> Option; -} - -/// An object implementing random access indexing by `uint` -/// -/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`. -pub trait RandomAccessIterator: Iterator { - /// Return the number of indexable elements. At most `std::uint::max_value` - /// elements are indexable, even if the iterator represents a longer range. - fn indexable(&self) -> uint; - - /// Return an element at an index - fn idx(&self, index: uint) -> Option; -} - -/// Iterator adaptors provided for every `DoubleEndedIterator` implementation. -/// -/// In the future these will be default methods instead of a utility trait. -pub trait DoubleEndedIteratorUtil { - /// Flip the direction of the iterator - fn invert(self) -> Invert; -} -/// Iterator adaptors provided for every `DoubleEndedIterator` implementation. -/// -/// In the future these will be default methods instead of a utility trait. -impl> DoubleEndedIteratorUtil for T { /// Flip the direction of the iterator /// /// The inverted iterator flips the ends on an iterator that can already @@ -94,11 +69,23 @@ impl> DoubleEndedIteratorUtil for T { /// Note: Random access with inverted indices still only applies to the first /// `uint::max_value` elements of the original iterator. #[inline] - fn invert(self) -> Invert { + fn invert(self) -> Invert { Invert{iter: self} } } +/// An object implementing random access indexing by `uint` +/// +/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`. +pub trait RandomAccessIterator: Iterator { + /// Return the number of indexable elements. At most `std::uint::max_value` + /// elements are indexable, even if the iterator represents a longer range. + fn indexable(&self) -> uint; + + /// Return an element at an index + fn idx(&self, index: uint) -> Option; +} + /// An double-ended iterator with the direction inverted #[deriving(Clone)] pub struct Invert { diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index f035e61fa1e08..c560f9ed930d7 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -51,7 +51,7 @@ pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; pub use hash::Hash; pub use iter::Times; pub use iterator::Extendable; -pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator, DoubleEndedIteratorUtil}; +pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator}; pub use iterator::{ClonableIterator, OrdIterator}; pub use num::{Num, NumCast}; pub use num::{Orderable, Signed, Unsigned, Round}; diff --git a/src/libstd/str.rs b/src/libstd/str.rs index b72e5a87c6d48..539c6e38a99b7 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -25,7 +25,7 @@ use container::{Container, Mutable}; use iter::Times; use iterator::{Iterator, FromIterator, Extendable, IteratorUtil}; use iterator::{Filter, AdditiveIterator, Map}; -use iterator::{Invert, DoubleEndedIterator, DoubleEndedIteratorUtil}; +use iterator::{Invert, DoubleEndedIterator}; use libc; use num::Zero; use option::{None, Option, Some}; From 4062b84f4a5926f1037535903b13b99b6806f490 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 07:19:23 -0700 Subject: [PATCH 14/23] std: merge Iterator and IteratorUtil --- src/libextra/smallintmap.rs | 2 +- src/libextra/terminfo/parm.rs | 1 - src/libextra/test.rs | 1 - src/libstd/hashmap.rs | 2 +- src/libstd/iterator.rs | 460 +++++++++++++----------------- src/libstd/os.rs | 2 +- src/libstd/path.rs | 2 +- src/libstd/prelude.rs | 2 +- src/libstd/rt/mod.rs | 2 +- src/libstd/rt/util.rs | 1 - src/libstd/str.rs | 3 +- src/libstd/str/ascii.rs | 2 +- src/libstd/to_bytes.rs | 2 +- src/libstd/trie.rs | 2 +- src/libstd/tuple.rs | 2 +- src/test/run-pass/trait-to-str.rs | 2 +- 16 files changed, 204 insertions(+), 284 deletions(-) diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index a1f3cd4f5487d..ac07fd2bebfbb 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -15,7 +15,7 @@ #[allow(missing_doc)]; -use std::iterator::{Iterator, IteratorUtil, Enumerate, FilterMap, Invert}; +use std::iterator::{Iterator, Enumerate, FilterMap, Invert}; use std::util::replace; use std::vec::{VecIterator, VecMutIterator}; use std::vec; diff --git a/src/libextra/terminfo/parm.rs b/src/libextra/terminfo/parm.rs index 3edd7f1c66b00..b2a5707676aff 100644 --- a/src/libextra/terminfo/parm.rs +++ b/src/libextra/terminfo/parm.rs @@ -12,7 +12,6 @@ use std::{char, vec, util}; use std::num::strconv::{SignNone,SignNeg,SignAll,int_to_str_bytes_common}; -use std::iterator::IteratorUtil; #[deriving(Eq)] enum States { diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 6adef685d9599..85ec69a85727a 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -525,7 +525,6 @@ impl ConsoleTestState { } pub fn fmt_metrics(mm: &MetricMap) -> ~str { - use std::iterator::IteratorUtil; let v : ~[~str] = mm.iter() .transform(|(k,v)| fmt!("%s: %f (+/- %f)", *k, diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index e7b33ce80fa9c..32b3032c53d49 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -19,7 +19,7 @@ use container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; use clone::Clone; use cmp::{Eq, Equiv}; use hash::Hash; -use iterator::{Iterator, IteratorUtil, FromIterator, Extendable}; +use iterator::{Iterator, FromIterator, Extendable}; use iterator::{FilterMap, Chain, Repeat, Zip}; use num; use option::{None, Option, Some}; diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 3e0f934460091..48d058c6f1cb2 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -49,76 +49,7 @@ pub trait Iterator { /// The common use case for the estimate is pre-allocating space to store the results. #[inline] fn size_hint(&self) -> (uint, Option) { (0, None) } -} - -/// A range iterator able to yield elements from both ends -pub trait DoubleEndedIterator: Iterator { - /// Yield an element from the end of the range, returning `None` if the range is empty. - fn next_back(&mut self) -> Option; - - /// Flip the direction of the iterator - /// - /// The inverted iterator flips the ends on an iterator that can already - /// be iterated from the front and from the back. - /// - /// - /// If the iterator also implements RandomAccessIterator, the inverted - /// iterator is also random access, with the indices starting at the back - /// of the original iterator. - /// - /// Note: Random access with inverted indices still only applies to the first - /// `uint::max_value` elements of the original iterator. - #[inline] - fn invert(self) -> Invert { - Invert{iter: self} - } -} -/// An object implementing random access indexing by `uint` -/// -/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`. -pub trait RandomAccessIterator: Iterator { - /// Return the number of indexable elements. At most `std::uint::max_value` - /// elements are indexable, even if the iterator represents a longer range. - fn indexable(&self) -> uint; - - /// Return an element at an index - fn idx(&self, index: uint) -> Option; -} - -/// An double-ended iterator with the direction inverted -#[deriving(Clone)] -pub struct Invert { - priv iter: T -} - -impl> Iterator for Invert { - #[inline] - fn next(&mut self) -> Option { self.iter.next_back() } - #[inline] - fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } -} - -impl> DoubleEndedIterator for Invert { - #[inline] - fn next_back(&mut self) -> Option { self.iter.next() } -} - -impl + RandomAccessIterator> RandomAccessIterator - for Invert { - #[inline] - fn indexable(&self) -> uint { self.iter.indexable() } - #[inline] - fn idx(&self, index: uint) -> Option { - self.iter.idx(self.indexable() - index - 1) - } -} - -/// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also -/// implementations of the `Iterator` trait. -/// -/// In the future these will be default methods instead of a utility trait. -pub trait IteratorUtil { /// Chain this iterator with another, returning a new iterator which will /// finish iterating over the current iterator, and then it will iterate /// over the other specified iterator. @@ -133,7 +64,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &1); /// assert!(it.next().is_none()); /// ~~~ - fn chain_>(self, other: U) -> Chain; + #[inline] + fn chain_>(self, other: U) -> Chain { + Chain{a: self, b: other, flag: false} + } /// Creates an iterator which iterates over both this and the specified /// iterators simultaneously, yielding the two elements as pairs. When @@ -149,7 +83,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), (&0, &1)); /// assert!(it.next().is_none()); /// ~~~ - fn zip>(self, other: U) -> Zip; + #[inline] + fn zip>(self, other: U) -> Zip { + Zip{a: self, b: other} + } // FIXME: #5898: should be called map /// Creates a new iterator which will apply the specified function to each @@ -164,7 +101,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), 4); /// assert!(it.next().is_none()); /// ~~~ - fn transform<'r, B>(self, f: &'r fn(A) -> B) -> Map<'r, A, B, Self>; + #[inline] + fn transform<'r, B>(self, f: &'r fn(A) -> B) -> Map<'r, A, B, Self> { + Map{iter: self, f: f} + } /// Creates an iterator which applies the predicate to each element returned /// by this iterator. Only elements which have the predicate evaluate to @@ -178,7 +118,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &2); /// assert!(it.next().is_none()); /// ~~~ - fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> Filter<'r, A, Self>; + #[inline] + fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> Filter<'r, A, Self> { + Filter{iter: self, predicate: predicate} + } /// Creates an iterator which both filters and maps elements. /// If the specified function returns None, the element is skipped. @@ -192,7 +135,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), 4); /// assert!(it.next().is_none()); /// ~~~ - fn filter_map<'r, B>(self, f: &'r fn(A) -> Option) -> FilterMap<'r, A, B, Self>; + #[inline] + fn filter_map<'r, B>(self, f: &'r fn(A) -> Option) -> FilterMap<'r, A, B, Self> { + FilterMap { iter: self, f: f } + } /// Creates an iterator which yields a pair of the value returned by this /// iterator plus the current index of iteration. @@ -206,7 +152,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), (1, &200)); /// assert!(it.next().is_none()); /// ~~~ - fn enumerate(self) -> Enumerate; + #[inline] + fn enumerate(self) -> Enumerate { + Enumerate{iter: self, count: 0} + } /// Creates an iterator which invokes the predicate on elements until it /// returns false. Once the predicate returns false, all further elements are @@ -222,7 +171,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &1); /// assert!(it.next().is_none()); /// ~~~ - fn skip_while<'r>(self, predicate: &'r fn(&A) -> bool) -> SkipWhile<'r, A, Self>; + #[inline] + fn skip_while<'r>(self, predicate: &'r fn(&A) -> bool) -> SkipWhile<'r, A, Self> { + SkipWhile{iter: self, flag: false, predicate: predicate} + } /// Creates an iterator which yields elements so long as the predicate /// returns true. After the predicate returns false for the first time, no @@ -237,7 +189,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &2); /// assert!(it.next().is_none()); /// ~~~ - fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhile<'r, A, Self>; + #[inline] + fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhile<'r, A, Self> { + TakeWhile{iter: self, flag: false, predicate: predicate} + } /// Creates an iterator which skips the first `n` elements of this iterator, /// and then it yields all further items. @@ -251,7 +206,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &5); /// assert!(it.next().is_none()); /// ~~~ - fn skip(self, n: uint) -> Skip; + #[inline] + fn skip(self, n: uint) -> Skip { + Skip{iter: self, n: n} + } // FIXME: #5898: should be called take /// Creates an iterator which yields the first `n` elements of this @@ -267,7 +225,10 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &3); /// assert!(it.next().is_none()); /// ~~~ - fn take_(self, n: uint) -> Take; + #[inline] + fn take_(self, n: uint) -> Take { + Take{iter: self, n: n} + } /// Creates a new iterator which behaves in a similar fashion to foldl. /// There is a state which is passed between each iteration and can be @@ -289,8 +250,11 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), 120); /// assert!(it.next().is_none()); /// ~~~ + #[inline] fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option) - -> Scan<'r, A, B, Self, St>; + -> Scan<'r, A, B, Self, St> { + Scan{iter: self, f: f, state: initial_state} + } /// Creates an iterator that maps each element to an iterator, /// and yields the elements of the produced iterators @@ -309,8 +273,11 @@ pub trait IteratorUtil { /// } /// ~~~ // FIXME: #5898: should be called `flat_map` + #[inline] fn flat_map_<'r, B, U: Iterator>(self, f: &'r fn(A) -> U) - -> FlatMap<'r, A, Self, U>; + -> FlatMap<'r, A, Self, U> { + FlatMap{iter: self, f: f, frontiter: None, backiter: None } + } /// Creates an iterator that calls a function with a reference to each /// element before yielding it. This is often useful for debugging an @@ -329,7 +296,10 @@ pub trait IteratorUtil { ///println(sum.to_str()); /// ~~~ // FIXME: #5898: should be called `peek` - fn peek_<'r>(self, f: &'r fn(&A)) -> Peek<'r, A, Self>; + #[inline] + fn peek_<'r>(self, f: &'r fn(&A)) -> Peek<'r, A, Self> { + Peek{iter: self, f: f} + } /// An adaptation of an external iterator to the for-loop protocol of rust. /// @@ -342,7 +312,17 @@ pub trait IteratorUtil { /// printfln!("%d", i); /// } /// ~~~ - fn advance(&mut self, f: &fn(A) -> bool) -> bool; + #[inline] + fn advance(&mut self, f: &fn(A) -> bool) -> bool { + loop { + match self.next() { + Some(x) => { + if !f(x) { return false; } + } + None => { return true; } + } + } + } /// Loops through the entire iterator, collecting all of the elements into /// a container implementing `FromIterator`. @@ -354,7 +334,10 @@ pub trait IteratorUtil { /// let b: ~[int] = a.iter().transform(|&x| x).collect(); /// assert!(a == b); /// ~~~ - fn collect>(&mut self) -> B; + #[inline] + fn collect>(&mut self) -> B { + FromIterator::from_iterator(self) + } /// Loops through the entire iterator, collecting all of the elements into /// a unique vector. This is simply collect() specialized for vectors. @@ -366,7 +349,10 @@ pub trait IteratorUtil { /// let b: ~[int] = a.iter().transform(|&x| x).to_owned_vec(); /// assert!(a == b); /// ~~~ - fn to_owned_vec(&mut self) -> ~[A]; + #[inline] + fn to_owned_vec(&mut self) -> ~[A] { + self.collect() + } /// Loops through `n` iterations, returning the `n`th element of the /// iterator. @@ -379,7 +365,16 @@ pub trait IteratorUtil { /// assert!(it.nth(2).get() == &3); /// assert!(it.nth(2) == None); /// ~~~ - fn nth(&mut self, n: uint) -> Option; + #[inline] + fn nth(&mut self, mut n: uint) -> Option { + loop { + match self.next() { + Some(x) => if n == 0 { return Some(x) }, + None => return None + } + n -= 1; + } + } /// Loops through the entire iterator, returning the last element of the /// iterator. @@ -391,7 +386,12 @@ pub trait IteratorUtil { /// assert!(a.iter().last().get() == &5); /// ~~~ // FIXME: #5898: should be called `last` - fn last_(&mut self) -> Option; + #[inline] + fn last_(&mut self) -> Option { + let mut last = None; + for x in *self { last = Some(x); } + last + } /// Performs a fold operation over the entire iterator, returning the /// eventual state at the end of the iteration. @@ -402,7 +402,17 @@ pub trait IteratorUtil { /// let a = [1, 2, 3, 4, 5]; /// assert!(a.iter().fold(0, |a, &b| a + b) == 15); /// ~~~ - fn fold(&mut self, start: B, f: &fn(B, A) -> B) -> B; + #[inline] + fn fold(&mut self, init: B, f: &fn(B, A) -> B) -> B { + let mut accum = init; + loop { + match self.next() { + Some(x) => { accum = f(accum, x); } + None => { break; } + } + } + accum + } // FIXME: #5898: should be called len /// Counts the number of elements in this iterator. @@ -415,7 +425,10 @@ pub trait IteratorUtil { /// assert!(it.len_() == 5); /// assert!(it.len_() == 0); /// ~~~ - fn len_(&mut self) -> uint; + #[inline] + fn len_(&mut self) -> uint { + self.fold(0, |cnt, _x| cnt + 1) + } /// Tests whether the predicate holds true for all elements in the iterator. /// @@ -426,7 +439,11 @@ pub trait IteratorUtil { /// assert!(a.iter().all(|&x| *x > 0)); /// assert!(!a.iter().all(|&x| *x > 2)); /// ~~~ - fn all(&mut self, f: &fn(A) -> bool) -> bool; + #[inline] + fn all(&mut self, f: &fn(A) -> bool) -> bool { + for x in *self { if !f(x) { return false; } } + true + } /// Tests whether any element of an iterator satisfies the specified /// predicate. @@ -439,179 +456,6 @@ pub trait IteratorUtil { /// assert!(it.any(|&x| *x == 3)); /// assert!(!it.any(|&x| *x == 3)); /// ~~~ - fn any(&mut self, f: &fn(A) -> bool) -> bool; - - /// Return the first element satisfying the specified predicate - fn find_(&mut self, predicate: &fn(&A) -> bool) -> Option; - - /// Return the index of the first element satisfying the specified predicate - fn position(&mut self, predicate: &fn(A) -> bool) -> Option; - - /// Count the number of elements satisfying the specified predicate - fn count(&mut self, predicate: &fn(A) -> bool) -> uint; - - /// Return the element that gives the maximum value from the specfied function - /// - /// # Example - /// - /// ~~~ {.rust} - /// let xs = [-3, 0, 1, 5, -10]; - /// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10); - /// ~~~ - fn max_by(&mut self, f: &fn(&A) -> B) -> Option; - - /// Return the element that gives the minimum value from the specfied function - /// - /// # Example - /// - /// ~~~ {.rust} - /// let xs = [-3, 0, 1, 5, -10]; - /// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0); - /// ~~~ - fn min_by(&mut self, f: &fn(&A) -> B) -> Option; -} - -/// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also -/// implementations of the `Iterator` trait. -/// -/// In the future these will be default methods instead of a utility trait. -impl> IteratorUtil for T { - #[inline] - fn chain_>(self, other: U) -> Chain { - Chain{a: self, b: other, flag: false} - } - - #[inline] - fn zip>(self, other: U) -> Zip { - Zip{a: self, b: other} - } - - // FIXME: #5898: should be called map - #[inline] - fn transform<'r, B>(self, f: &'r fn(A) -> B) -> Map<'r, A, B, T> { - Map{iter: self, f: f} - } - - #[inline] - fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> Filter<'r, A, T> { - Filter{iter: self, predicate: predicate} - } - - #[inline] - fn filter_map<'r, B>(self, f: &'r fn(A) -> Option) -> FilterMap<'r, A, B, T> { - FilterMap { iter: self, f: f } - } - - #[inline] - fn enumerate(self) -> Enumerate { - Enumerate{iter: self, count: 0} - } - - #[inline] - fn skip_while<'r>(self, predicate: &'r fn(&A) -> bool) -> SkipWhile<'r, A, T> { - SkipWhile{iter: self, flag: false, predicate: predicate} - } - - #[inline] - fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhile<'r, A, T> { - TakeWhile{iter: self, flag: false, predicate: predicate} - } - - #[inline] - fn skip(self, n: uint) -> Skip { - Skip{iter: self, n: n} - } - - // FIXME: #5898: should be called take - #[inline] - fn take_(self, n: uint) -> Take { - Take{iter: self, n: n} - } - - #[inline] - fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option) - -> Scan<'r, A, B, T, St> { - Scan{iter: self, f: f, state: initial_state} - } - - #[inline] - fn flat_map_<'r, B, U: Iterator>(self, f: &'r fn(A) -> U) - -> FlatMap<'r, A, T, U> { - FlatMap{iter: self, f: f, frontiter: None, backiter: None } - } - - // FIXME: #5898: should be called `peek` - #[inline] - fn peek_<'r>(self, f: &'r fn(&A)) -> Peek<'r, A, T> { - Peek{iter: self, f: f} - } - - /// A shim implementing the `for` loop iteration protocol for iterator objects - #[inline] - fn advance(&mut self, f: &fn(A) -> bool) -> bool { - loop { - match self.next() { - Some(x) => { - if !f(x) { return false; } - } - None => { return true; } - } - } - } - - #[inline] - fn collect>(&mut self) -> B { - FromIterator::from_iterator(self) - } - - #[inline] - fn to_owned_vec(&mut self) -> ~[A] { - self.collect() - } - - /// Return the `n`th item yielded by an iterator. - #[inline] - fn nth(&mut self, mut n: uint) -> Option { - loop { - match self.next() { - Some(x) => if n == 0 { return Some(x) }, - None => return None - } - n -= 1; - } - } - - /// Return the last item yielded by an iterator. - #[inline] - fn last_(&mut self) -> Option { - let mut last = None; - for x in *self { last = Some(x); } - last - } - - /// Reduce an iterator to an accumulated value - #[inline] - fn fold(&mut self, init: B, f: &fn(B, A) -> B) -> B { - let mut accum = init; - loop { - match self.next() { - Some(x) => { accum = f(accum, x); } - None => { break; } - } - } - accum - } - - /// Count the number of items yielded by an iterator - #[inline] - fn len_(&mut self) -> uint { self.fold(0, |cnt, _x| cnt + 1) } - - #[inline] - fn all(&mut self, f: &fn(A) -> bool) -> bool { - for x in *self { if !f(x) { return false; } } - true - } - #[inline] fn any(&mut self, f: &fn(A) -> bool) -> bool { for x in *self { if f(x) { return true; } } @@ -640,6 +484,7 @@ impl> IteratorUtil for T { None } + /// Count the number of elements satisfying the specified predicate #[inline] fn count(&mut self, predicate: &fn(A) -> bool) -> uint { let mut i = 0; @@ -649,6 +494,14 @@ impl> IteratorUtil for T { i } + /// Return the element that gives the maximum value from the specfied function + /// + /// # Example + /// + /// ~~~ {.rust} + /// let xs = [-3, 0, 1, 5, -10]; + /// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10); + /// ~~~ #[inline] fn max_by(&mut self, f: &fn(&A) -> B) -> Option { self.fold(None, |max: Option<(A, B)>, x| { @@ -664,6 +517,14 @@ impl> IteratorUtil for T { }).map_move(|(x, _)| x) } + /// Return the element that gives the minimum value from the specfied function + /// + /// # Example + /// + /// ~~~ {.rust} + /// let xs = [-3, 0, 1, 5, -10]; + /// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0); + /// ~~~ #[inline] fn min_by(&mut self, f: &fn(&A) -> B) -> Option { self.fold(None, |min: Option<(A, B)>, x| { @@ -680,6 +541,69 @@ impl> IteratorUtil for T { } } +/// A range iterator able to yield elements from both ends +pub trait DoubleEndedIterator: Iterator { + /// Yield an element from the end of the range, returning `None` if the range is empty. + fn next_back(&mut self) -> Option; + + /// Flip the direction of the iterator + /// + /// The inverted iterator flips the ends on an iterator that can already + /// be iterated from the front and from the back. + /// + /// + /// If the iterator also implements RandomAccessIterator, the inverted + /// iterator is also random access, with the indices starting at the back + /// of the original iterator. + /// + /// Note: Random access with inverted indices still only applies to the first + /// `uint::max_value` elements of the original iterator. + #[inline] + fn invert(self) -> Invert { + Invert{iter: self} + } +} + +/// An object implementing random access indexing by `uint` +/// +/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`. +pub trait RandomAccessIterator: Iterator { + /// Return the number of indexable elements. At most `std::uint::max_value` + /// elements are indexable, even if the iterator represents a longer range. + fn indexable(&self) -> uint; + + /// Return an element at an index + fn idx(&self, index: uint) -> Option; +} + +/// An double-ended iterator with the direction inverted +#[deriving(Clone)] +pub struct Invert { + priv iter: T +} + +impl> Iterator for Invert { + #[inline] + fn next(&mut self) -> Option { self.iter.next_back() } + #[inline] + fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } +} + +impl> DoubleEndedIterator for Invert { + #[inline] + fn next_back(&mut self) -> Option { self.iter.next() } +} + +impl + RandomAccessIterator> RandomAccessIterator + for Invert { + #[inline] + fn indexable(&self) -> uint { self.iter.indexable() } + #[inline] + fn idx(&self, index: uint) -> Option { + self.iter.idx(self.indexable() - index - 1) + } +} + /// A trait for iterators over elements which can be added together pub trait AdditiveIterator { /// Iterates over the entire iterator, summing up all the elements @@ -1882,7 +1806,7 @@ mod tests { #[test] fn test_all() { - let v = ~&[1, 2, 3, 4, 5]; + let v: ~&[int] = ~&[1, 2, 3, 4, 5]; assert!(v.iter().all(|&x| x < 10)); assert!(!v.iter().all(|&x| x.is_even())); assert!(!v.iter().all(|&x| x > 100)); @@ -1891,7 +1815,7 @@ mod tests { #[test] fn test_any() { - let v = ~&[1, 2, 3, 4, 5]; + let v: ~&[int] = ~&[1, 2, 3, 4, 5]; assert!(v.iter().any(|&x| x < 10)); assert!(v.iter().any(|&x| x.is_even())); assert!(!v.iter().any(|&x| x > 100)); @@ -1900,7 +1824,7 @@ mod tests { #[test] fn test_find() { - let v = &[1, 3, 9, 27, 103, 14, 11]; + let v: &[int] = &[1, 3, 9, 27, 103, 14, 11]; assert_eq!(*v.iter().find_(|x| *x & 1 == 0).unwrap(), 14); assert_eq!(*v.iter().find_(|x| *x % 3 == 0).unwrap(), 3); assert!(v.iter().find_(|x| *x % 12 == 0).is_none()); @@ -1924,13 +1848,13 @@ mod tests { #[test] fn test_max_by() { - let xs = [-3, 0, 1, 5, -10]; + let xs: &[int] = &[-3, 0, 1, 5, -10]; assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10); } #[test] fn test_min_by() { - let xs = [-3, 0, 1, 5, -10]; + let xs: &[int] = &[-3, 0, 1, 5, -10]; assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0); } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 9ade21a4ede07..c916be79c53e5 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -32,7 +32,7 @@ use c_str::ToCStr; use clone::Clone; use container::Container; use io; -use iterator::{IteratorUtil, range}; +use iterator::range; use libc; use libc::{c_char, c_void, c_int, size_t}; use libc::FILE; diff --git a/src/libstd/path.rs b/src/libstd/path.rs index fb8f8fc7b67d5..177f0efb6dad3 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -21,7 +21,7 @@ use c_str; use clone::Clone; use cmp::Eq; use container::Container; -use iterator::{Iterator, IteratorUtil, range}; +use iterator::{Iterator, range}; use libc; use num; use option::{None, Option, Some}; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index c560f9ed930d7..9a8737f4dee3f 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -51,7 +51,7 @@ pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; pub use hash::Hash; pub use iter::Times; pub use iterator::Extendable; -pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator}; +pub use iterator::{Iterator, DoubleEndedIterator}; pub use iterator::{ClonableIterator, OrdIterator}; pub use num::{Num, NumCast}; pub use num::{Orderable, Signed, Unsigned, Round}; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 91297af5c935c..1b9f28b95fb3f 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -63,7 +63,7 @@ Several modules in `core` are clients of `rt`: use cell::Cell; use clone::Clone; use container::Container; -use iterator::{Iterator, IteratorUtil, range}; +use iterator::{Iterator, range}; use option::{Some, None}; use ptr::RawPtr; use rt::local::Local; diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 40e5c8d4bf1a0..6280b64ecf51c 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -10,7 +10,6 @@ use container::Container; use from_str::FromStr; -use iterator::IteratorUtil; use libc; use option::{Some, None}; use os; diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 539c6e38a99b7..7f2e5f93bdd01 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -23,7 +23,7 @@ use char::Char; use clone::Clone; use container::{Container, Mutable}; use iter::Times; -use iterator::{Iterator, FromIterator, Extendable, IteratorUtil}; +use iterator::{Iterator, FromIterator, Extendable}; use iterator::{Filter, AdditiveIterator, Map}; use iterator::{Invert, DoubleEndedIterator}; use libc; @@ -2546,7 +2546,6 @@ impl Zero for @str { #[cfg(test)] mod tests { - use iterator::IteratorUtil; use container::Container; use option::Some; use libc::c_char; diff --git a/src/libstd/str/ascii.rs b/src/libstd/str/ascii.rs index 02a6247428c86..c6ae535c19a3c 100644 --- a/src/libstd/str/ascii.rs +++ b/src/libstd/str/ascii.rs @@ -17,7 +17,7 @@ use str::OwnedStr; use container::Container; use cast; use ptr; -use iterator::{Iterator, IteratorUtil}; +use iterator::Iterator; use vec::{CopyableVector, ImmutableVector}; #[cfg(stage0)] use vec::OwnedVector; diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 5ad7969c8d21f..f871f4ef6d6ac 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -17,7 +17,7 @@ The `ToBytes` and `IterBytes` traits use cast; use io; use io::Writer; -use iterator::IteratorUtil; +use iterator::Iterator; use option::{None, Option, Some}; use str::StrSlice; use vec::ImmutableVector; diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 5ef5526e5162d..fc28e6996ba8b 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -11,7 +11,7 @@ //! An ordered map and set for integer keys implemented as a radix trie use prelude::*; -use iterator::{IteratorUtil, FromIterator, Extendable}; +use iterator::{FromIterator, Extendable}; use uint; use util::{swap, replace}; use vec; diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 41af29022a66c..93216a293192c 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -15,7 +15,7 @@ use clone::Clone; use vec; use vec::ImmutableVector; -use iterator::IteratorUtil; +use iterator::Iterator; pub use self::inner::*; diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index 3e4cfdc105cad..afe84a82637ca 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -16,7 +16,7 @@ extern mod std; use std::str::StrVector; use std::vec::ImmutableVector; -use std::iterator::IteratorUtil; +use std::iterator::Iterator; use std::int; trait to_str { From 68f40d215eae0b0370807368ba58edd0befc8bcb Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 20:09:47 -0700 Subject: [PATCH 15/23] std: Rename Iterator.transform -> .map cc #5898 --- src/compiletest/header.rs | 2 +- src/compiletest/runtest.rs | 6 +- src/libextra/bitv.rs | 6 +- src/libextra/dlist.rs | 14 ++--- src/libextra/fileinput.rs | 2 +- src/libextra/getopts.rs | 2 +- src/libextra/num/bigint.rs | 4 +- src/libextra/par.rs | 6 +- src/libextra/priority_queue.rs | 2 +- src/libextra/ringbuf.rs | 4 +- src/libextra/terminfo/parm.rs | 2 +- src/libextra/terminfo/parser/compiled.rs | 2 +- src/libextra/test.rs | 8 +-- src/libextra/treemap.rs | 4 +- src/librustc/back/rpath.rs | 6 +- src/librustc/driver/driver.rs | 6 +- src/librustc/front/config.rs | 6 +- src/librustc/front/test.rs | 4 +- src/librustc/metadata/creader.rs | 2 +- src/librustc/middle/cfg/construct.rs | 12 ++-- src/librustc/middle/check_match.rs | 2 +- src/librustc/middle/const_eval.rs | 4 +- src/librustc/middle/trans/adt.rs | 4 +- src/librustc/middle/trans/builder.rs | 2 +- src/librustc/middle/trans/cabi.rs | 2 +- src/librustc/middle/trans/common.rs | 10 +-- src/librustc/middle/trans/consts.rs | 2 +- src/librustc/middle/trans/debuginfo.rs | 8 +-- src/librustc/middle/trans/expr.rs | 2 +- src/librustc/middle/trans/monomorphize.rs | 8 +-- src/librustc/middle/ty.rs | 6 +- src/librustc/middle/typeck/astconv.rs | 2 +- src/librustc/middle/typeck/check/method.rs | 2 +- src/librustc/middle/typeck/check/mod.rs | 4 +- src/librustc/middle/typeck/check/vtable.rs | 2 +- src/librustc/middle/typeck/coherence.rs | 2 +- src/librustc/middle/typeck/collect.rs | 2 +- src/librustc/rustc.rs | 2 +- src/librustdoc/attr_parser.rs | 2 +- src/librustdoc/attr_pass.rs | 8 +-- src/librustdoc/extract.rs | 6 +- src/librustdoc/fold.rs | 14 ++--- src/librustdoc/page_pass.rs | 2 +- src/librustdoc/prune_hidden_pass.rs | 2 +- src/librustdoc/prune_private_pass.rs | 4 +- src/librustdoc/tystr_pass.rs | 4 +- src/librusti/rusti.rs | 2 +- src/librustpkg/rustpkg.rs | 2 +- src/libstd/hashmap.rs | 4 +- src/libstd/iterator.rs | 61 +++++++++---------- src/libstd/rt/kill.rs | 2 +- src/libstd/str.rs | 16 ++--- src/libstd/trie.rs | 4 +- src/libstd/tuple.rs | 4 +- src/libstd/vec.rs | 6 +- src/libsyntax/attr.rs | 4 +- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/cfg.rs | 2 +- src/libsyntax/ext/deriving/decodable.rs | 4 +- src/libsyntax/ext/deriving/generic.rs | 4 +- src/libsyntax/ext/deriving/rand.rs | 2 +- src/libsyntax/ext/ifmt.rs | 14 ++--- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/fold.rs | 10 +-- src/libsyntax/opt_vec.rs | 4 +- src/libsyntax/parse/comments.rs | 2 +- src/test/bench/graph500-bfs.rs | 6 +- src/test/bench/shootout-chameneos-redux.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/task-perf-one-million.rs | 4 +- src/test/run-pass/block-arg.rs | 2 +- src/test/run-pass/trait-to-str.rs | 2 +- 72 files changed, 188 insertions(+), 189 deletions(-) diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index a07da151afc3b..5e3687d70575d 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -142,7 +142,7 @@ fn parse_check_line(line: &str) -> Option<~str> { fn parse_exec_env(line: &str) -> Option<(~str, ~str)> { do parse_name_value_directive(line, ~"exec-env").map |nv| { // nv is either FOO or FOO=BAR - let mut strs: ~[~str] = nv.splitn_iter('=', 1).transform(|s| s.to_owned()).collect(); + let mut strs: ~[~str] = nv.splitn_iter('=', 1).map(|s| s.to_owned()).collect(); match strs.len() { 1u => (strs.pop(), ~""), diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 9c176b504b2ee..d325341d157aa 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -350,13 +350,13 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError], fatal(~"process did not return an error status"); } - let prefixes = expected_errors.iter().transform(|ee| { + let prefixes = expected_errors.iter().map(|ee| { fmt!("%s:%u:", testfile.to_str(), ee.line) }).collect::<~[~str]>(); fn to_lower( s : &str ) -> ~str { let i = s.iter(); - let c : ~[char] = i.transform( |c| { + let c : ~[char] = i.map( |c| { if c.is_ascii() { c.to_ascii().to_lower().to_char() } else { @@ -760,7 +760,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps, let cmdline = make_cmdline("", args.prog, args.args); // get bare program string - let mut tvec: ~[~str] = args.prog.split_iter('/').transform(|ts| ts.to_owned()).collect(); + let mut tvec: ~[~str] = args.prog.split_iter('/').map(|ts| ts.to_owned()).collect(); let prog_short = tvec.pop(); // copy to target diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 20a3add3e7b3d..63d62bd480980 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -869,7 +869,7 @@ impl BitvSet { let min = num::min(self.bitv.storage.len(), other.bitv.storage.len()); self.bitv.storage.slice(0, min).iter().enumerate() .zip(Repeat::new(&other.bitv.storage)) - .transform(|((i, &w), o_store)| (i * uint::bits, w, o_store[i])) + .map(|((i, &w), o_store)| (i * uint::bits, w, o_store[i])) } /// Visits each word in self or other that extends beyond the other. This @@ -888,11 +888,11 @@ impl BitvSet { if olen < slen { self.bitv.storage.slice_from(olen).iter().enumerate() .zip(Repeat::new(olen)) - .transform(|((i, &w), min)| (true, (i + min) * uint::bits, w)) + .map(|((i, &w), min)| (true, (i + min) * uint::bits, w)) } else { other.bitv.storage.slice_from(slen).iter().enumerate() .zip(Repeat::new(slen)) - .transform(|((i, &w), min)| (false, (i + min) * uint::bits, w)) + .map(|((i, &w), min)| (false, (i + min) * uint::bits, w)) } } } diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 2158a90963bc9..3e1038b2b4e83 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -600,7 +600,7 @@ impl Eq for DList { impl Clone for DList { fn clone(&self) -> DList { - self.iter().transform(|x| x.clone()).collect() + self.iter().map(|x| x.clone()).collect() } } @@ -690,7 +690,7 @@ mod tests { #[cfg(test)] fn list_from(v: &[T]) -> DList { - v.iter().transform(|x| (*x).clone()).collect() + v.iter().map(|x| (*x).clone()).collect() } #[test] @@ -1014,7 +1014,7 @@ mod tests { fn bench_collect_into(b: &mut test::BenchHarness) { let v = &[0, ..64]; do b.iter { - let _: DList = v.iter().transform(|x| *x).collect(); + let _: DList = v.iter().map(|x| *x).collect(); } } @@ -1075,7 +1075,7 @@ mod tests { #[bench] fn bench_iter(b: &mut test::BenchHarness) { let v = &[0, ..128]; - let m: DList = v.iter().transform(|&x|x).collect(); + let m: DList = v.iter().map(|&x|x).collect(); do b.iter { assert!(m.iter().len_() == 128); } @@ -1083,7 +1083,7 @@ mod tests { #[bench] fn bench_iter_mut(b: &mut test::BenchHarness) { let v = &[0, ..128]; - let mut m: DList = v.iter().transform(|&x|x).collect(); + let mut m: DList = v.iter().map(|&x|x).collect(); do b.iter { assert!(m.mut_iter().len_() == 128); } @@ -1091,7 +1091,7 @@ mod tests { #[bench] fn bench_iter_rev(b: &mut test::BenchHarness) { let v = &[0, ..128]; - let m: DList = v.iter().transform(|&x|x).collect(); + let m: DList = v.iter().map(|&x|x).collect(); do b.iter { assert!(m.rev_iter().len_() == 128); } @@ -1099,7 +1099,7 @@ mod tests { #[bench] fn bench_iter_mut_rev(b: &mut test::BenchHarness) { let v = &[0, ..128]; - let mut m: DList = v.iter().transform(|&x|x).collect(); + let mut m: DList = v.iter().map(|&x|x).collect(); do b.iter { assert!(m.mut_rev_iter().len_() == 128); } diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs index 14b02688cffcf..e268e83bf3fb0 100644 --- a/src/libextra/fileinput.rs +++ b/src/libextra/fileinput.rs @@ -353,7 +353,7 @@ a literal `-`. */ // XXX: stupid, unclear name pub fn pathify(vec: &[~str], stdin_hyphen : bool) -> ~[Option] { - vec.iter().transform(|str| { + vec.iter().map(|str| { if stdin_hyphen && "-" == *str { None } else { diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index 1b65528923a10..000520fe41e6e 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -647,7 +647,7 @@ pub mod groups { let desc_sep = "\n" + " ".repeat(24); - let mut rows = opts.iter().transform(|optref| { + let mut rows = opts.iter().map(|optref| { let OptGroup{short_name: short_name, long_name: long_name, hint: hint, diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 0c8701bd0b515..27dfc090f8888 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -287,7 +287,7 @@ impl Mul for BigUint { if n == 1 { return (*a).clone(); } let mut carry = 0; - let mut prod = do a.data.iter().transform |ai| { + let mut prod = do a.data.iter().map |ai| { let (hi, lo) = BigDigit::from_uint( (*ai as uint) * (n as uint) + (carry as uint) ); @@ -625,7 +625,7 @@ impl BigUint { if n_bits == 0 || self.is_zero() { return (*self).clone(); } let mut carry = 0; - let mut shifted = do self.data.iter().transform |elem| { + let mut shifted = do self.data.iter().map |elem| { let (hi, lo) = BigDigit::from_uint( (*elem as uint) << n_bits | (carry as uint) ); diff --git a/src/libextra/par.rs b/src/libextra/par.rs index bb79b5c8b95df..71dddc481ae37 100644 --- a/src/libextra/par.rs +++ b/src/libextra/par.rs @@ -77,7 +77,7 @@ fn map_slices( info!("num_tasks: %?", (num_tasks, futures.len())); assert_eq!(num_tasks, futures.len()); - do futures.move_iter().transform |ys| { + do futures.move_iter().map |ys| { let mut ys = ys; ys.get() }.collect() @@ -90,7 +90,7 @@ pub fn map( vec::concat(map_slices(xs, || { let f = fn_factory(); let result: ~fn(uint, &[A]) -> ~[B] = - |_, slice| slice.iter().transform(|x| f(x)).collect(); + |_, slice| slice.iter().map(|x| f(x)).collect(); result })) } @@ -102,7 +102,7 @@ pub fn mapi( let slices = map_slices(xs, || { let f = fn_factory(); let result: ~fn(uint, &[A]) -> ~[B] = |base, slice| { - slice.iter().enumerate().transform(|(i, x)| { + slice.iter().enumerate().map(|(i, x)| { f(i + base, x) }).collect() }; diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index 696ecc881b723..4b94219b30d53 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -367,7 +367,7 @@ mod tests { fn test_from_iter() { let xs = ~[9u, 8, 7, 6, 5, 4, 3, 2, 1]; - let mut q: PriorityQueue = xs.rev_iter().transform(|&x| x).collect(); + let mut q: PriorityQueue = xs.rev_iter().map(|&x| x).collect(); for &x in xs.iter() { assert_eq!(q.pop(), x); diff --git a/src/libextra/ringbuf.rs b/src/libextra/ringbuf.rs index da8089250b345..32c82e662b354 100644 --- a/src/libextra/ringbuf.rs +++ b/src/libextra/ringbuf.rs @@ -692,8 +692,8 @@ mod tests { fn test_from_iterator() { use std::iterator; let v = ~[1,2,3,4,5,6,7]; - let deq: RingBuf = v.iter().transform(|&x| x).collect(); - let u: ~[int] = deq.iter().transform(|&x| x).collect(); + let deq: RingBuf = v.iter().map(|&x| x).collect(); + let u: ~[int] = deq.iter().map(|&x| x).collect(); assert_eq!(u, v); let mut seq = iterator::count(0u, 2).take_(256); diff --git a/src/libextra/terminfo/parm.rs b/src/libextra/terminfo/parm.rs index b2a5707676aff..bb59e34f98a12 100644 --- a/src/libextra/terminfo/parm.rs +++ b/src/libextra/terminfo/parm.rs @@ -105,7 +105,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) *dst = (*src).clone(); } - for c in cap.iter().transform(|&x| x) { + for c in cap.iter().map(|&x| x) { let cur = c as char; let mut old_state = state; match state { diff --git a/src/libextra/terminfo/parser/compiled.rs b/src/libextra/terminfo/parser/compiled.rs index 426cacb62faad..0d2badff4929b 100644 --- a/src/libextra/terminfo/parser/compiled.rs +++ b/src/libextra/terminfo/parser/compiled.rs @@ -214,7 +214,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> { } let names_str = str::from_bytes(file.read_bytes(names_bytes as uint - 1)); // don't read NUL - let term_names: ~[~str] = names_str.split_iter('|').transform(|s| s.to_owned()).collect(); + let term_names: ~[~str] = names_str.split_iter('|').map(|s| s.to_owned()).collect(); file.read_byte(); // consume NUL diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 85ec69a85727a..8b7332ff545a4 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -526,10 +526,10 @@ impl ConsoleTestState { pub fn fmt_metrics(mm: &MetricMap) -> ~str { let v : ~[~str] = mm.iter() - .transform(|(k,v)| fmt!("%s: %f (+/- %f)", - *k, - v.value as float, - v.noise as float)) + .map(|(k,v)| fmt!("%s: %f (+/- %f)", + *k, + v.value as float, + v.noise as float)) .collect(); v.connect(", ") } diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 6e63b74449f0a..424492a3cfea4 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -1259,7 +1259,7 @@ mod test_treemap { fn test_from_iter() { let xs = ~[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; - let map: TreeMap = xs.iter().transform(|&x| x).collect(); + let map: TreeMap = xs.iter().map(|&x| x).collect(); for &(k, v) in xs.iter() { assert_eq!(map.find(&k), Some(&v)); @@ -1558,7 +1558,7 @@ mod test_set { fn test_from_iter() { let xs = ~[1, 2, 3, 4, 5, 6, 7, 8, 9]; - let set: TreeSet = xs.iter().transform(|&x| x).collect(); + let set: TreeSet = xs.iter().map(|&x| x).collect(); for x in xs.iter() { assert!(set.contains(x)); diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 5dc92dbc5e622..e07400c79b0e4 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -49,7 +49,7 @@ fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path { } pub fn rpaths_to_flags(rpaths: &[Path]) -> ~[~str] { - rpaths.iter().transform(|rpath| fmt!("-Wl,-rpath,%s",rpath.to_str())).collect() + rpaths.iter().map(|rpath| fmt!("-Wl,-rpath,%s",rpath.to_str())).collect() } fn get_rpaths(os: session::os, @@ -100,7 +100,7 @@ fn get_rpaths(os: session::os, fn get_rpaths_relative_to_output(os: session::os, output: &Path, libs: &[Path]) -> ~[Path] { - libs.iter().transform(|a| get_rpath_relative_to_output(os, output, a)).collect() + libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect() } pub fn get_rpath_relative_to_output(os: session::os, @@ -123,7 +123,7 @@ pub fn get_rpath_relative_to_output(os: session::os, } fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] { - libs.iter().transform(|a| get_absolute_rpath(a)).collect() + libs.iter().map(|a| get_absolute_rpath(a)).collect() } pub fn get_absolute_rpath(lib: &Path) -> Path { diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index dce632bd9d6bb..fdd7c9231b155 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -120,7 +120,7 @@ pub fn build_configuration(sess: Session, argv0: @str, input: &input) -> // Convert strings provided as --cfg [cfgspec] into a crate_cfg fn parse_cfgspecs(cfgspecs: ~[~str], demitter: diagnostic::Emitter) -> ast::CrateConfig { - do cfgspecs.move_iter().transform |s| { + do cfgspecs.move_iter().map |s| { let sess = parse::new_parse_sess(Some(demitter)); parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess) }.collect::() @@ -726,7 +726,7 @@ pub fn build_session_options(binary: @str, let addl_lib_search_paths = getopts::opt_strs(matches, "L").map(|s| Path(*s)); let linker = getopts::opt_maybe_str(matches, "linker"); let linker_args = getopts::opt_strs(matches, "link-args").flat_map( |a| { - a.split_iter(' ').transform(|arg| arg.to_owned()).collect() + a.split_iter(' ').map(|arg| arg.to_owned()).collect() }); let cfg = parse_cfgspecs(getopts::opt_strs(matches, "cfg"), demitter); @@ -737,7 +737,7 @@ pub fn build_session_options(binary: @str, let custom_passes = match getopts::opt_maybe_str(matches, "passes") { None => ~[], Some(s) => { - s.split_iter(|c: char| c == ' ' || c == ',').transform(|s| { + s.split_iter(|c: char| c == ' ' || c == ',').map(|s| { s.trim().to_owned() }).collect() } diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index d6584846655d2..026532c89c329 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -102,12 +102,12 @@ fn fold_item_underscore(cx: @Context, item: &ast::item_, let item = match *item { ast::item_impl(ref a, ref b, ref c, ref methods) => { let methods = methods.iter().filter(|m| method_in_cfg(cx, **m)) - .transform(|x| *x).collect(); + .map(|x| *x).collect(); ast::item_impl((*a).clone(), (*b).clone(), (*c).clone(), methods) } ast::item_trait(ref a, ref b, ref methods) => { let methods = methods.iter().filter(|m| trait_method_in_cfg(cx, *m) ) - .transform(|x| (*x).clone()).collect(); + .map(|x| (*x).clone()).collect(); ast::item_trait((*a).clone(), (*b).clone(), methods) } ref item => (*item).clone(), @@ -180,5 +180,5 @@ fn trait_method_in_cfg(cx: @Context, meth: &ast::trait_method) -> bool { // Determine if an item should be translated in the current crate // configuration based on the item's attributes fn in_cfg(cfg: &[@ast::MetaItem], attrs: &[ast::Attribute]) -> bool { - attr::test_cfg(cfg, attrs.iter().transform(|x| *x)) + attr::test_cfg(cfg, attrs.iter().map(|x| *x)) } diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index c6b1bdbe51ba1..597de440ae1fc 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -126,7 +126,7 @@ fn fold_mod(cx: @mut TestCtxt, let mod_nomain = ast::_mod { view_items: m.view_items.clone(), - items: m.items.iter().transform(|i| nomain(cx, *i)).collect(), + items: m.items.iter().map(|i| nomain(cx, *i)).collect(), }; fold::noop_fold_mod(&mod_nomain, fld) @@ -236,7 +236,7 @@ fn is_ignored(cx: @mut TestCtxt, i: @ast::item) -> bool { do i.attrs.iter().any |attr| { // check ignore(cfg(foo, bar)) "ignore" == attr.name() && match attr.meta_item_list() { - Some(ref cfgs) => attr::test_cfg(cx.crate.config, cfgs.iter().transform(|x| *x)), + Some(ref cfgs) => attr::test_cfg(cx.crate.config, cfgs.iter().map(|x| *x)), None => true } } diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 0a9e8490f22dc..bc9085b6887d1 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -83,7 +83,7 @@ fn warn_if_multiple_versions(e: @mut Env, *crate_cache[crate_cache.len() - 1].metas ); - let vec: ~[Either] = crate_cache.iter().transform(|&entry| { + let vec: ~[Either] = crate_cache.iter().map(|&entry| { let othername = loader::crate_name_from_metas(*entry.metas); if name == othername { Left(entry) diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 767c2b4ee2ed7..282292a2ac09c 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -112,23 +112,23 @@ impl CFGBuilder { ast::pat_enum(_, Some(ref subpats)) | ast::pat_tup(ref subpats) => { let pats_exit = - self.pats_all(subpats.iter().transform(|p| *p), pred); + self.pats_all(subpats.iter().map(|p| *p), pred); self.add_node(pat.id, [pats_exit]) } ast::pat_struct(_, ref subpats, _) => { let pats_exit = - self.pats_all(subpats.iter().transform(|f| f.pat), pred); + self.pats_all(subpats.iter().map(|f| f.pat), pred); self.add_node(pat.id, [pats_exit]) } ast::pat_vec(ref pre, ref vec, ref post) => { let pre_exit = - self.pats_all(pre.iter().transform(|p| *p), pred); + self.pats_all(pre.iter().map(|p| *p), pred); let vec_exit = - self.pats_all(vec.iter().transform(|p| *p), pre_exit); + self.pats_all(vec.iter().map(|p| *p), pre_exit); let post_exit = - self.pats_all(post.iter().transform(|p| *p), vec_exit); + self.pats_all(post.iter().map(|p| *p), vec_exit); self.add_node(pat.id, [post_exit]) } } @@ -376,7 +376,7 @@ impl CFGBuilder { ast::expr_struct(_, ref fields, base) => { let base_exit = self.opt_expr(base, pred); let field_exprs: ~[@ast::expr] = - fields.iter().transform(|f| f.expr).collect(); + fields.iter().map(|f| f.expr).collect(); self.straightline(expr, base_exit, field_exprs) } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 1b420b9c06a55..81bd2491c6987 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -657,7 +657,7 @@ pub fn specialize(cx: &MatchCheckCtxt, ty_to_str(cx.tcx, left_ty))); } } - let args = class_fields.iter().transform(|class_field| { + let args = class_fields.iter().map(|class_field| { match flds.iter().find_(|f| f.ident == class_field.ident) { Some(f) => f.pat, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 3b56764f2fcad..2de94cdbf4ccd 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -102,7 +102,7 @@ pub fn classify(e: &expr, ast::expr_tup(ref es) | ast::expr_vec(ref es, ast::m_imm) => { - join_all(es.iter().transform(|e| classify(*e, tcx))) + join_all(es.iter().map(|e| classify(*e, tcx))) } ast::expr_vstore(e, vstore) => { @@ -116,7 +116,7 @@ pub fn classify(e: &expr, } ast::expr_struct(_, ref fs, None) => { - let cs = do fs.iter().transform |f| { + let cs = do fs.iter().map |f| { classify(f.expr, tcx) }; join_all(cs) diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 2eb9841c6c757..a00cfa2912380 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -508,7 +508,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: uint, } General(ref cases) => { let case = &cases[discr]; - let max_sz = cases.iter().transform(|x| x.size).max().unwrap(); + let max_sz = cases.iter().map(|x| x.size).max().unwrap(); let discr_ty = C_uint(ccx, discr); let contents = build_const_struct(ccx, case, ~[discr_ty] + vals); @@ -519,7 +519,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: uint, C_struct(build_const_struct(ccx, nonnull, vals)) } else { assert_eq!(vals.len(), 0); - let vals = do nonnull.fields.iter().enumerate().transform |(i, &ty)| { + let vals = do nonnull.fields.iter().enumerate().map |(i, &ty)| { let llty = type_of::sizing_type_of(ccx, ty); if i == ptrfield { C_null(llty) } else { C_undef(llty) } }.collect::<~[ValueRef]>(); diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index 7d7fc9c087e64..8f48c00b8d6b4 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -521,7 +521,7 @@ impl Builder { } self.inbounds_gep(base, small_vec.slice(0, ixs.len())) } else { - let v = do ixs.iter().transform |i| { C_i32(*i as i32) }.collect::<~[ValueRef]>(); + let v = do ixs.iter().map |i| { C_i32(*i as i32) }.collect::<~[ValueRef]>(); self.count_insn("gepi"); self.inbounds_gep(base, v) } diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 895bea715c964..6a1905c451f97 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -37,7 +37,7 @@ pub struct FnType { impl FnType { pub fn decl_fn(&self, decl: &fn(fnty: Type) -> ValueRef) -> ValueRef { - let atys = self.arg_tys.iter().transform(|t| t.ty).collect::<~[Type]>(); + let atys = self.arg_tys.iter().map(|t| t.ty).collect::<~[Type]>(); let rty = self.ret_ty.ty; let fnty = Type::func(atys, &rty); let llfn = decl(fnty); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index f756460bd028b..40a83eb977078 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -316,7 +316,7 @@ pub struct cleanup_path { pub fn shrink_scope_clean(scope_info: &mut ScopeInfo, size: uint) { scope_info.landing_pad = None; scope_info.cleanup_paths = scope_info.cleanup_paths.iter() - .take_while(|&cu| cu.size <= size).transform(|&x|x).collect(); + .take_while(|&cu| cu.size <= size).map(|&x|x).collect(); } pub fn grow_scope_clean(scope_info: &mut ScopeInfo) { @@ -1000,7 +1000,7 @@ pub fn node_id_type_params(bcx: @mut Block, id: ast::NodeId) -> ~[ty::t] { match bcx.fcx.param_substs { Some(substs) => { - do params.iter().transform |t| { + do params.iter().map |t| { ty::subst_tps(tcx, substs.tys, substs.self_ty, *t) }.collect() } @@ -1025,7 +1025,7 @@ pub fn resolve_vtables_under_param_substs(tcx: ty::ctxt, param_substs: Option<@param_substs>, vts: typeck::vtable_res) -> typeck::vtable_res { - @vts.iter().transform(|ds| + @vts.iter().map(|ds| resolve_param_vtables_under_param_substs(tcx, param_substs, *ds)) @@ -1037,7 +1037,7 @@ pub fn resolve_param_vtables_under_param_substs( param_substs: Option<@param_substs>, ds: typeck::vtable_param_res) -> typeck::vtable_param_res { - @ds.iter().transform( + @ds.iter().map( |d| resolve_vtable_under_param_substs(tcx, param_substs, d)) @@ -1063,7 +1063,7 @@ pub fn resolve_vtable_under_param_substs(tcx: ty::ctxt, typeck::vtable_static(trait_id, ref tys, sub) => { let tys = match param_substs { Some(substs) => { - do tys.iter().transform |t| { + do tys.iter().map |t| { ty::subst_tps(tcx, substs.tys, substs.self_ty, *t) }.collect() } diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 0cb423d4921eb..bdac0925273bf 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -499,7 +499,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef { do expr::with_field_tys(tcx, ety, Some(e.id)) |discr, field_tys| { let cs: ~[ValueRef] = field_tys.iter().enumerate() - .transform(|(ix, &field_ty)| { + .map(|(ix, &field_ty)| { match fs.iter().find_(|f| field_ty.ident == f.ident) { Some(f) => const_expr(cx, (*f).expr), None => { diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 11136627826be..1fb64d9c67130 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -662,7 +662,7 @@ fn enum_metadata(cx: &mut CrateContext, let enumerators_metadata: ~[DIDescriptor] = variants .iter() - .transform(|v| { + .map(|v| { let name: &str = cx.sess.str_of(v.name); let discriminant_value = v.disr_val as c_ulonglong; @@ -709,7 +709,7 @@ fn enum_metadata(cx: &mut CrateContext, let variants_member_metadata: ~[DIDescriptor] = do struct_defs .iter() .enumerate() - .transform |(i, struct_def)| { + .map |(i, struct_def)| { let variant_type_metadata = adt_struct_metadata( cx, struct_def, @@ -766,7 +766,7 @@ fn enum_metadata(cx: &mut CrateContext, { let arg_llvm_types: ~[Type] = do struct_def.fields.map |&ty| { type_of::type_of(cx, ty) }; let arg_metadata: ~[DIType] = do struct_def.fields.iter().enumerate() - .transform |(i, &ty)| { + .map |(i, &ty)| { match discriminant_type_metadata { Some(metadata) if i == 0 => metadata, _ => type_metadata(cx, ty, span) @@ -816,7 +816,7 @@ fn composite_type_metadata(cx: &mut CrateContext, let member_metadata: ~[DIDescriptor] = member_llvm_types .iter() .enumerate() - .transform(|(i, &member_llvm_type)| { + .map(|(i, &member_llvm_type)| { let (member_size, member_align) = size_and_align_of(cx, member_llvm_type); let member_offset = machine::llelement_offset(cx, composite_llvm_type, i); let member_name: &str = member_names[i]; diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 8c63be084fd55..5931b54342f33 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -582,7 +582,7 @@ fn trans_rvalue_dps_unadjusted(bcx: @mut Block, expr: @ast::expr, ast::expr_tup(ref args) => { let repr = adt::represent_type(bcx.ccx(), expr_ty(bcx, expr)); let numbered_fields: ~[(uint, @ast::expr)] = - args.iter().enumerate().transform(|(i, arg)| (i, *arg)).collect(); + args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect(); return trans_adt(bcx, repr, 0, numbered_fields, None, dest); } ast::expr_lit(@codemap::spanned {node: ast::lit_str(s), _}) => { diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 5f8837b538cdf..14a69f10c4012 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -372,12 +372,12 @@ pub fn make_mono_id(ccx: @mut CrateContext, debug!("make_mono_id vtables=%s substs=%s", vts.repr(ccx.tcx), substs.tys.repr(ccx.tcx)); let vts_iter = substs.self_vtables.iter().chain_(vts.iter()); - vts_iter.zip(substs_iter).transform(|(vtable, subst)| { + vts_iter.zip(substs_iter).map(|(vtable, subst)| { let v = vtable.map(|vt| meth::vtable_id(ccx, vt)); (*subst, if !v.is_empty() { Some(@v) } else { None }) }).collect() } - None => substs_iter.transform(|subst| (*subst, None::<@~[mono_id]>)).collect() + None => substs_iter.map(|subst| (*subst, None::<@~[mono_id]>)).collect() }; @@ -389,7 +389,7 @@ pub fn make_mono_id(ccx: @mut CrateContext, substs.self_ty.map(|_| type_use::use_repr|type_use::use_tydesc); let uses_iter = self_use.iter().chain_(uses.iter()); - precise_param_ids.iter().zip(uses_iter).transform(|(id, uses)| { + precise_param_ids.iter().zip(uses_iter).map(|(id, uses)| { if ccx.sess.no_monomorphic_collapse() { match *id { (a, b) => mono_precise(a, b) @@ -429,7 +429,7 @@ pub fn make_mono_id(ccx: @mut CrateContext, }).collect() } None => { - precise_param_ids.iter().transform(|x| { + precise_param_ids.iter().map(|x| { let (a, b) = *x; mono_precise(a, b) }).collect() diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 849c35cdd2c03..4a576ff3bb000 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3791,9 +3791,9 @@ pub fn substd_enum_variants(cx: ctxt, id: ast::def_id, substs: &substs) -> ~[@VariantInfo] { - do enum_variants(cx, id).iter().transform |variant_info| { + do enum_variants(cx, id).iter().map |variant_info| { let substd_args = variant_info.args.iter() - .transform(|aty| subst(cx, substs, *aty)).collect(); + .map(|aty| subst(cx, substs, *aty)).collect(); let substd_ctor_ty = subst(cx, substs, variant_info.ctor_ty); @@ -3935,7 +3935,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[@VariantInfo] { _ }, _) => { let mut last_discriminant: Option = None; - @enum_definition.variants.iter().transform(|variant| { + @enum_definition.variants.iter().map(|variant| { let mut discriminant = match last_discriminant { Some(val) => val + 1, diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 750bd506f3e48..c666e98c9c15f 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -724,7 +724,7 @@ pub fn ty_of_closure( in_binding_rscope(rscope, RegionParamNames(bound_lifetime_names.clone())); - let input_tys = do decl.inputs.iter().enumerate().transform |(i, a)| { + let input_tys = do decl.inputs.iter().enumerate().map |(i, a)| { let expected_arg_ty = do expected_sig.chain_ref |e| { // no guarantee that the correct number of expected args // were supplied diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index ae0a95688ed20..84e5d8f9bf743 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -759,7 +759,7 @@ impl<'self> LookupContext<'self> { -> Option { // XXX(pcwalton): Do we need to clone here? let relevant_candidates: ~[Candidate] = - candidates.iter().transform(|c| (*c).clone()). + candidates.iter().map(|c| (*c).clone()). filter(|c| self.is_relevant(rcvr_ty, c)).collect(); let relevant_candidates = self.merge_candidates(relevant_candidates); diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index da0e219310fde..f31251bda9951 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1818,7 +1818,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, _ => () } - let tps : ~[ty::t] = tys.iter().transform(|ty| fcx.to_ty(ty)).collect(); + let tps : ~[ty::t] = tys.iter().map(|ty| fcx.to_ty(ty)).collect(); match method::lookup(fcx, expr, base, @@ -2644,7 +2644,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let mut bot_field = false; let mut err_field = false; - let elt_ts = do elts.iter().enumerate().transform |(i, e)| { + let elt_ts = do elts.iter().enumerate().map |(i, e)| { let opt_hint = match flds { Some(ref fs) if i < fs.len() => Some(fs[i]), _ => None diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 700d96727eae2..37f4a6ba49737 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -100,7 +100,7 @@ fn lookup_vtables(vcx: &VtableContext, let mut result = substs.tps.rev_iter() .zip(type_param_defs.rev_iter()) - .transform(|(ty, def)| + .map(|(ty, def)| lookup_vtables_for_param(vcx, location_info, Some(substs), &*def.bounds, *ty, is_early)) .to_owned_vec(); diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index c3df0d06f83dd..b93f979894db7 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -182,7 +182,7 @@ impl CoherenceChecker { item_impl(_, ref opt_trait, _, _) => { let opt_trait : ~[trait_ref] = opt_trait.iter() - .transform(|x| (*x).clone()) + .map(|x| (*x).clone()) .collect(); self.check_implementation(item, opt_trait); } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 907a076b1a1ef..94cf5b431bafa 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -731,7 +731,7 @@ pub fn convert_methods(ccx: &CrateCtxt, -> ~[ConvertedMethod] { let tcx = ccx.tcx; - return ms.iter().transform(|m| { + return ms.iter().map(|m| { let num_rcvr_ty_params = rcvr_ty_generics.type_param_defs.len(); let m_ty_generics = ty_generics(ccx, rcvr_ty_generics.region_param, &m.generics, diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 668aaff35bb88..4cb6d7de0d3dd 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -157,7 +157,7 @@ Available lint options: let lint_dict = lint::get_lint_dict(); let mut lint_dict = lint_dict.move_iter() - .transform(|(k, v)| (v, k)) + .map(|(k, v)| (v, k)) .collect::<~[(lint::LintSpec, &'static str)]>(); lint_dict.qsort(); diff --git a/src/librustdoc/attr_parser.rs b/src/librustdoc/attr_parser.rs index f1d6b7285e88f..ce8d1977443f8 100644 --- a/src/librustdoc/attr_parser.rs +++ b/src/librustdoc/attr_parser.rs @@ -27,7 +27,7 @@ pub struct CrateAttrs { fn doc_metas(attrs: ~[ast::Attribute]) -> ~[@ast::MetaItem] { attrs.iter() .filter(|at| "doc" == at.name()) - .transform(|at| at.desugar_doc().meta()) + .map(|at| at.desugar_doc().meta()) .collect() } diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index a1cb81f450357..d68f1f112e008 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -123,7 +123,7 @@ fn fold_enum( let doc = fold::default_seq_fold_enum(fold, doc); doc::EnumDoc { - variants: do doc.variants.iter().transform |variant| { + variants: do doc.variants.iter().map |variant| { let variant = (*variant).clone(); let desc = { let variant = variant.clone(); @@ -182,7 +182,7 @@ fn merge_method_attrs( ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { - methods.iter().transform(|method| { + methods.iter().map(|method| { match (*method).clone() { ast::required(ty_m) => { (to_str(ty_m.ident), @@ -197,7 +197,7 @@ fn merge_method_attrs( ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref methods), _ }, _) => { - methods.iter().transform(|method| { + methods.iter().map(|method| { (to_str(method.ident), attr_parser::parse_desc(method.attrs.clone())) }).collect() @@ -206,7 +206,7 @@ fn merge_method_attrs( } }; - do docs.iter().zip(attrs.iter()).transform |(doc, attrs)| { + do docs.iter().zip(attrs.iter()).map |(doc, attrs)| { assert!(doc.name == attrs.first()); let desc = attrs.second(); diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index 2cab62296a4dd..55552924d4461 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -185,7 +185,7 @@ fn enumdoc_from_enum( fn variantdocs_from_variants( variants: ~[ast::variant] ) -> ~[doc::VariantDoc] { - variants.iter().transform(variantdoc_from_variant).collect() + variants.iter().map(variantdoc_from_variant).collect() } fn variantdoc_from_variant(variant: &ast::variant) -> doc::VariantDoc { @@ -202,7 +202,7 @@ fn traitdoc_from_trait( ) -> doc::TraitDoc { doc::TraitDoc { item: itemdoc, - methods: do methods.iter().transform |method| { + methods: do methods.iter().map |method| { match (*method).clone() { ast::required(ty_m) => { doc::MethodDoc { @@ -238,7 +238,7 @@ fn impldoc_from_impl( bounds_str: None, trait_types: ~[], self_ty: None, - methods: do methods.iter().transform |method| { + methods: do methods.iter().map |method| { doc::MethodDoc { name: to_str(method.ident), brief: None, diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index 589232f6e2f2f..3e74916228f00 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -153,7 +153,7 @@ pub fn default_par_fold(ctxt: T) -> Fold { pub fn default_seq_fold_doc(fold: &Fold, doc: doc::Doc) -> doc::Doc { doc::Doc { - pages: do doc.pages.iter().transform |page| { + pages: do doc.pages.iter().map |page| { match (*page).clone() { doc::CratePage(doc) => { doc::CratePage((fold.fold_crate)(fold, doc)) @@ -189,7 +189,7 @@ pub fn default_any_fold_mod( ) -> doc::ModDoc { doc::ModDoc { item: (fold.fold_item)(fold, doc.item.clone()), - items: doc.items.iter().transform(|ItemTag| { + items: doc.items.iter().map(|ItemTag| { fold_ItemTag(fold, (*ItemTag).clone()) }).collect(), .. doc @@ -202,7 +202,7 @@ pub fn default_seq_fold_mod( ) -> doc::ModDoc { doc::ModDoc { item: (fold.fold_item)(fold, doc.item.clone()), - items: doc.items.iter().transform(|ItemTag| { + items: doc.items.iter().map(|ItemTag| { fold_ItemTag(fold, (*ItemTag).clone()) }).collect(), .. doc @@ -215,7 +215,7 @@ pub fn default_par_fold_mod( ) -> doc::ModDoc { doc::ModDoc { item: (fold.fold_item)(fold, doc.item.clone()), - items: doc.items.iter().transform(|ItemTag| { + items: doc.items.iter().map(|ItemTag| { fold_ItemTag(fold, (*ItemTag).clone()) }).collect(), .. doc @@ -228,7 +228,7 @@ pub fn default_any_fold_nmod( ) -> doc::NmodDoc { doc::NmodDoc { item: (fold.fold_item)(fold, doc.item.clone()), - fns: doc.fns.iter().transform(|FnDoc| { + fns: doc.fns.iter().map(|FnDoc| { (fold.fold_fn)(fold, (*FnDoc).clone()) }).collect(), .. doc @@ -241,7 +241,7 @@ pub fn default_seq_fold_nmod( ) -> doc::NmodDoc { doc::NmodDoc { item: (fold.fold_item)(fold, doc.item.clone()), - fns: doc.fns.iter().transform(|FnDoc| { + fns: doc.fns.iter().map(|FnDoc| { (fold.fold_fn)(fold, (*FnDoc).clone()) }).collect(), .. doc @@ -254,7 +254,7 @@ pub fn default_par_fold_nmod( ) -> doc::NmodDoc { doc::NmodDoc { item: (fold.fold_item)(fold, doc.item.clone()), - fns: doc.fns.iter().transform(|FnDoc| { + fns: doc.fns.iter().map(|FnDoc| { (fold.fold_fn)(fold, (*FnDoc).clone()) }).collect(), .. doc diff --git a/src/librustdoc/page_pass.rs b/src/librustdoc/page_pass.rs index 82a4724496dd1..342c949e3fc60 100644 --- a/src/librustdoc/page_pass.rs +++ b/src/librustdoc/page_pass.rs @@ -123,7 +123,7 @@ fn strip_mod(doc: doc::ModDoc) -> doc::ModDoc { doc::ModTag(_) | doc::NmodTag(_) => false, _ => true } - }.transform(|x| (*x).clone()).collect::<~[doc::ItemTag]>(), + }.map(|x| (*x).clone()).collect::<~[doc::ItemTag]>(), .. doc.clone() } } diff --git a/src/librustdoc/prune_hidden_pass.rs b/src/librustdoc/prune_hidden_pass.rs index 04cb0e3f71076..9dc2f43f7ac92 100644 --- a/src/librustdoc/prune_hidden_pass.rs +++ b/src/librustdoc/prune_hidden_pass.rs @@ -43,7 +43,7 @@ fn fold_mod( doc::ModDoc { items: do doc.items.iter().filter |item_tag| { !is_hidden(fold.ctxt.clone(), item_tag.item()) - }.transform(|x| (*x).clone()).collect(), + }.map(|x| (*x).clone()).collect(), .. doc } } diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 3e380732d0f07..0ee0889cb9fee 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -91,7 +91,7 @@ fn strip_priv_methods( ast::private => false, ast::inherited => item_vis == ast::public } - }.transform(|x| (*x).clone()).collect(); + }.map(|x| (*x).clone()).collect(); doc::ImplDoc { methods: methods, @@ -126,7 +126,7 @@ fn fold_mod( is_visible(fold.ctxt.clone(), item_tag.item()) } } - }).transform(|x| (*x).clone()).collect(), + }).map(|x| (*x).clone()).collect(), .. doc } } diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 196c7e892a880..e9c6dcd08623c 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -124,7 +124,7 @@ fn fold_enum( let srv = fold.ctxt.clone(); doc::EnumDoc { - variants: do doc.variants.iter().transform |variant| { + variants: do doc.variants.iter().map |variant| { let sig = { let variant = (*variant).clone(); do astsrv::exec(srv.clone()) |ctxt| { @@ -169,7 +169,7 @@ fn merge_methods( item_id: doc::AstId, docs: ~[doc::MethodDoc] ) -> ~[doc::MethodDoc] { - do docs.iter().transform |doc| { + do docs.iter().map |doc| { doc::MethodDoc { sig: get_method_sig(srv.clone(), item_id, doc.name.clone()), .. (*doc).clone() diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index bb863df334812..0f8644ad837e4 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -453,7 +453,7 @@ pub fn run_line(repl: &mut Repl, input: @io::Reader, out: @io::Writer, line: ~st if line.starts_with(":") { // drop the : and the \n (one byte each) let full = line.slice(1, line.len()); - let split: ~[~str] = full.word_iter().transform(|s| s.to_owned()).collect(); + let split: ~[~str] = full.word_iter().map(|s| s.to_owned()).collect(); let len = split.len(); if len > 0 { diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index 26dab4120fda4..3ae2ad3751ffb 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -158,7 +158,7 @@ impl<'self> PkgScript<'self> { let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]); // Run the configs() function to get the configs let cfgs = str::from_bytes_slice(output.output).word_iter() - .transform(|w| w.to_owned()).collect(); + .map(|w| w.to_owned()).collect(); (cfgs, output.status) } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 32b3032c53d49..5fe47dc6603b5 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -977,7 +977,7 @@ mod test_map { fn test_from_iter() { let xs = ~[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; - let map: HashMap = xs.iter().transform(|&x| x).collect(); + let map: HashMap = xs.iter().map(|&x| x).collect(); for &(k, v) in xs.iter() { assert_eq!(map.find(&k), Some(&v)); @@ -1169,7 +1169,7 @@ mod test_set { fn test_from_iter() { let xs = ~[1, 2, 3, 4, 5, 6, 7, 8, 9]; - let set: HashSet = xs.iter().transform(|&x| x).collect(); + let set: HashSet = xs.iter().map(|&x| x).collect(); for x in xs.iter() { assert!(set.contains(x)); diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 48d058c6f1cb2..8718bee283e6a 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -88,7 +88,6 @@ pub trait Iterator { Zip{a: self, b: other} } - // FIXME: #5898: should be called map /// Creates a new iterator which will apply the specified function to each /// element returned by the first, yielding the mapped element instead. /// @@ -96,13 +95,13 @@ pub trait Iterator { /// /// ~~~ {.rust} /// let a = [1, 2]; - /// let mut it = a.iter().transform(|&x| 2 * x); + /// let mut it = a.iter().map(|&x| 2 * x); /// assert_eq!(it.next().get(), 2); /// assert_eq!(it.next().get(), 4); /// assert!(it.next().is_none()); /// ~~~ #[inline] - fn transform<'r, B>(self, f: &'r fn(A) -> B) -> Map<'r, A, B, Self> { + fn map<'r, B>(self, f: &'r fn(A) -> B) -> Map<'r, A, B, Self> { Map{iter: self, f: f} } @@ -288,7 +287,7 @@ pub trait Iterator { /// ~~~ {.rust} ///let xs = [1u, 4, 2, 3, 8, 9, 6]; ///let sum = xs.iter() - /// .transform(|&x| x) + /// .map(|&x| x) /// .peek_(|&x| debug!("filtering %u", x)) /// .filter(|&x| x % 2 == 0) /// .peek_(|&x| debug!("%u made it through", x)) @@ -331,7 +330,7 @@ pub trait Iterator { /// /// ~~~ {.rust} /// let a = [1, 2, 3, 4, 5]; - /// let b: ~[int] = a.iter().transform(|&x| x).collect(); + /// let b: ~[int] = a.iter().map(|&x| x).collect(); /// assert!(a == b); /// ~~~ #[inline] @@ -346,7 +345,7 @@ pub trait Iterator { /// /// ~~~ {.rust} /// let a = [1, 2, 3, 4, 5]; - /// let b: ~[int] = a.iter().transform(|&x| x).to_owned_vec(); + /// let b: ~[int] = a.iter().map(|&x| x).to_owned_vec(); /// assert!(a == b); /// ~~~ #[inline] @@ -612,7 +611,7 @@ pub trait AdditiveIterator { /// /// ~~~ {.rust} /// let a = [1, 2, 3, 4, 5]; - /// let mut it = a.iter().transform(|&x| x); + /// let mut it = a.iter().map(|&x| x); /// assert!(it.sum() == 15); /// ~~~ fn sum(&mut self) -> A; @@ -1547,7 +1546,7 @@ mod tests { assert_eq!(i, expected.len()); let ys = count(30u, 10).take_(4); - let mut it = xs.iter().transform(|&x| x).chain_(ys); + let mut it = xs.iter().map(|&x| x).chain_(ys); let mut i = 0; for x in it { assert_eq!(x, expected[i]); @@ -1662,7 +1661,7 @@ mod tests { let mut n = 0; let ys = xs.iter() - .transform(|&x| x) + .map(|&x| x) .peek_(|_| n += 1) .collect::<~[uint]>(); @@ -1731,33 +1730,33 @@ mod tests { #[test] fn test_iterator_sum() { let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v.slice(0, 4).iter().transform(|&x| x).sum(), 6); - assert_eq!(v.iter().transform(|&x| x).sum(), 55); - assert_eq!(v.slice(0, 0).iter().transform(|&x| x).sum(), 0); + assert_eq!(v.slice(0, 4).iter().map(|&x| x).sum(), 6); + assert_eq!(v.iter().map(|&x| x).sum(), 55); + assert_eq!(v.slice(0, 0).iter().map(|&x| x).sum(), 0); } #[test] fn test_iterator_product() { let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v.slice(0, 4).iter().transform(|&x| x).product(), 0); - assert_eq!(v.slice(1, 5).iter().transform(|&x| x).product(), 24); - assert_eq!(v.slice(0, 0).iter().transform(|&x| x).product(), 1); + assert_eq!(v.slice(0, 4).iter().map(|&x| x).product(), 0); + assert_eq!(v.slice(1, 5).iter().map(|&x| x).product(), 24); + assert_eq!(v.slice(0, 0).iter().map(|&x| x).product(), 1); } #[test] fn test_iterator_max() { let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v.slice(0, 4).iter().transform(|&x| x).max(), Some(3)); - assert_eq!(v.iter().transform(|&x| x).max(), Some(10)); - assert_eq!(v.slice(0, 0).iter().transform(|&x| x).max(), None); + assert_eq!(v.slice(0, 4).iter().map(|&x| x).max(), Some(3)); + assert_eq!(v.iter().map(|&x| x).max(), Some(10)); + assert_eq!(v.slice(0, 0).iter().map(|&x| x).max(), None); } #[test] fn test_iterator_min() { let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v.slice(0, 4).iter().transform(|&x| x).min(), Some(0)); - assert_eq!(v.iter().transform(|&x| x).min(), Some(0)); - assert_eq!(v.slice(0, 0).iter().transform(|&x| x).min(), None); + assert_eq!(v.slice(0, 4).iter().map(|&x| x).min(), Some(0)); + assert_eq!(v.iter().map(|&x| x).min(), Some(0)); + assert_eq!(v.slice(0, 0).iter().map(|&x| x).min(), None); } #[test] @@ -1775,11 +1774,11 @@ mod tests { assert_eq!(c.take_while(|_| false).size_hint(), (0, None)); assert_eq!(c.skip_while(|_| false).size_hint(), (0, None)); assert_eq!(c.enumerate().size_hint(), (uint::max_value, None)); - assert_eq!(c.chain_(vi.transform(|&i| i)).size_hint(), (uint::max_value, None)); + assert_eq!(c.chain_(vi.map(|&i| i)).size_hint(), (uint::max_value, None)); assert_eq!(c.zip(vi).size_hint(), (10, Some(10))); assert_eq!(c.scan(0, |_,_| Some(0)).size_hint(), (0, None)); assert_eq!(c.filter(|_| false).size_hint(), (0, None)); - assert_eq!(c.transform(|_| 0).size_hint(), (uint::max_value, None)); + assert_eq!(c.map(|_| 0).size_hint(), (uint::max_value, None)); assert_eq!(c.filter_map(|_| Some(0)).size_hint(), (0, None)); assert_eq!(vi.take_(5).size_hint(), (5, Some(5))); @@ -1793,14 +1792,14 @@ mod tests { assert_eq!(vi.zip(v2.iter()).size_hint(), (3, Some(3))); assert_eq!(vi.scan(0, |_,_| Some(0)).size_hint(), (0, Some(10))); assert_eq!(vi.filter(|_| false).size_hint(), (0, Some(10))); - assert_eq!(vi.transform(|i| i+1).size_hint(), (10, Some(10))); + assert_eq!(vi.map(|i| i+1).size_hint(), (10, Some(10))); assert_eq!(vi.filter_map(|_| Some(0)).size_hint(), (0, Some(10))); } #[test] fn test_collect() { let a = ~[1, 2, 3, 4, 5]; - let b: ~[int] = a.iter().transform(|&x| x).collect(); + let b: ~[int] = a.iter().map(|&x| x).collect(); assert_eq!(a, b); } @@ -1864,13 +1863,13 @@ mod tests { let mut it = xs.iter(); it.next(); it.next(); - assert_eq!(it.invert().transform(|&x| x).collect::<~[int]>(), ~[16, 14, 12, 10, 8, 6]); + assert_eq!(it.invert().map(|&x| x).collect::<~[int]>(), ~[16, 14, 12, 10, 8, 6]); } #[test] fn test_double_ended_map() { let xs = [1, 2, 3, 4, 5, 6]; - let mut it = xs.iter().transform(|&x| x * -1); + let mut it = xs.iter().map(|&x| x * -1); assert_eq!(it.next(), Some(-1)); assert_eq!(it.next(), Some(-2)); assert_eq!(it.next_back(), Some(-6)); @@ -2020,7 +2019,7 @@ mod tests { fn test_random_access_peek() { let xs = [1, 2, 3, 4, 5]; - // test .transform and .peek_ that don't implement Clone + // test .map and .peek_ that don't implement Clone let it = xs.iter().peek_(|_| {}); assert_eq!(xs.len(), it.indexable()); for (i, elt) in xs.iter().enumerate() { @@ -2030,11 +2029,11 @@ mod tests { } #[test] - fn test_random_access_transform() { + fn test_random_access_map() { let xs = [1, 2, 3, 4, 5]; - // test .transform and .peek_ that don't implement Clone - let it = xs.iter().transform(|x| *x); + // test .map and .peek_ that don't implement Clone + let it = xs.iter().map(|x| *x); assert_eq!(xs.len(), it.indexable()); for (i, elt) in xs.iter().enumerate() { assert_eq!(Some(*elt), it.idx(i)); diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index 26c6c9119a17b..07b4ea10b6a37 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -239,7 +239,7 @@ impl BlockedTask { }; // Even if the task was unkillable before, we use 'Killable' because // multiple pipes will have handles. It does not really mean killable. - handles.move_iter().transform(|x| Killable(x)).collect() + handles.move_iter().map(|x| Killable(x)).collect() } // This assertion has two flavours because the wake involves an atomic op. diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 7f2e5f93bdd01..b2c0b5a4fb22f 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -185,7 +185,7 @@ impl<'self, S: Str> StrVector for &'self [S] { pub fn concat(&self) -> ~str { if self.is_empty() { return ~""; } - let len = self.iter().transform(|s| s.as_slice().len()).sum(); + let len = self.iter().map(|s| s.as_slice().len()).sum(); let mut s = with_capacity(len); @@ -210,7 +210,7 @@ impl<'self, S: Str> StrVector for &'self [S] { pub fn concat(&self) -> ~str { if self.is_empty() { return ~""; } - let len = self.iter().transform(|s| s.as_slice().len()).sum(); + let len = self.iter().map(|s| s.as_slice().len()).sum(); let mut s = with_capacity(len); @@ -239,7 +239,7 @@ impl<'self, S: Str> StrVector for &'self [S] { // this is wrong without the guarantee that `self` is non-empty let len = sep.len() * (self.len() - 1) - + self.iter().transform(|s| s.as_slice().len()).sum(); + + self.iter().map(|s| s.as_slice().len()).sum(); let mut s = ~""; let mut first = true; @@ -280,7 +280,7 @@ impl<'self, S: Str> StrVector for &'self [S] { // this is wrong without the guarantee that `self` is non-empty let len = sep.len() * (self.len() - 1) - + self.iter().transform(|s| s.as_slice().len()).sum(); + + self.iter().map(|s| s.as_slice().len()).sum(); let mut s = ~""; let mut first = true; @@ -1445,7 +1445,7 @@ impl<'self> StrSlice<'self> for &'self str { /// ~~~ #[inline] fn iter(&self) -> CharIterator<'self> { - self.char_offset_iter().transform(|(_, c)| c) + self.char_offset_iter().map(|(_, c)| c) } /// An iterator over the characters of `self`, in reverse order. @@ -1457,7 +1457,7 @@ impl<'self> StrSlice<'self> for &'self str { /// An iterator over the bytes of `self` #[inline] fn byte_iter(&self) -> ByteIterator<'self> { - self.as_bytes().iter().transform(|&b| b) + self.as_bytes().iter().map(|&b| b) } /// An iterator over the bytes of `self`, in reverse order @@ -1565,7 +1565,7 @@ impl<'self> StrSlice<'self> for &'self str { /// An iterator over the lines of a string, separated by either /// `\n` or (`\r\n`). fn any_line_iter(&self) -> AnyLineIterator<'self> { - do self.line_iter().transform |line| { + do self.line_iter().map |line| { let l = line.len(); if l > 0 && line[l - 1] == '\r' as u8 { line.slice(0, l - 1) } else { line } @@ -3686,7 +3686,7 @@ mod tests { #[test] fn test_str_container() { fn sum_len(v: &[S]) -> uint { - v.iter().transform(|x| x.len()).sum() + v.iter().map(|x| x.len()).sum() } let s = ~"01234"; diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index fc28e6996ba8b..0bfee145a3cfc 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -617,7 +617,7 @@ mod test_map { fn test_from_iter() { let xs = ~[(1u, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; - let map: TrieMap = xs.iter().transform(|&x| x).collect(); + let map: TrieMap = xs.iter().map(|&x| x).collect(); for &(k, v) in xs.iter() { assert_eq!(map.find(&k), Some(&v)); @@ -680,7 +680,7 @@ mod test_set { fn test_from_iter() { let xs = ~[9u, 8, 7, 6, 5, 4, 3, 2, 1]; - let set: TrieSet = xs.iter().transform(|&x| x).collect(); + let set: TrieSet = xs.iter().map(|&x| x).collect(); for x in xs.iter() { assert!(set.contains(x)); diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 93216a293192c..80d1626c084fd 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -102,7 +102,7 @@ impl<'self, fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { match *self { (ref a, ref b) => { - a.iter().zip(b.iter()).transform(|(aa, bb)| f(aa, bb)).collect() + a.iter().zip(b.iter()).map(|(aa, bb)| f(aa, bb)).collect() } } } @@ -122,7 +122,7 @@ impl ExtendedTupleOps for (~[A], ~[B]) { fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { match *self { (ref a, ref b) => { - a.iter().zip(b.iter()).transform(|(aa, bb)| f(aa, bb)).collect() + a.iter().zip(b.iter()).map(|(aa, bb)| f(aa, bb)).collect() } } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 60abe65f94dfe..c831dd7091828 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1068,10 +1068,10 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { } /// Deprecated, use iterators where possible - /// (`self.iter().transform(f)`). Apply a function to each element + /// (`self.iter().map(f)`). Apply a function to each element /// of a vector and return the results. fn map(&self, f: &fn(t: &T) -> U) -> ~[U] { - self.iter().transform(f).collect() + self.iter().map(f).collect() } /** @@ -2148,7 +2148,7 @@ pub mod bytes { impl Clone for ~[A] { #[inline] fn clone(&self) -> ~[A] { - self.iter().transform(|item| item.clone()).collect() + self.iter().map(|item| item.clone()).collect() } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index d5150cd2ace93..e0160db81fd97 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -201,7 +201,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] { // This is sort of stupid here, but we need to sort by // human-readable strings. let mut v = items.iter() - .transform(|&mi| (mi.name(), mi)) + .map(|&mi| (mi.name(), mi)) .collect::<~[(@str, @MetaItem)]>(); do extra::sort::quick_sort(v) |&(a, _), &(b, _)| { @@ -209,7 +209,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] { } // There doesn't seem to be a more optimal way to do this - do v.move_iter().transform |(_, m)| { + do v.move_iter().map |(_, m)| { match m.node { MetaList(n, ref mis) => { @spanned { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1902e510935a7..65032642fda78 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -702,7 +702,7 @@ impl AstBuilder for @ExtCtxt { } fn variant(&self, span: span, name: ident, tys: ~[ast::Ty]) -> ast::variant { - let args = tys.move_iter().transform(|ty| { + let args = tys.move_iter().map(|ty| { ast::variant_arg { ty: ty, id: self.next_id() } }).collect(); diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index 069cac0103677..5f9437fd253ef 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -39,7 +39,7 @@ pub fn expand_cfg(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacR // test_cfg searches for meta items looking like `cfg(foo, ...)` let in_cfg = &[cx.meta_list(sp, @"cfg", cfgs)]; - let matches_cfg = attr::test_cfg(cx.cfg(), in_cfg.iter().transform(|&x| x)); + let matches_cfg = attr::test_cfg(cx.cfg(), in_cfg.iter().map(|&x| x)); let e = cx.expr_bool(sp, matches_cfg); MRExpr(e) } diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 59b7da16c2bcb..1abfe246f9da8 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -90,7 +90,7 @@ fn decodable_substructure(cx: @ExtCtxt, span: span, } } Right(ref fields) => { - let fields = do fields.iter().enumerate().transform |(i, f)| { + let fields = do fields.iter().enumerate().map |(i, f)| { cx.field_imm(span, *f, getarg(cx.str_of(*f), i)) }.collect(); cx.expr_struct_ident(span, substr.type_ident, fields) @@ -132,7 +132,7 @@ fn decodable_substructure(cx: @ExtCtxt, span: span, } } Right(ref fields) => { - let fields = do fields.iter().enumerate().transform |(i, f)| { + let fields = do fields.iter().enumerate().map |(i, f)| { cx.field_imm(span, *f, getarg(i)) }.collect(); cx.expr_struct_ident(span, name, fields) diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index fb1e6bf191384..a1abe47e0909d 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -590,7 +590,7 @@ impl<'self> MethodDef<'self> { // transpose raw_fields let fields = match raw_fields { [ref self_arg, .. rest] => { - do self_arg.iter().enumerate().transform |(i, &(opt_id, field))| { + do self_arg.iter().enumerate().map |(i, &(opt_id, field))| { let other_fields = do rest.map |l| { match &l[i] { &(_, ex) => ex @@ -750,7 +750,7 @@ impl<'self> MethodDef<'self> { let field_tuples = do self_vec.iter() .zip(enum_matching_fields.iter()) - .transform |(&(id, self_f), other)| { + .map |(&(id, self_f), other)| { (id, self_f, (*other).clone()) }.collect(); substructure = EnumMatching(variant_index, variant, field_tuples); diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 2966a8c114daf..e55a96f77ff9b 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -95,7 +95,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { let rand_variant = cx.expr_binary(span, ast::rem, rv_call, variant_count); - let mut arms = do variants.iter().enumerate().transform |(i, id_sum)| { + let mut arms = do variants.iter().enumerate().map |(i, id_sum)| { let i_expr = cx.expr_uint(span, i); let pat = cx.pat_lit(span, i_expr); diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index de700466d9e6d..a44201544d58a 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -353,9 +353,9 @@ impl Context { let trans_method = |method: &parse::Method| { let method = match *method { parse::Select(ref arms, ref default) => { - let arms = arms.iter().transform(|arm| { + let arms = arms.iter().map(|arm| { let p = self.ecx.path_global(sp, rtpath("SelectArm")); - let result = arm.result.iter().transform(|p| { + let result = arm.result.iter().map(|p| { self.trans_piece(p) }).collect(); let s = arm.selector.to_managed(); @@ -368,7 +368,7 @@ impl Context { self.ecx.expr_vec_slice(sp, result)), ]) }).collect(); - let default = default.iter().transform(|p| { + let default = default.iter().map(|p| { self.trans_piece(p) }).collect(); self.ecx.expr_call_global(sp, rtpath("Select"), ~[ @@ -381,9 +381,9 @@ impl Context { Some(i) => { some(self.ecx.expr_uint(sp, i)) } None => { none() } }; - let arms = arms.iter().transform(|arm| { + let arms = arms.iter().map(|arm| { let p = self.ecx.path_global(sp, rtpath("PluralArm")); - let result = arm.result.iter().transform(|p| { + let result = arm.result.iter().map(|p| { self.trans_piece(p) }).collect(); let (lr, selarg) = match arm.selector { @@ -408,7 +408,7 @@ impl Context { self.ecx.expr_vec_slice(sp, result)), ]) }).collect(); - let default = default.iter().transform(|p| { + let default = default.iter().map(|p| { self.trans_piece(p) }).collect(); self.ecx.expr_call_global(sp, rtpath("Plural"), ~[ @@ -575,7 +575,7 @@ impl Context { Some(self.format_arg(e.span, Right(name), lname)); } - let args = names.move_iter().transform(|a| a.unwrap()); + let args = names.move_iter().map(|a| a.unwrap()); let mut args = locals.move_iter().chain_(args); // Next, build up the actual call to the sprintf function. diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 71903b9aa0204..031f0fb4199ae 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -105,7 +105,7 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { result::Ok(src) => { - let u8_exprs: ~[@ast::expr] = src.iter().transform(|char| cx.expr_u8(sp, *char)).collect(); + let u8_exprs: ~[@ast::expr] = src.iter().map(|char| cx.expr_u8(sp, *char)).collect(); base::MRExpr(cx.expr_vec(sp, u8_exprs)) } result::Err(ref e) => { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index c1c63466221ea..65694f013f751 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -704,7 +704,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ { // ...nor do modules pub fn noop_fold_mod(m: &_mod, fld: @ast_fold) -> _mod { ast::_mod { - view_items: m.view_items.iter().transform(|x| fld.fold_view_item(x)).collect(), + view_items: m.view_items.iter().map(|x| fld.fold_view_item(x)).collect(), items: m.items.iter().filter_map(|x| fld.fold_item(*x)).collect(), } } @@ -713,8 +713,8 @@ fn noop_fold_foreign_mod(nm: &foreign_mod, fld: @ast_fold) -> foreign_mod { ast::foreign_mod { sort: nm.sort, abis: nm.abis, - view_items: nm.view_items.iter().transform(|x| fld.fold_view_item(x)).collect(), - items: nm.items.iter().transform(|x| fld.fold_foreign_item(*x)).collect(), + view_items: nm.view_items.iter().map(|x| fld.fold_view_item(x)).collect(), + items: nm.items.iter().map(|x| fld.fold_foreign_item(*x)).collect(), } } @@ -734,7 +734,7 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ { struct_variant_kind(ref struct_def) => { kind = struct_variant_kind(@ast::struct_def { fields: struct_def.fields.iter() - .transform(|f| fld.fold_struct_field(*f)).collect(), + .map(|f| fld.fold_struct_field(*f)).collect(), ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c)) }) } @@ -828,7 +828,7 @@ impl ast_fold for AstFoldFns { fn fold_view_item(@self, x: &view_item) -> view_item { ast::view_item { node: (self.fold_view_item)(&x.node, self as @ast_fold), - attrs: x.attrs.iter().transform(|a| fold_attribute_(*a, self as @ast_fold)).collect(), + attrs: x.attrs.iter().map(|a| fold_attribute_(*a, self as @ast_fold)).collect(), vis: x.vis, span: (self.new_span)(x.span), } diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index 3758a8db62a9e..5d79532c8c535 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -60,7 +60,7 @@ impl OptVec { fn map_move(self, op: &fn(T) -> U) -> OptVec { match self { Empty => Empty, - Vec(v) => Vec(v.move_iter().transform(op).collect()) + Vec(v) => Vec(v.move_iter().map(op).collect()) } } @@ -92,7 +92,7 @@ impl OptVec { #[inline] fn map_to_vec(&self, op: &fn(&T) -> B) -> ~[B] { - self.iter().transform(op).collect() + self.iter().map(op).collect() } fn mapi_to_vec(&self, op: &fn(uint, &T) -> B) -> ~[B] { diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 41379e6599c6e..5b9725ec6a042 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -115,7 +115,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { if comment.starts_with("/*") { let lines = comment.slice(3u, comment.len() - 2u) .any_line_iter() - .transform(|s| s.to_owned()) + .map(|s| s.to_owned()) .collect::<~[~str]>(); let lines = vertical_trim(lines); diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 02aa5eae50691..9725297bace53 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -96,7 +96,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph { } } - do graph.move_iter().transform |v| { + do graph.move_iter().map |v| { let mut vec = ~[]; for i in v.move_iter() { vec.push(i); @@ -193,7 +193,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { // Do the BFS. info!("PBFS iteration %?", i); i += 1; - colors = do colors.iter().enumerate().transform |(i, c)| { + colors = do colors.iter().enumerate().map |(i, c)| { let c : color = *c; match c { white => { @@ -220,7 +220,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { } // Convert the results. - do colors.iter().transform |c| { + do colors.iter().map |c| { match *c { white => { -1i64 } black(parent) => { parent } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 2b177ccb98fcc..f82c5e692e44d 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -150,7 +150,7 @@ fn rendezvous(nn: uint, set: ~[color]) { // these channels will allow us to talk to each creature by 'name'/index let to_creature: ~[Chan>] = - set.iter().enumerate().transform(|(ii, col)| { + set.iter().enumerate().map(|(ii, col)| { // create each creature as a listener with a port, and // give us a channel to talk to each let ii = ii; diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 49120eb789e1c..66b9bdc0a42c9 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -172,7 +172,7 @@ fn main() { let sizes = ~[1u,2,3,4,6,12,18]; let mut streams = vec::from_fn(sizes.len(), |_| Some(stream::<~str>())); let mut from_child = ~[]; - let to_child = do sizes.iter().zip(streams.mut_iter()).transform |(sz, stream_ref)| { + let to_child = do sizes.iter().zip(streams.mut_iter()).map |(sz, stream_ref)| { let sz = *sz; let stream = util::replace(stream_ref, None); let (from_child_, to_parent_) = stream.unwrap(); diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index e0292aed168b5..5efe13f8bca6b 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -28,14 +28,14 @@ fn calc(children: uint, parent_wait_chan: &Chan>>) { }; let child_start_chans: ~[Chan>] = - wait_ports.move_iter().transform(|port| port.recv()).collect(); + wait_ports.move_iter().map(|port| port.recv()).collect(); let (start_port, start_chan) = stream::>(); parent_wait_chan.send(start_chan); let parent_result_chan: Chan = start_port.recv(); let child_sum_ports: ~[Port] = - do child_start_chans.move_iter().transform |child_start_chan| { + do child_start_chans.move_iter().map |child_start_chan| { let (child_sum_port, child_sum_chan) = stream::(); child_start_chan.send(child_sum_chan); child_sum_port diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index 7b74d1d314b40..aabc005c57fb3 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -28,7 +28,7 @@ pub fn main() { assert!(any_negative); // Higher precedence than unary operations: - let abs_v = do v.iter().transform |e| { e.abs() }.collect::<~[float]>(); + let abs_v = do v.iter().map |e| { e.abs() }.collect::<~[float]>(); assert!(do abs_v.iter().all |e| { e.is_positive() }); assert!(!do abs_v.iter().any |e| { e.is_negative() }); diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index afe84a82637ca..493b810c10488 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -29,7 +29,7 @@ impl to_str for int { impl to_str for ~[T] { fn to_str(&self) -> ~str { - fmt!("[%s]", self.iter().transform(|e| e.to_str()).collect::<~[~str]>().connect(", ")) + fmt!("[%s]", self.iter().map(|e| e.to_str()).collect::<~[~str]>().connect(", ")) } } From 24d2cd0ef4585743736aa86fb4b94d00ca40f3ab Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 20:16:07 -0700 Subject: [PATCH 16/23] std: Iterator.take_ -> .take --- src/libextra/ringbuf.rs | 2 +- src/libstd/iterator.rs | 56 ++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/libextra/ringbuf.rs b/src/libextra/ringbuf.rs index 32c82e662b354..bb9ac74bc77ac 100644 --- a/src/libextra/ringbuf.rs +++ b/src/libextra/ringbuf.rs @@ -696,7 +696,7 @@ mod tests { let u: ~[int] = deq.iter().map(|&x| x).collect(); assert_eq!(u, v); - let mut seq = iterator::count(0u, 2).take_(256); + let mut seq = iterator::count(0u, 2).take(256); let deq: RingBuf = seq.collect(); for (i, &x) in deq.iter().enumerate() { assert_eq!(2*i, x); diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 8718bee283e6a..e723121564969 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -210,7 +210,6 @@ pub trait Iterator { Skip{iter: self, n: n} } - // FIXME: #5898: should be called take /// Creates an iterator which yields the first `n` elements of this /// iterator, and then it will always return None. /// @@ -218,14 +217,14 @@ pub trait Iterator { /// /// ~~~ {.rust} /// let a = [1, 2, 3, 4, 5]; - /// let mut it = a.iter().take_(3); + /// let mut it = a.iter().take(3); /// assert_eq!(it.next().get(), &1); /// assert_eq!(it.next().get(), &2); /// assert_eq!(it.next().get(), &3); /// assert!(it.next().is_none()); /// ~~~ #[inline] - fn take_(self, n: uint) -> Take { + fn take(self, n: uint) -> Take { Take{iter: self, n: n} } @@ -263,7 +262,7 @@ pub trait Iterator { /// ~~~ {.rust} /// let xs = [2u, 3]; /// let ys = [0u, 1, 0, 1, 2]; - /// let mut it = xs.iter().flat_map_(|&x| count(0u, 1).take_(x)); + /// let mut it = xs.iter().flat_map_(|&x| count(0u, 1).take(x)); /// // Check that `it` has the same elements as `ys` /// let mut i = 0; /// for x: uint in it { @@ -288,15 +287,14 @@ pub trait Iterator { ///let xs = [1u, 4, 2, 3, 8, 9, 6]; ///let sum = xs.iter() /// .map(|&x| x) - /// .peek_(|&x| debug!("filtering %u", x)) + /// .peek(|&x| debug!("filtering %u", x)) /// .filter(|&x| x % 2 == 0) - /// .peek_(|&x| debug!("%u made it through", x)) + /// .peek(|&x| debug!("%u made it through", x)) /// .sum(); ///println(sum.to_str()); /// ~~~ - // FIXME: #5898: should be called `peek` #[inline] - fn peek_<'r>(self, f: &'r fn(&A)) -> Peek<'r, A, Self> { + fn peek<'r>(self, f: &'r fn(&A)) -> Peek<'r, A, Self> { Peek{iter: self, f: f} } @@ -700,7 +698,7 @@ pub trait ClonableIterator { /// # Example /// /// ~~~ {.rust} - /// let a = count(1,1).take_(1); + /// let a = count(1,1).take(1); /// let mut cy = a.cycle(); /// assert_eq!(cy.next(), Some(1)); /// assert_eq!(cy.next(), Some(1)); @@ -1527,7 +1525,7 @@ mod tests { #[test] fn test_counter_from_iter() { - let mut it = count(0, 5).take_(10); + let mut it = count(0, 5).take(10); let xs: ~[int] = FromIterator::from_iterator(&mut it); assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]); } @@ -1545,7 +1543,7 @@ mod tests { } assert_eq!(i, expected.len()); - let ys = count(30u, 10).take_(4); + let ys = count(30u, 10).take(4); let mut it = xs.iter().map(|&x| x).chain_(ys); let mut i = 0; for x in it { @@ -1557,7 +1555,7 @@ mod tests { #[test] fn test_filter_map() { - let mut it = count(0u, 1u).take_(10) + let mut it = count(0u, 1u).take(10) .filter_map(|x| if x.is_even() { Some(x*x) } else { None }); assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]); } @@ -1614,7 +1612,7 @@ mod tests { fn test_iterator_take() { let xs = [0u, 1, 2, 3, 5, 13, 15, 16, 17, 19]; let ys = [0u, 1, 2, 3, 5]; - let mut it = xs.iter().take_(5); + let mut it = xs.iter().take(5); let mut i = 0; for &x in it { assert_eq!(x, ys[i]); @@ -1646,7 +1644,7 @@ mod tests { fn test_iterator_flat_map() { let xs = [0u, 3, 6]; let ys = [0u, 1, 2, 3, 4, 5, 6, 7, 8]; - let mut it = xs.iter().flat_map_(|&x| count(x, 1).take_(3)); + let mut it = xs.iter().flat_map_(|&x| count(x, 1).take(3)); let mut i = 0; for x in it { assert_eq!(x, ys[i]); @@ -1662,7 +1660,7 @@ mod tests { let ys = xs.iter() .map(|&x| x) - .peek_(|_| n += 1) + .peek(|_| n += 1) .collect::<~[uint]>(); assert_eq!(n, xs.len()); @@ -1693,13 +1691,13 @@ mod tests { #[test] fn test_cycle() { let cycle_len = 3; - let it = count(0u, 1).take_(cycle_len).cycle(); + let it = count(0u, 1).take(cycle_len).cycle(); assert_eq!(it.size_hint(), (uint::max_value, None)); - for (i, x) in it.take_(100).enumerate() { + for (i, x) in it.take(100).enumerate() { assert_eq!(i % cycle_len, x); } - let mut it = count(0u, 1).take_(0).cycle(); + let mut it = count(0u, 1).take(0).cycle(); assert_eq!(it.size_hint(), (0, Some(0))); assert_eq!(it.next(), None); } @@ -1769,7 +1767,7 @@ mod tests { assert_eq!(c.size_hint(), (uint::max_value, None)); assert_eq!(vi.size_hint(), (10, Some(10))); - assert_eq!(c.take_(5).size_hint(), (5, Some(5))); + assert_eq!(c.take(5).size_hint(), (5, Some(5))); assert_eq!(c.skip(5).size_hint().second(), None); assert_eq!(c.take_while(|_| false).size_hint(), (0, None)); assert_eq!(c.skip_while(|_| false).size_hint(), (0, None)); @@ -1781,8 +1779,8 @@ mod tests { assert_eq!(c.map(|_| 0).size_hint(), (uint::max_value, None)); assert_eq!(c.filter_map(|_| Some(0)).size_hint(), (0, None)); - assert_eq!(vi.take_(5).size_hint(), (5, Some(5))); - assert_eq!(vi.take_(12).size_hint(), (10, Some(10))); + assert_eq!(vi.take(5).size_hint(), (5, Some(5))); + assert_eq!(vi.take(12).size_hint(), (10, Some(10))); assert_eq!(vi.skip(3).size_hint(), (7, Some(7))); assert_eq!(vi.skip(12).size_hint(), (0, Some(0))); assert_eq!(vi.take_while(|_| false).size_hint(), (0, Some(10))); @@ -2001,10 +1999,10 @@ mod tests { fn test_random_access_take() { let xs = [1, 2, 3, 4, 5]; let empty: &[int] = []; - check_randacc_iter(xs.iter().take_(3), 3); - check_randacc_iter(xs.iter().take_(20), xs.len()); - check_randacc_iter(xs.iter().take_(0), 0); - check_randacc_iter(empty.iter().take_(2), 0); + check_randacc_iter(xs.iter().take(3), 3); + check_randacc_iter(xs.iter().take(20), xs.len()); + check_randacc_iter(xs.iter().take(0), 0); + check_randacc_iter(empty.iter().take(2), 0); } #[test] @@ -2019,8 +2017,8 @@ mod tests { fn test_random_access_peek() { let xs = [1, 2, 3, 4, 5]; - // test .map and .peek_ that don't implement Clone - let it = xs.iter().peek_(|_| {}); + // test .map and .peek that don't implement Clone + let it = xs.iter().peek(|_| {}); assert_eq!(xs.len(), it.indexable()); for (i, elt) in xs.iter().enumerate() { assert_eq!(Some(elt), it.idx(i)); @@ -2032,7 +2030,7 @@ mod tests { fn test_random_access_map() { let xs = [1, 2, 3, 4, 5]; - // test .map and .peek_ that don't implement Clone + // test .map and .peek that don't implement Clone let it = xs.iter().map(|x| *x); assert_eq!(xs.len(), it.indexable()); for (i, elt) in xs.iter().enumerate() { @@ -2044,7 +2042,7 @@ mod tests { fn test_random_access_cycle() { let xs = [1, 2, 3, 4, 5]; let empty: &[int] = []; - check_randacc_iter(xs.iter().cycle().take_(27), 27); + check_randacc_iter(xs.iter().cycle().take(27), 27); check_randacc_iter(empty.iter().cycle(), 0); } From 60c2661684b5a7c07a7bf951567aaca0ca6bcf93 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 20:20:05 -0700 Subject: [PATCH 17/23] std: Iterator.flat_map_ -> .flat_map --- src/libstd/iterator.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index e723121564969..86a0b6b8d8ca7 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -262,7 +262,7 @@ pub trait Iterator { /// ~~~ {.rust} /// let xs = [2u, 3]; /// let ys = [0u, 1, 0, 1, 2]; - /// let mut it = xs.iter().flat_map_(|&x| count(0u, 1).take(x)); + /// let mut it = xs.iter().flat_map(|&x| count(0u, 1).take(x)); /// // Check that `it` has the same elements as `ys` /// let mut i = 0; /// for x: uint in it { @@ -270,9 +270,8 @@ pub trait Iterator { /// i += 1; /// } /// ~~~ - // FIXME: #5898: should be called `flat_map` #[inline] - fn flat_map_<'r, B, U: Iterator>(self, f: &'r fn(A) -> U) + fn flat_map<'r, B, U: Iterator>(self, f: &'r fn(A) -> U) -> FlatMap<'r, A, Self, U> { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -1644,7 +1643,7 @@ mod tests { fn test_iterator_flat_map() { let xs = [0u, 3, 6]; let ys = [0u, 1, 2, 3, 4, 5, 6, 7, 8]; - let mut it = xs.iter().flat_map_(|&x| count(x, 1).take(3)); + let mut it = xs.iter().flat_map(|&x| count(x, 1).take(3)); let mut i = 0; for x in it { assert_eq!(x, ys[i]); @@ -1937,7 +1936,7 @@ mod tests { fn test_double_ended_flat_map() { let u = [0u,1]; let v = [5,6,7,8]; - let mut it = u.iter().flat_map_(|x| v.slice(*x, v.len()).iter()); + let mut it = u.iter().flat_map(|x| v.slice(*x, v.len()).iter()); assert_eq!(it.next_back().unwrap(), &8); assert_eq!(it.next().unwrap(), &5); assert_eq!(it.next_back().unwrap(), &7); From 1db62d8311cba10c9f5f2ce38543fec7dad5b9c9 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 20:22:59 -0700 Subject: [PATCH 18/23] std: Iterator.chain_ -> .chain --- src/librustc/middle/trans/monomorphize.rs | 6 +++--- src/libstd/hashmap.rs | 4 ++-- src/libstd/iterator.rs | 16 ++++++++-------- src/libsyntax/ext/ifmt.rs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 14a69f10c4012..740ba884fb7b8 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -366,12 +366,12 @@ pub fn make_mono_id(ccx: @mut CrateContext, param_uses: Option<@~[type_use::type_uses]>) -> mono_id { // FIXME (possibly #5801): Need a lot of type hints to get // .collect() to work. - let substs_iter = substs.self_ty.iter().chain_(substs.tys.iter()); + let substs_iter = substs.self_ty.iter().chain(substs.tys.iter()); let precise_param_ids: ~[(ty::t, Option<@~[mono_id]>)] = match substs.vtables { Some(vts) => { debug!("make_mono_id vtables=%s substs=%s", vts.repr(ccx.tcx), substs.tys.repr(ccx.tcx)); - let vts_iter = substs.self_vtables.iter().chain_(vts.iter()); + let vts_iter = substs.self_vtables.iter().chain(vts.iter()); vts_iter.zip(substs_iter).map(|(vtable, subst)| { let v = vtable.map(|vt| meth::vtable_id(ccx, vt)); (*subst, if !v.is_empty() { Some(@v) } else { None }) @@ -387,7 +387,7 @@ pub fn make_mono_id(ccx: @mut CrateContext, // We just say it is fully used. let self_use = substs.self_ty.map(|_| type_use::use_repr|type_use::use_tydesc); - let uses_iter = self_use.iter().chain_(uses.iter()); + let uses_iter = self_use.iter().chain(uses.iter()); precise_param_ids.iter().zip(uses_iter).map(|(id, uses)| { if ccx.sess.no_monomorphic_collapse() { diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 5fe47dc6603b5..7a22477685911 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -724,7 +724,7 @@ impl HashSet { /// Visit the values representing the symmetric difference pub fn symmetric_difference_iter<'a>(&'a self, other: &'a HashSet) -> Chain, SetAlgebraIter<'a, T>> { - self.difference_iter(other).chain_(other.difference_iter(self)) + self.difference_iter(other).chain(other.difference_iter(self)) } /// Visit the values representing the intersection @@ -740,7 +740,7 @@ impl HashSet { /// Visit the values representing the union pub fn union_iter<'a>(&'a self, other: &'a HashSet) -> Chain, SetAlgebraIter<'a, T>> { - self.iter().chain_(other.difference_iter(self)) + self.iter().chain(other.difference_iter(self)) } } diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 86a0b6b8d8ca7..944b568db3f7d 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -59,13 +59,13 @@ pub trait Iterator { /// ~~~ {.rust} /// let a = [0]; /// let b = [1]; - /// let mut it = a.iter().chain_(b.iter()); + /// let mut it = a.iter().chain(b.iter()); /// assert_eq!(it.next().get(), &0); /// assert_eq!(it.next().get(), &1); /// assert!(it.next().is_none()); /// ~~~ #[inline] - fn chain_>(self, other: U) -> Chain { + fn chain>(self, other: U) -> Chain { Chain{a: self, b: other, flag: false} } @@ -1534,7 +1534,7 @@ mod tests { let xs = [0u, 1, 2, 3, 4, 5]; let ys = [30u, 40, 50, 60]; let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60]; - let mut it = xs.iter().chain_(ys.iter()); + let mut it = xs.iter().chain(ys.iter()); let mut i = 0; for &x in it { assert_eq!(x, expected[i]); @@ -1543,7 +1543,7 @@ mod tests { assert_eq!(i, expected.len()); let ys = count(30u, 10).take(4); - let mut it = xs.iter().map(|&x| x).chain_(ys); + let mut it = xs.iter().map(|&x| x).chain(ys); let mut i = 0; for x in it { assert_eq!(x, expected[i]); @@ -1771,7 +1771,7 @@ mod tests { assert_eq!(c.take_while(|_| false).size_hint(), (0, None)); assert_eq!(c.skip_while(|_| false).size_hint(), (0, None)); assert_eq!(c.enumerate().size_hint(), (uint::max_value, None)); - assert_eq!(c.chain_(vi.map(|&i| i)).size_hint(), (uint::max_value, None)); + assert_eq!(c.chain(vi.map(|&i| i)).size_hint(), (uint::max_value, None)); assert_eq!(c.zip(vi).size_hint(), (10, Some(10))); assert_eq!(c.scan(0, |_,_| Some(0)).size_hint(), (0, None)); assert_eq!(c.filter(|_| false).size_hint(), (0, None)); @@ -1785,7 +1785,7 @@ mod tests { assert_eq!(vi.take_while(|_| false).size_hint(), (0, Some(10))); assert_eq!(vi.skip_while(|_| false).size_hint(), (0, Some(10))); assert_eq!(vi.enumerate().size_hint(), (10, Some(10))); - assert_eq!(vi.chain_(v2.iter()).size_hint(), (13, Some(13))); + assert_eq!(vi.chain(v2.iter()).size_hint(), (13, Some(13))); assert_eq!(vi.zip(v2.iter()).size_hint(), (3, Some(3))); assert_eq!(vi.scan(0, |_,_| Some(0)).size_hint(), (0, Some(10))); assert_eq!(vi.filter(|_| false).size_hint(), (0, Some(10))); @@ -1900,7 +1900,7 @@ mod tests { fn test_double_ended_chain() { let xs = [1, 2, 3, 4, 5]; let ys = ~[7, 9, 11]; - let mut it = xs.iter().chain_(ys.iter()).invert(); + let mut it = xs.iter().chain(ys.iter()).invert(); assert_eq!(it.next().unwrap(), &11) assert_eq!(it.next().unwrap(), &9) assert_eq!(it.next_back().unwrap(), &1) @@ -1953,7 +1953,7 @@ mod tests { fn test_random_access_chain() { let xs = [1, 2, 3, 4, 5]; let ys = ~[7, 9, 11]; - let mut it = xs.iter().chain_(ys.iter()); + let mut it = xs.iter().chain(ys.iter()); assert_eq!(it.idx(0).unwrap(), &1); assert_eq!(it.idx(5).unwrap(), &7); assert_eq!(it.idx(7).unwrap(), &11); diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index a44201544d58a..9fd325798d76d 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -576,7 +576,7 @@ impl Context { } let args = names.move_iter().map(|a| a.unwrap()); - let mut args = locals.move_iter().chain_(args); + let mut args = locals.move_iter().chain(args); // Next, build up the actual call to the sprintf function. let result = self.ecx.expr_call_global(self.fmtsp, ~[ From 74d2552b0ab671a7455b5a60972c0cc6e3ecdb82 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 20:25:45 -0700 Subject: [PATCH 19/23] std: Iterator.last_ -> .last --- src/libstd/iterator.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 944b568db3f7d..811adb53cb40f 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -381,9 +381,8 @@ pub trait Iterator { /// let a = [1, 2, 3, 4, 5]; /// assert!(a.iter().last().get() == &5); /// ~~~ - // FIXME: #5898: should be called `last` #[inline] - fn last_(&mut self) -> Option { + fn last(&mut self) -> Option { let mut last = None; for x in *self { last = Some(x); } last @@ -1712,8 +1711,8 @@ mod tests { #[test] fn test_iterator_last() { let v = &[0, 1, 2, 3, 4]; - assert_eq!(v.iter().last_().unwrap(), &4); - assert_eq!(v.slice(0, 1).iter().last_().unwrap(), &0); + assert_eq!(v.iter().last().unwrap(), &4); + assert_eq!(v.slice(0, 1).iter().last().unwrap(), &0); } #[test] From f9dee04aaabc0ee38f91744e07fe67f36ec6c8e9 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 20:30:03 -0700 Subject: [PATCH 20/23] std: Iterator.len_ -> .len --- src/compiletest/runtest.rs | 2 +- src/libextra/dlist.rs | 8 ++++---- src/librustpkg/version.rs | 4 ++-- src/libstd/iterator.rs | 13 ++++++------- src/libstd/str.rs | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index d325341d157aa..0fb64152d376c 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -938,7 +938,7 @@ fn disassemble_extract(config: &config, _props: &TestProps, fn count_extracted_lines(p: &Path) -> uint { let x = io::read_whole_file_str(&p.with_filetype("ll")).unwrap(); - x.line_iter().len_() + x.line_iter().len() } diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 3e1038b2b4e83..19a72b0029fb2 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -1077,7 +1077,7 @@ mod tests { let v = &[0, ..128]; let m: DList = v.iter().map(|&x|x).collect(); do b.iter { - assert!(m.iter().len_() == 128); + assert!(m.iter().len() == 128); } } #[bench] @@ -1085,7 +1085,7 @@ mod tests { let v = &[0, ..128]; let mut m: DList = v.iter().map(|&x|x).collect(); do b.iter { - assert!(m.mut_iter().len_() == 128); + assert!(m.mut_iter().len() == 128); } } #[bench] @@ -1093,7 +1093,7 @@ mod tests { let v = &[0, ..128]; let m: DList = v.iter().map(|&x|x).collect(); do b.iter { - assert!(m.rev_iter().len_() == 128); + assert!(m.rev_iter().len() == 128); } } #[bench] @@ -1101,7 +1101,7 @@ mod tests { let v = &[0, ..128]; let mut m: DList = v.iter().map(|&x|x).collect(); do b.iter { - assert!(m.mut_rev_iter().len_() == 128); + assert!(m.mut_rev_iter().len() == 128); } } } diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index ab4f47ba69abc..44cb8065b382b 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -200,7 +200,7 @@ fn try_parsing_version(s: &str) -> Option { /// Just an approximation fn is_url_like(p: &Path) -> bool { let str = p.to_str(); - str.split_iter('/').len_() > 2 + str.split_iter('/').len() > 2 } /// If s is of the form foo#bar, where bar is a valid version @@ -215,7 +215,7 @@ pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, Vers for st in s.split_iter(sep) { debug!("whole = %s part = %s", s, st); } - if s.split_iter(sep).len_() > 2 { + if s.split_iter(sep).len() > 2 { return None; } match s.rfind(sep) { diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 811adb53cb40f..dc9550f6e4d46 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -409,7 +409,6 @@ pub trait Iterator { accum } - // FIXME: #5898: should be called len /// Counts the number of elements in this iterator. /// /// # Example @@ -417,11 +416,11 @@ pub trait Iterator { /// ~~~ {.rust} /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter(); - /// assert!(it.len_() == 5); - /// assert!(it.len_() == 0); + /// assert!(it.len() == 5); + /// assert!(it.len() == 0); /// ~~~ #[inline] - fn len_(&mut self) -> uint { + fn len(&mut self) -> uint { self.fold(0, |cnt, _x| cnt + 1) } @@ -1718,9 +1717,9 @@ mod tests { #[test] fn test_iterator_len() { let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - assert_eq!(v.slice(0, 4).iter().len_(), 4); - assert_eq!(v.slice(0, 10).iter().len_(), 10); - assert_eq!(v.slice(0, 0).iter().len_(), 0); + assert_eq!(v.slice(0, 4).iter().len(), 4); + assert_eq!(v.slice(0, 10).iter().len(), 10); + assert_eq!(v.slice(0, 0).iter().len(), 0); } #[test] diff --git a/src/libstd/str.rs b/src/libstd/str.rs index b2c0b5a4fb22f..df71a6f054a2a 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1593,7 +1593,7 @@ impl<'self> StrSlice<'self> for &'self str { /// Returns the number of characters that a string holds #[inline] - fn char_len(&self) -> uint { self.iter().len_() } + fn char_len(&self) -> uint { self.iter().len() } /// Returns a slice of the given string from the byte range /// [`begin`..`end`) From 6fcf2ee8e341c594fe9b9c148e13a4cb8ce6b4a3 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 9 Aug 2013 20:49:29 -0700 Subject: [PATCH 21/23] std: Transform.find_ -> .find --- src/librust/rust.rs | 2 +- src/librustc/driver/driver.rs | 2 +- src/librustc/metadata/creader.rs | 2 +- src/librustc/middle/check_match.rs | 10 +++++----- src/librustc/middle/trans/_match.rs | 4 ++-- src/librustc/middle/trans/base.rs | 2 +- src/librustc/middle/trans/consts.rs | 2 +- src/librustc/middle/trans/meth.rs | 2 +- src/librustc/middle/trans/monomorphize.rs | 2 +- src/librustc/middle/ty.rs | 2 +- src/librustc/middle/typeck/check/mod.rs | 2 +- src/librustc/middle/typeck/collect.rs | 2 +- src/librustdoc/attr_pass.rs | 2 +- src/librustdoc/config.rs | 2 +- src/librustdoc/prune_private_pass.rs | 2 +- src/librustdoc/tystr_pass.rs | 6 +++--- src/librusti/rusti.rs | 2 +- src/librustpkg/package_source.rs | 2 +- src/libstd/iterator.rs | 8 ++++---- src/libstd/str.rs | 4 ++-- src/libsyntax/attr.rs | 4 ++-- 21 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/librust/rust.rs b/src/librust/rust.rs index 010486cdf855c..b8f81a44759ce 100644 --- a/src/librust/rust.rs +++ b/src/librust/rust.rs @@ -128,7 +128,7 @@ fn rustc_help() { } fn find_cmd(command_string: &str) -> Option { - do COMMANDS.iter().find_ |command| { + do COMMANDS.iter().find |command| { command.cmd == command_string }.map_move(|x| *x) } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index fdd7c9231b155..fdf887574695f 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -946,7 +946,7 @@ pub fn build_output_filenames(input: &input, let linkage_metas = attr::find_linkage_metas(attrs); if !linkage_metas.is_empty() { // But if a linkage meta is present, that overrides - let maybe_name = linkage_metas.iter().find_(|m| "name" == m.name()); + let maybe_name = linkage_metas.iter().find(|m| "name" == m.name()); match maybe_name.chain(|m| m.value_str()) { Some(s) => stem = s, _ => () diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index bc9085b6887d1..82f5c4f88435a 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -183,7 +183,7 @@ fn visit_item(e: &Env, i: @ast::item) { match fm.sort { ast::named => { let link_name = i.attrs.iter() - .find_(|at| "link_name" == at.name()) + .find(|at| "link_name" == at.name()) .chain(|at| at.value_str()); let foreign_name = match link_name { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 81bd2491c6987..b640181515b38 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -169,7 +169,7 @@ pub fn check_exhaustive(cx: &MatchCheckCtxt, sp: span, pats: ~[@pat]) { }; let variants = ty::enum_variants(cx.tcx, id); - match variants.iter().find_(|v| v.id == vid) { + match variants.iter().find(|v| v.id == vid) { Some(v) => Some(cx.tcx.sess.str_of(v.name)), None => { fail!("check_exhaustive: bad variant in ctor") @@ -222,7 +222,7 @@ pub enum ctor { pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful { if m.len() == 0u { return useful_; } if m[0].len() == 0u { return not_useful; } - let real_pat = match m.iter().find_(|r| r[0].id != 0) { + let real_pat = match m.iter().find(|r| r[0].id != 0) { Some(r) => r[0], None => v[0] }; let left_ty = if real_pat.id == 0 { ty::mk_nil() } @@ -470,7 +470,7 @@ pub fn ctor_arity(cx: &MatchCheckCtxt, ctor: &ctor, ty: ty::t) -> uint { ty::ty_enum(eid, _) => { let id = match *ctor { variant(id) => id, _ => fail!("impossible case") }; - match ty::enum_variants(cx.tcx, eid).iter().find_(|v| v.id == id ) { + match ty::enum_variants(cx.tcx, eid).iter().find(|v| v.id == id ) { Some(v) => v.args.len(), None => fail!("impossible case") } @@ -627,7 +627,7 @@ pub fn specialize(cx: &MatchCheckCtxt, if variant(variant_id) == *ctor_id { // FIXME #4731: Is this right? --pcw let args = flds.map(|ty_field| { - match flds.iter().find_(|f| + match flds.iter().find(|f| f.ident == ty_field.ident) { Some(f) => f.pat, _ => wild() @@ -658,7 +658,7 @@ pub fn specialize(cx: &MatchCheckCtxt, } } let args = class_fields.iter().map(|class_field| { - match flds.iter().find_(|f| + match flds.iter().find(|f| f.ident == class_field.ident) { Some(f) => f.pat, _ => wild() diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 327d2e698c1e1..1a9c36313df74 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -588,7 +588,7 @@ fn enter_opt<'r>(bcx: @mut Block, let mut reordered_patterns = ~[]; let r = ty::lookup_struct_fields(tcx, struct_id); for field in r.iter() { - match field_pats.iter().find_(|p| p.ident == field.ident) { + match field_pats.iter().find(|p| p.ident == field.ident) { None => reordered_patterns.push(dummy), Some(fp) => reordered_patterns.push(fp.pat) } @@ -648,7 +648,7 @@ fn enter_rec_or_struct<'r>(bcx: @mut Block, ast::pat_struct(_, ref fpats, _) => { let mut pats = ~[]; for fname in fields.iter() { - match fpats.iter().find_(|p| p.ident == *fname) { + match fpats.iter().find(|p| p.ident == *fname) { None => pats.push(dummy), Some(pat) => pats.push(pat.pat) } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 6b51832e8e337..f89327c10afc0 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1277,7 +1277,7 @@ pub fn cleanup_and_leave(bcx: @mut Block, let mut skip = 0; let mut dest = None; { - let r = (*inf).cleanup_paths.rev_iter().find_(|cp| cp.target == leave); + let r = (*inf).cleanup_paths.rev_iter().find(|cp| cp.target == leave); for cp in r.iter() { if cp.size == inf.cleanups.len() { Br(bcx, cp.dest); diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index bdac0925273bf..1992d71427f20 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -500,7 +500,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef { |discr, field_tys| { let cs: ~[ValueRef] = field_tys.iter().enumerate() .map(|(ix, &field_ty)| { - match fs.iter().find_(|f| field_ty.ident == f.ident) { + match fs.iter().find(|f| field_ty.ident == f.ident) { Some(f) => const_expr(cx, (*f).expr), None => { match base_val { diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index f2c63164c8238..4cc4f8fa696d0 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -288,7 +288,7 @@ pub fn method_with_name(ccx: &mut CrateContext, let imp = ccx.tcx.impls.find(&impl_id) .expect("could not find impl while translating"); - let meth = imp.methods.iter().find_(|m| m.ident == name) + let meth = imp.methods.iter().find(|m| m.ident == name) .expect("could not find method while translating"); ccx.impl_method_cache.insert((impl_id, name), meth.def_id); diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 740ba884fb7b8..21ef9058069ab 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -245,7 +245,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext, } ast_map::node_variant(ref v, enum_item, _) => { let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id)); - let this_tv = *tvs.iter().find_(|tv| { tv.id.node == fn_id.node}).unwrap(); + let this_tv = *tvs.iter().find(|tv| { tv.id.node == fn_id.node}).unwrap(); let d = mk_lldecl(); set_inline_hint(d); match v.node.kind { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 4a576ff3bb000..bba5d85083b70 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4117,7 +4117,7 @@ pub fn lookup_struct_field(cx: ctxt, field_id: ast::def_id) -> field_ty { let r = lookup_struct_fields(cx, parent); - match r.iter().find_( + match r.iter().find( |f| f.id.node == field_id.node) { Some(t) => *t, None => cx.sess.bug("struct ID not found in parent's fields") diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f31251bda9951..8bc3241256875 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1122,7 +1122,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt, fieldname: ast::ident, substs: &ty::substs) -> Option { - let o_field = items.iter().find_(|f| f.ident == fieldname); + let o_field = items.iter().find(|f| f.ident == fieldname); do o_field.map() |f| { ty::lookup_field_type(tcx, class_id, f.id, substs) } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 94cf5b431bafa..b5516fcc8eba6 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -675,7 +675,7 @@ pub fn check_methods_against_trait(ccx: &CrateCtxt, // we'll catch it in coherence let trait_ms = ty::trait_methods(tcx, trait_ref.def_id); for impl_m in impl_ms.iter() { - match trait_ms.iter().find_(|trait_m| trait_m.ident == impl_m.mty.ident) { + match trait_ms.iter().find(|trait_m| trait_m.ident == impl_m.mty.ident) { Some(trait_m) => { let num_impl_tps = generics.ty_params.len(); compare_impl_method( diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index d68f1f112e008..b5503cc51e10c 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -133,7 +133,7 @@ fn fold_enum( node: ast::item_enum(ref enum_definition, _), _ }, _) => { let ast_variant = - (*enum_definition.variants.iter().find_(|v| { + (*enum_definition.variants.iter().find(|v| { to_str(v.node.name) == variant.name }).unwrap()).clone(); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 3598eb7c0fb9b..877338902cc07 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -221,7 +221,7 @@ pub fn maybe_find_pandoc( } }; - let pandoc = do possible_pandocs.iter().find_ |&pandoc| { + let pandoc = do possible_pandocs.iter().find |&pandoc| { let output = process_output(*pandoc, [~"--version"]); debug!("testing pandoc cmd %s: %?", *pandoc, output); output.status == 0 diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 0ee0889cb9fee..e1bc059e20f9c 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -81,7 +81,7 @@ fn strip_priv_methods( item_vis: ast::visibility ) -> doc::ImplDoc { let methods = do doc.methods.iter().filter |method| { - let ast_method = do methods.iter().find_ |m| { + let ast_method = do methods.iter().find |m| { extract::to_str(m.ident) == method.name }; assert!(ast_method.is_some()); diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index e9c6dcd08623c..aa4407af76d2e 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -133,7 +133,7 @@ fn fold_enum( node: ast::item_enum(ref enum_definition, _), _ }, _) => { let ast_variant = - (*do enum_definition.variants.iter().find_ |v| { + (*do enum_definition.variants.iter().find |v| { to_str(v.node.name) == variant.name }.unwrap()).clone(); @@ -187,7 +187,7 @@ fn get_method_sig( ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { - match methods.iter().find_(|&method| { + match methods.iter().find(|&method| { match (*method).clone() { ast::required(ty_m) => to_str(ty_m.ident) == method_name, ast::provided(m) => to_str(m.ident) == method_name, @@ -223,7 +223,7 @@ fn get_method_sig( ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref methods), _ }, _) => { - match methods.iter().find_(|method| { + match methods.iter().find(|method| { to_str(method.ident) == method_name }) { Some(method) => { diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index 0f8644ad837e4..29ad9eb49a3b1 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -315,7 +315,7 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option { // file, skip compilation and return None. let mut should_compile = true; let dir = os::list_dir_path(&Path(outputs.out_filename.dirname())); - let maybe_lib_path = do dir.iter().find_ |file| { + let maybe_lib_path = do dir.iter().find |file| { // The actual file's name has a hash value and version // number in it which is unknown at this time, so looking // for a file that matches out_filename won't work, diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 9833e18e016b6..ff485342fbe98 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -55,7 +55,7 @@ impl PkgSrc { let dir; let dirs = pkgid_src_in_workspace(&self.id, &self.root); debug!("Checking dirs: %?", dirs); - let path = dirs.iter().find_(|&d| os::path_exists(d)); + let path = dirs.iter().find(|&d| os::path_exists(d)); match path { Some(d) => dir = (*d).clone(), None => dir = match self.fetch_git() { diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index dc9550f6e4d46..a7a1c0bede8db 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -458,7 +458,7 @@ pub trait Iterator { /// Return the first element satisfying the specified predicate #[inline] - fn find_(&mut self, predicate: &fn(&A) -> bool) -> Option { + fn find(&mut self, predicate: &fn(&A) -> bool) -> Option { for x in *self { if predicate(&x) { return Some(x) } } @@ -1819,9 +1819,9 @@ mod tests { #[test] fn test_find() { let v: &[int] = &[1, 3, 9, 27, 103, 14, 11]; - assert_eq!(*v.iter().find_(|x| *x & 1 == 0).unwrap(), 14); - assert_eq!(*v.iter().find_(|x| *x % 3 == 0).unwrap(), 3); - assert!(v.iter().find_(|x| *x % 12 == 0).is_none()); + assert_eq!(*v.iter().find(|x| *x & 1 == 0).unwrap(), 14); + assert_eq!(*v.iter().find(|x| *x % 3 == 0).unwrap(), 3); + assert!(v.iter().find(|x| *x % 12 == 0).is_none()); } #[test] diff --git a/src/libstd/str.rs b/src/libstd/str.rs index df71a6f054a2a..820c344f73938 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -59,7 +59,7 @@ pub fn from_bytes(vv: &[u8]) -> ~str { use str::not_utf8::cond; if !is_utf8(vv) { - let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap(); + let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap(); cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", first_bad_byte as uint)) } else { @@ -76,7 +76,7 @@ pub fn from_bytes_owned(vv: ~[u8]) -> ~str { use str::not_utf8::cond; if !is_utf8(vv) { - let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap(); + let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap(); cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", first_bad_byte as uint)) } else { diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index e0160db81fd97..b0dda2b7dc89f 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -186,13 +186,13 @@ pub fn contains_name(metas: &[AM], name: &str) -> bool { pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) -> Option<@str> { attrs.iter() - .find_(|at| name == at.name()) + .find(|at| name == at.name()) .chain(|at| at.value_str()) } pub fn last_meta_item_value_str_by_name(items: &[@MetaItem], name: &str) -> Option<@str> { - items.rev_iter().find_(|mi| name == mi.name()).chain(|i| i.value_str()) + items.rev_iter().find(|mi| name == mi.name()).chain(|i| i.value_str()) } /* Higher-level applications */ From e48ca19bc594f880ea99e005dbbfdd3d2f70759e Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sat, 10 Aug 2013 07:13:47 -0700 Subject: [PATCH 22/23] std: fix the non-stage0 str::raw::slice_bytes which broke in a merge --- src/libstd/str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 820c344f73938..26a00cca4c82b 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1051,7 +1051,7 @@ pub mod raw { /// If end is greater than the length of the string. #[cfg(not(stage0))] #[inline] - pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str { + pub unsafe fn slice_bytes<'a>(s: &'a str, begin: uint, end: uint) -> &'a str { do s.as_imm_buf |sbuf, n| { assert!((begin <= end)); assert!((end <= n)); From 5b2c1c543fb7e2201ff2c7c579fafef670b149e0 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sat, 10 Aug 2013 07:14:10 -0700 Subject: [PATCH 23/23] syntax and rustc: fix some warnings --- src/librustc/back/rpath.rs | 2 +- src/librustc/metadata/filesearch.rs | 1 - src/libsyntax/ext/ifmt.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index e07400c79b0e4..e7706815ff537 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -14,7 +14,7 @@ use metadata::cstore; use metadata::filesearch; use std::hashmap::HashSet; -use std::{num, os, path, uint, util, vec}; +use std::{os, util, vec}; fn not_win32(os: session::os) -> bool { os != session::os_win32 diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 2b44d793a9d38..56200a221be37 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -11,7 +11,6 @@ use std::option; use std::os; -use std::{result, str}; use std::hashmap::HashSet; // A module for searching for libraries diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index 9fd325798d76d..a3adb42425ae2 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -685,7 +685,7 @@ pub fn expand_syntax_ext(ecx: @ExtCtxt, sp: span, }; cx.fmtsp = efmt.span; let fmt = expr_to_str(ecx, efmt, - ~"first argument to ifmt! must be a string literal."); + "first argument to ifmt! must be a string literal."); let mut err = false; do parse::parse_error::cond.trap(|m| {