diff options
| author | Graham Fawcett <fawcett@uwindsor.ca> | 2012-01-18 15:18:26 -0500 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-01-21 13:31:12 -0800 |
| commit | 35d12be2ce6f62ce75b4f59c2932415dc8b7b786 (patch) | |
| tree | 408b7bd64a8cdfd53a36a88f1867b93514b6928b /src | |
| parent | 818b646950e69410c6328a1fe914e7a4edf6de72 (diff) | |
| download | rust-35d12be2ce6f62ce75b4f59c2932415dc8b7b786.tar.gz rust-35d12be2ce6f62ce75b4f59c2932415dc8b7b786.zip | |
fix #1352: change param order on vec::init_fn (and vec::init_fn_mut), putting block in final position.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/middle/typeck.rs | 8 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 12 | ||||
| -rw-r--r-- | src/libstd/bitv.rs | 2 | ||||
| -rw-r--r-- | src/libstd/getopts.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/shootout-fannkuchredux.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/sudoku.rs | 4 |
6 files changed, 15 insertions, 15 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index cfeddd46050..bc6cd6ee14b 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -142,7 +142,7 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path, tpt: ty_param_bounds_and_ty, sp: span) -> ty_param_substs_opt_and_ty { let ty_param_count = vec::len(*tpt.bounds); - let vars = vec::init_fn({|_i| next_ty_var(fcx)}, ty_param_count); + let vars = vec::init_fn(ty_param_count, {|_i| next_ty_var(fcx)}); let ty_substs_len = vec::len(pth.node.types); if ty_substs_len > 0u { let param_var_len = vec::len(vars); @@ -611,9 +611,9 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method, } else { let impl_fty = ty::mk_fn(tcx, impl_m.fty); // Add dummy substs for the parameters of the impl method - let substs = substs + vec::init_fn({|i| + let substs = substs + vec::init_fn(vec::len(*if_m.tps), {|i| ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0}) - }, vec::len(*if_m.tps)); + }); let if_fty = ty::substitute_type_params(tcx, substs, ty::mk_fn(tcx, if_m.fty)); alt ty::unify::unify(impl_fty, if_fty, ty::unify::precise, tcx) { @@ -2334,7 +2334,7 @@ fn next_ty_var(fcx: @fn_ctxt) -> ty::t { fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint) -> {vars: [ty::t], ty: ty::t} { - let vars = vec::init_fn({|_i| next_ty_var(fcx)}, count); + let vars = vec::init_fn(count, {|_i| next_ty_var(fcx)}); {vars: vars, ty: ty::substitute_type_params(fcx.ccx.tcx, vars, tp)} } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 1868c79e97b..918b99d1b8a 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -88,7 +88,7 @@ Creates and initializes an immutable vector. Creates an immutable vector of size `n_elts` and initializes the elements to the value returned by the function `op`. */ -fn init_fn<T>(op: init_op<T>, n_elts: uint) -> [T] { +fn init_fn<T>(n_elts: uint, op: init_op<T>) -> [T] { let v = []; reserve(v, n_elts); let i: uint = 0u; @@ -105,7 +105,7 @@ Creates and initializes a mutable vector. Creates a mutable vector of size `n_elts` and initializes the elements to the value returned by the function `op`. */ -fn init_fn_mut<T>(op: init_op<T>, n_elts: uint) -> [mutable T] { +fn init_fn_mut<T>(n_elts: uint, op: init_op<T>) -> [mutable T] { let v = [mutable]; reserve(v, n_elts); let i: uint = 0u; @@ -365,13 +365,13 @@ Function: grow_fn Expands a vector in place, initializing the new elements to the result of a function -Function `init_fn` is called `n` times with the values [0..`n`) +Function `init_op` is called `n` times with the values [0..`n`) Parameters: v - The vector to grow n - The number of elements to add -init_fn - A function to call to retreive each appended element's value +init_op - A function to call to retreive each appended element's value */ fn grow_fn<T>(&v: [T], n: uint, op: init_op<T>) { reserve(v, next_power_of_two(len(v) + n)); @@ -1026,14 +1026,14 @@ mod tests { #[test] fn test_init_fn() { // Test on-stack init_fn. - let v = init_fn(square, 3u); + let v = init_fn(3u, square); assert (len(v) == 3u); assert (v[0] == 0u); assert (v[1] == 1u); assert (v[2] == 4u); // Test on-heap init_fn. - v = init_fn(square, 5u); + v = init_fn(5u, square); assert (len(v) == 5u); assert (v[0] == 0u); assert (v[1] == 1u); diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 30af05a9c49..8296398c9e6 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -267,7 +267,7 @@ in the resulting vector has either value 0u or 1u. */ fn to_vec(v: t) -> [uint] { let sub = bind init_to_vec(v, _); - ret vec::init_fn::<uint>(sub, v.nbits); + ret vec::init_fn::<uint>(v.nbits, sub); } /* diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 6c21ec1330e..b870dde34c6 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -212,7 +212,7 @@ err(fail_) - On failure. Use <fail_str> to get an error message. fn getopts(args: [str], opts: [opt]) -> result { let n_opts = vec::len::<opt>(opts); fn f(_x: uint) -> [optval] { ret []; } - let vals = vec::init_fn_mut::<[optval]>(f, n_opts); + let vals = vec::init_fn_mut::<[optval]>(n_opts, f); let free: [str] = []; let l = vec::len(args); let i = 0u; diff --git a/src/test/bench/shootout-fannkuchredux.rs b/src/test/bench/shootout-fannkuchredux.rs index eb61182e408..fce617b8d65 100644 --- a/src/test/bench/shootout-fannkuchredux.rs +++ b/src/test/bench/shootout-fannkuchredux.rs @@ -7,7 +7,7 @@ fn fannkuch(n: int) -> int { fn perm1init(i: uint) -> int { ret i as int; } let perm = vec::init_elt_mut(0, n as uint); - let perm1 = vec::init_fn_mut(perm1init, n as uint); + let perm1 = vec::init_fn_mut(n as uint, perm1init); let count = vec::init_elt_mut(0, n as uint); let f = 0; let i = 0; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index c6896a20044..e656bb650c5 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -31,7 +31,7 @@ enum grid_t { grid_ctor(grid), } fn read_grid(f: io::reader) -> grid_t { assert f.read_line() == "9,9"; /* assert first line is exactly "9,9" */ - let g = vec::init_fn({|_i| vec::init_elt_mut(0 as u8, 10u) }, 10u); + let g = vec::init_fn(10u, {|_i| vec::init_elt_mut(0 as u8, 10u) }); while !f.eof() { // FIXME: replace with unicode compliant call let comps = str::split(str::trim(f.read_line()), ',' as u8); @@ -130,7 +130,7 @@ fn write_grid(f: io::writer, g: grid_t) { fn main(args: [str]) { let grid = if vec::len(args) == 1u { // FIXME create sudoku inline since nested vec consts dont work yet - let g = vec::init_fn({|_i| vec::init_elt_mut(0 as u8, 10u) }, 10u); + let g = vec::init_fn(10u, {|_i| vec::init_elt_mut(0 as u8, 10u) }); g[0][1] = 4u8; g[0][3] = 6u8; g[0][7] = 3u8; |
