]> git.lizzy.rs Git - rust.git/commitdiff
Merge remote-tracking branch 'erickt/master'
authorBrian Anderson <banderson@mozilla.com>
Sun, 5 Feb 2012 23:15:21 +0000 (15:15 -0800)
committerBrian Anderson <banderson@mozilla.com>
Sun, 5 Feb 2012 23:15:21 +0000 (15:15 -0800)
Conflicts:
src/libcore/vec.rs
src/libstd/getopts.rs

1  2 
doc/tutorial.md
src/comp/middle/alias.rs
src/comp/middle/shape.rs
src/comp/middle/trans/base.rs
src/comp/middle/typeck.rs
src/libcore/vec.rs
src/libstd/getopts.rs
src/libstd/map.rs

diff --cc doc/tutorial.md
Simple merge
Simple merge
Simple merge
index f330c48d636a586361ac0ff2dafb532776978df6,03c98dfa827df708e2dcba7900a43e5efe9a8410..37e410e9d5c91c1359f9f34e771fab98f62a267a
@@@ -3387,15 -3370,12 +3387,15 @@@ fn trans_rec(bcx: @block_ctxt, fields: 
          ret bcx;
        }
        save_in(pos) { pos }
 +      _ { bcx_tcx(bcx).sess.bug("trans_rec: weird dest"); }
      };
  
 -    let ty_fields = alt ty::struct(bcx_tcx(bcx), t) { ty::ty_rec(f) { f } };
 +    let ty_fields = alt ty::struct(bcx_tcx(bcx), t) { ty::ty_rec(f) { f }
 +      _ { bcx_tcx(bcx).sess.bug("trans_rec: id doesn't\
 +           have a record type") } };
      let temp_cleanups = [];
      for fld in fields {
-         let ix = option::get(vec::position_pred(ty_fields, {|ft|
+         let ix = option::get(vec::position(ty_fields, {|ft|
              str::eq(fld.node.ident, ft.ident)
          }));
          let dst = GEP_tup_like_1(bcx, t, addr, [0, ix as int]);
index 9a37ec4a01880845cd4e5d4a4ec9a7d3b07b0d51,b91379246520f1c016e743e36655a2f554923f0f..50f5dd2100737b3b9ad64f076306f9b1f04a9c41
@@@ -1474,13 -1511,9 +1474,13 @@@ fn lookup_method(fcx: @fn_ctxt, isc: re
                ty::bound_iface(t) {
                  let (iid, tps) = alt ty::struct(tcx, t) {
                      ty::ty_iface(i, tps) { (i, tps) }
 +                    _ {
 +                        tcx.sess.span_bug(sp, "Undocument invariant in \
 +                          lookup_method");
 +                    }
                  };
                  let ifce_methods = ty::iface_methods(tcx, iid);
-                 alt vec::position_pred(*ifce_methods, {|m| m.ident == name}) {
+                 alt vec::position(*ifce_methods, {|m| m.ident == name}) {
                    some(pos) {
                      let m = ifce_methods[pos];
                      ret some({method_ty: ty::mk_fn(tcx, m.fty),
index bb88ad3c5617240912a72ad61c2af33943a543ce,dd256af1d6f56ef664069e0e9e99134be4b0a7bf..0dc5dea59bcd8050d036f3f69ecd865462a40411
@@@ -599,13 -727,53 +718,53 @@@ Apply function `f` to each element of `
  When function `f` returns true then an option containing the element
  is returned. If `f` matches no elements then none is returned.
  */
 -fn find<T: copy>(v: [T], f: fn(T) -> bool) -> option::t<T> {
 +fn find<T: copy>(v: [T], f: fn(T) -> bool) -> option<T> {
-     for elt: T in v { if f(elt) { ret some(elt); } }
-     ret none;
+     find_from(v, 0u, len(v), f)
  }
  
  /*
- Function: position
+ Function: find_from
+ Search for the first element that matches a given predicate within a range
+ Apply function `f` to each element of `v` within the range [`start`, `end`).
+ When function `f` returns true then an option containing the element
+ is returned. If `f` matches no elements then none is returned.
+ */
+ fn find_from<T: copy>(v: [T], start: uint, end: uint, f: fn(T) -> bool) ->
 -  option::t<T> {
++  option<T> {
+     option::map(position_from(v, start, end, f)) { |i| v[i] }
+ }
+ /*
+ Function: rfind
+ Search for the last element that matches a given predicate
+ Apply function `f` to each element of `v` in reverse order. When function `f`
+ returns true then an option containing the element is returned. If `f`
+ matches no elements then none is returned.
+ */
 -fn rfind<T: copy>(v: [T], f: fn(T) -> bool) -> option::t<T> {
++fn rfind<T: copy>(v: [T], f: fn(T) -> bool) -> option<T> {
+     rfind_from(v, 0u, len(v), f)
+ }
+ /*
+ Function: rfind_from
+ Search for the last element that matches a given predicate within a range
+ Apply function `f` to each element of `v` in reverse order within the range
+ [`start`, `end`). When function `f` returns true then an option containing
+ the element is returned. If `f` matches no elements then none is returned.
+ */
+ fn rfind_from<T: copy>(v: [T], start: uint, end: uint, f: fn(T) -> bool) ->
 -  option::t<T> {
++  option<T> {
+     option::map(rposition_from(v, start, end, f)) { |i| v[i] }
+ }
+ /*
+ Function: position_elt
  
  Find the first index containing a matching value
  
@@@ -614,20 -782,86 +773,86 @@@ Returns
  option::some(uint) - The first index containing a matching value
  option::none - No elements matched
  */
- fn position<T>(x: T, v: [T]) -> option<uint> {
-     let i: uint = 0u;
-     while i < len(v) { if x == v[i] { ret some::<uint>(i); } i += 1u; }
 -fn position_elt<T>(v: [T], x: T) -> option::t<uint> {
++fn position_elt<T>(v: [T], x: T) -> option<uint> {
+     position(v) { |y| x == y }
+ }
+ /*
+ Function: position
+ Find the first index matching some predicate
+ Apply function `f` to each element of `v`.  When function `f` returns true
+ then an option containing the index is returned. If `f` matches no elements
+ then none is returned.
+ */
 -fn position<T>(v: [T], f: fn(T) -> bool) -> option::t<uint> {
++fn position<T>(v: [T], f: fn(T) -> bool) -> option<uint> {
+     position_from(v, 0u, len(v), f)
+ }
+ /*
+ Function: position_from
+ Find the first index matching some predicate within a range
+ Apply function `f` to each element of `v` between the range [`start`, `end`).
+ When function `f` returns true then an option containing the index is
+ returned. If `f` matches no elements then none is returned.
+ */
+ fn position_from<T>(v: [T], start: uint, end: uint, f: fn(T) -> bool) ->
 -  option::t<uint> {
++  option<uint> {
+     assert start <= end;
+     assert end <= len(v);
+     let i = start;
+     while i < end { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
      ret none;
  }
  
  /*
- Function: position_pred
+ Function: rposition_elt
+ Find the last index containing a matching value
+ Returns:
+ option::some(uint) - The last index containing a matching value
+ option::none - No elements matched
+ */
 -fn rposition_elt<T>(v: [T], x: T) -> option::t<uint> {
++fn rposition_elt<T>(v: [T], x: T) -> option<uint> {
+     rposition(v) { |y| x == y }
+ }
+ /*
+ Function: rposition
+ Find the last index matching some predicate
  
- Find the first index for which the value matches some predicate
+ Apply function `f` to each element of `v` in reverse order.  When function
+ `f` returns true then an option containing the index is returned. If `f`
+ matches no elements then none is returned.
  */
- fn position_pred<T>(v: [T], f: fn(T) -> bool) -> option<uint> {
-     let i: uint = 0u;
-     while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
 -fn rposition<T>(v: [T], f: fn(T) -> bool) -> option::t<uint> {
++fn rposition<T>(v: [T], f: fn(T) -> bool) -> option<uint> {
+     rposition_from(v, 0u, len(v), f)
+ }
+ /*
+ Function: rposition_from
+ Find the last index matching some predicate within a range
+ Apply function `f` to each element of `v` in reverse order between the range
+ [`start`, `end`). When function `f` returns true then an option containing
+ the index is returned. If `f` matches no elements then none is returned.
+ */
+ fn rposition_from<T>(v: [T], start: uint, end: uint, f: fn(T) -> bool) ->
 -  option::t<uint> {
++  option<uint> {
+     assert start <= end;
+     assert end <= len(v);
+     let i = end;
+     while i > start {
+         if f(v[i - 1u]) { ret some::<uint>(i - 1u); }
+         i -= 1u;
+     }
      ret none;
  }
  
index bc96cb65efa680caf78be3d232c8477ef0ef33ba,c517a2f996df708ba81ccbb3c8615de6d3f681c7..48d83f0e5c2c825f452db3d15ca2382160ab2101
@@@ -148,8 -148,8 +148,8 @@@ fn name_str(nm: name) -> str 
      ret alt nm { short(ch) { str::from_char(ch) } long(s) { s } };
  }
  
 -fn find_opt(opts: [opt], nm: name) -> option::t<uint> {
 +fn find_opt(opts: [opt], nm: name) -> option<uint> {
-     vec::position_pred(opts, { |opt| opt.name == nm })
+     vec::position(opts, { |opt| opt.name == nm })
  }
  
  /*
Simple merge