Skip to content

Commit 35d12be

Browse files
gmfawcettbrson
authored andcommitted
fix #1352: change param order on vec::init_fn (and vec::init_fn_mut), putting block in final position.
1 parent 818b646 commit 35d12be

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

Diff for: src/comp/middle/typeck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
142142
tpt: ty_param_bounds_and_ty, sp: span)
143143
-> ty_param_substs_opt_and_ty {
144144
let ty_param_count = vec::len(*tpt.bounds);
145-
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, ty_param_count);
145+
let vars = vec::init_fn(ty_param_count, {|_i| next_ty_var(fcx)});
146146
let ty_substs_len = vec::len(pth.node.types);
147147
if ty_substs_len > 0u {
148148
let param_var_len = vec::len(vars);
@@ -611,9 +611,9 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
611611
} else {
612612
let impl_fty = ty::mk_fn(tcx, impl_m.fty);
613613
// Add dummy substs for the parameters of the impl method
614-
let substs = substs + vec::init_fn({|i|
614+
let substs = substs + vec::init_fn(vec::len(*if_m.tps), {|i|
615615
ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0})
616-
}, vec::len(*if_m.tps));
616+
});
617617
let if_fty = ty::substitute_type_params(tcx, substs,
618618
ty::mk_fn(tcx, if_m.fty));
619619
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 {
23342334

23352335
fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint)
23362336
-> {vars: [ty::t], ty: ty::t} {
2337-
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, count);
2337+
let vars = vec::init_fn(count, {|_i| next_ty_var(fcx)});
23382338
{vars: vars, ty: ty::substitute_type_params(fcx.ccx.tcx, vars, tp)}
23392339
}
23402340

Diff for: src/libcore/vec.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Creates and initializes an immutable vector.
8888
Creates an immutable vector of size `n_elts` and initializes the elements
8989
to the value returned by the function `op`.
9090
*/
91-
fn init_fn<T>(op: init_op<T>, n_elts: uint) -> [T] {
91+
fn init_fn<T>(n_elts: uint, op: init_op<T>) -> [T] {
9292
let v = [];
9393
reserve(v, n_elts);
9494
let i: uint = 0u;
@@ -105,7 +105,7 @@ Creates and initializes a mutable vector.
105105
Creates a mutable vector of size `n_elts` and initializes the elements to
106106
the value returned by the function `op`.
107107
*/
108-
fn init_fn_mut<T>(op: init_op<T>, n_elts: uint) -> [mutable T] {
108+
fn init_fn_mut<T>(n_elts: uint, op: init_op<T>) -> [mutable T] {
109109
let v = [mutable];
110110
reserve(v, n_elts);
111111
let i: uint = 0u;
@@ -365,13 +365,13 @@ Function: grow_fn
365365
Expands a vector in place, initializing the new elements to the result of a
366366
function
367367
368-
Function `init_fn` is called `n` times with the values [0..`n`)
368+
Function `init_op` is called `n` times with the values [0..`n`)
369369
370370
Parameters:
371371
372372
v - The vector to grow
373373
n - The number of elements to add
374-
init_fn - A function to call to retreive each appended element's value
374+
init_op - A function to call to retreive each appended element's value
375375
*/
376376
fn grow_fn<T>(&v: [T], n: uint, op: init_op<T>) {
377377
reserve(v, next_power_of_two(len(v) + n));
@@ -1026,14 +1026,14 @@ mod tests {
10261026
#[test]
10271027
fn test_init_fn() {
10281028
// Test on-stack init_fn.
1029-
let v = init_fn(square, 3u);
1029+
let v = init_fn(3u, square);
10301030
assert (len(v) == 3u);
10311031
assert (v[0] == 0u);
10321032
assert (v[1] == 1u);
10331033
assert (v[2] == 4u);
10341034

10351035
// Test on-heap init_fn.
1036-
v = init_fn(square, 5u);
1036+
v = init_fn(5u, square);
10371037
assert (len(v) == 5u);
10381038
assert (v[0] == 0u);
10391039
assert (v[1] == 1u);

Diff for: src/libstd/bitv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ in the resulting vector has either value 0u or 1u.
267267
*/
268268
fn to_vec(v: t) -> [uint] {
269269
let sub = bind init_to_vec(v, _);
270-
ret vec::init_fn::<uint>(sub, v.nbits);
270+
ret vec::init_fn::<uint>(v.nbits, sub);
271271
}
272272

273273
/*

Diff for: src/libstd/getopts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ err(fail_) - On failure. Use <fail_str> to get an error message.
212212
fn getopts(args: [str], opts: [opt]) -> result {
213213
let n_opts = vec::len::<opt>(opts);
214214
fn f(_x: uint) -> [optval] { ret []; }
215-
let vals = vec::init_fn_mut::<[optval]>(f, n_opts);
215+
let vals = vec::init_fn_mut::<[optval]>(n_opts, f);
216216
let free: [str] = [];
217217
let l = vec::len(args);
218218
let i = 0u;

Diff for: src/test/bench/shootout-fannkuchredux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn fannkuch(n: int) -> int {
77
fn perm1init(i: uint) -> int { ret i as int; }
88

99
let perm = vec::init_elt_mut(0, n as uint);
10-
let perm1 = vec::init_fn_mut(perm1init, n as uint);
10+
let perm1 = vec::init_fn_mut(n as uint, perm1init);
1111
let count = vec::init_elt_mut(0, n as uint);
1212
let f = 0;
1313
let i = 0;

Diff for: src/test/bench/sudoku.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum grid_t { grid_ctor(grid), }
3131
fn read_grid(f: io::reader) -> grid_t {
3232
assert f.read_line() == "9,9"; /* assert first line is exactly "9,9" */
3333

34-
let g = vec::init_fn({|_i| vec::init_elt_mut(0 as u8, 10u) }, 10u);
34+
let g = vec::init_fn(10u, {|_i| vec::init_elt_mut(0 as u8, 10u) });
3535
while !f.eof() {
3636
// FIXME: replace with unicode compliant call
3737
let comps = str::split(str::trim(f.read_line()), ',' as u8);
@@ -130,7 +130,7 @@ fn write_grid(f: io::writer, g: grid_t) {
130130
fn main(args: [str]) {
131131
let grid = if vec::len(args) == 1u {
132132
// FIXME create sudoku inline since nested vec consts dont work yet
133-
let g = vec::init_fn({|_i| vec::init_elt_mut(0 as u8, 10u) }, 10u);
133+
let g = vec::init_fn(10u, {|_i| vec::init_elt_mut(0 as u8, 10u) });
134134
g[0][1] = 4u8;
135135
g[0][3] = 6u8;
136136
g[0][7] = 3u8;

0 commit comments

Comments
 (0)