Skip to content

Commit

Permalink
Add pass-by-ref annotation to the tests to make them typecheck
Browse files Browse the repository at this point in the history
Issue #1008
  • Loading branch information
marijnh committed Oct 7, 2011
1 parent fe916fb commit 41528dc
Show file tree
Hide file tree
Showing 24 changed files with 49 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/test/compile-fail/fn-compare-mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// error-pattern:expected fn() but found fn(int)
// error-pattern:expected fn() but found fn(+int)

fn main() {
fn f() { }
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/lambda-mutate-nested.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// error-pattern:assigning to upvar
// Make sure that nesting a block within a lambda doesn't let us
// mutate upvars from a lambda.
fn f2(x: block()) { x(); }

fn main() {
let i = 0;
let ctr = lambda () -> int { block () { i = i + 1; }(); ret i; };
let ctr = lambda () -> int { f2({|| i = i + 1; }); ret i; };
log_err ctr();
log_err ctr();
log_err ctr();
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-alt-generic-box2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_generic<@T>(expected: T, eq: compare<T>) {
}

fn test_vec() {
fn compare_box(v1: @int, v2: @int) -> bool { ret v1 == v2; }
fn compare_box(&&v1: @int, &&v2: @int) -> bool { ret v1 == v2; }
let eq = bind compare_box(_, _);
test_generic::<@int>(@1, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-alt-generic-unique2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_generic<@T>(expected: T, eq: compare<T>) {
}

fn test_vec() {
fn compare_box(v1: ~int, v2: ~int) -> bool { ret v1 == v2; }
fn compare_box(&&v1: ~int, &&v2: ~int) -> bool { ret v1 == v2; }
let eq = bind compare_box(_, _);
test_generic::<~int>(~1, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-alt-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_generic<@T>(expected: T, eq: compare<T>) {
}

fn test_bool() {
fn compare_bool(b1: bool, b2: bool) -> bool { ret b1 == b2; }
fn compare_bool(&&b1: bool, &&b2: bool) -> bool { ret b1 == b2; }
let eq = bind compare_bool(_, _);
test_generic::<bool>(true, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-block-generic-box2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_generic<@T>(expected: T, eq: compare<T>) {
}

fn test_vec() {
fn compare_vec(v1: @int, v2: @int) -> bool { ret v1 == v2; }
fn compare_vec(&&v1: @int, &&v2: @int) -> bool { ret v1 == v2; }
let eq = bind compare_vec(_, _);
test_generic::<@int>(@1, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-block-generic-unique2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_generic<@T>(expected: T, eq: compare<T>) {
}

fn test_vec() {
fn compare_vec(v1: ~int, v2: ~int) -> bool { ret v1 == v2; }
fn compare_vec(&&v1: ~int, &&v2: ~int) -> bool { ret v1 == v2; }
let eq = bind compare_vec(_, _);
test_generic::<~int>(~1, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-block-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn test_generic<@T>(expected: T, eq: compare<T>) {
}

fn test_bool() {
fn compare_bool(b1: bool, b2: bool) -> bool { ret b1 == b2; }
fn compare_bool(&&b1: bool, &&b2: bool) -> bool { ret b1 == b2; }
let eq = bind compare_bool(_, _);
test_generic::<bool>(true, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-if-generic-box2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_generic<@T>(expected: T, not_expected: T, eq: compare<T>) {
}

fn test_vec() {
fn compare_box(v1: @int, v2: @int) -> bool { ret v1 == v2; }
fn compare_box(&&v1: @int, &&v2: @int) -> bool { ret v1 == v2; }
let eq = bind compare_box(_, _);
test_generic::<@int>(@1, @2, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/expr-if-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn test_generic<@T>(expected: T, not_expected: T, eq: compare<T>) {
}

fn test_bool() {
fn compare_bool(b1: bool, b2: bool) -> bool { ret b1 == b2; }
fn compare_bool(&&b1: bool, &&b2: bool) -> bool { ret b1 == b2; }
let eq = bind compare_bool(_, _);
test_generic::<bool>(true, false, eq);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/fixed-point-bind-box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn fix<A, @B>(f: fn(fn(A) -> B, A) -> B) -> fn(A) -> B {
ret bind fix_help(f, _);
}

fn fact_(f: fn(int) -> int, n: int) -> int {
fn fact_(f: fn(&&int) -> int, &&n: int) -> int {
// fun fact 0 = 1
ret if n == 0 { 1 } else { n * f(n - 1) };
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/fixed-point-bind-unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn fix<A, ~B>(f: fn(fn(A) -> B, A) -> B) -> fn(A) -> B {
ret bind fix_help(f, _);
}

fn fact_(f: fn(int) -> int, n: int) -> int {
fn fact_(f: fn(&&int) -> int, &&n: int) -> int {
// fun fact 0 = 1
ret if n == 0 { 1 } else { n * f(n - 1) };
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/generic-temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

fn mk() -> int { ret 1; }

fn chk(a: int) { log a; assert (a == 1); }
fn chk(&&a: int) { log a; assert (a == 1); }

fn apply<T>(produce: fn() -> T, consume: fn(T)) { consume(produce()); }

fn main() {
let produce: fn() -> int = mk;
let consume: fn(int) = chk;
let consume: fn(&&int) = chk;
apply::<int>(produce, consume);
}
2 changes: 1 addition & 1 deletion src/test/run-pass/resource-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource finish<T>(arg: {val: T, fin: fn(T)}) { arg.fin(arg.val); }

fn main() {
let box = @mutable 10;
fn dec_box(i: @mutable int) { *i -= 1; }
fn dec_box(&&i: @mutable int) { *i -= 1; }

{ let i <- finish({val: box, fin: dec_box}); }
assert (*box == 9);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/unchecked-predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn pure_foldl<@T, @U>(ls: list<T>, u: U, f: block(T, U) -> U) -> U {
// Shows how to use an "unchecked" block to call a general
// fn from a pure fn
pure fn pure_length<@T>(ls: list<T>) -> uint {
fn count<T>(_t: T, u: uint) -> uint { u + 1u }
fn count<T>(_t: T, &&u: uint) -> uint { u + 1u }
unchecked{ pure_foldl(ls, 0u, count) }
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/stdtest/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ type reccy = {x: int, y: int, t: taggy};

#[test]
fn test() {
fn inteq(a: int, b: int) -> bool { ret a == b; }
fn intboxeq(a: @int, b: @int) -> bool { ret a == b; }
fn inteq(&&a: int, &&b: int) -> bool { ret a == b; }
fn intboxeq(&&a: @int, &&b: @int) -> bool { ret a == b; }
fn taggyeq(a: taggy, b: taggy) -> bool {
alt a {
one(a1) { alt b { one(b1) { ret a1 == b1; } _ { ret false; } } }
Expand Down
8 changes: 4 additions & 4 deletions src/test/stdtest/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import std::vec::len;
#[test]
fn test_either_left() {
let val = left(10);
fn f_left(x: int) -> bool { x == 10 }
fn f_right(_x: uint) -> bool { false }
fn f_left(&&x: int) -> bool { x == 10 }
fn f_right(&&_x: uint) -> bool { false }
assert (either(f_left, f_right, val));
}

#[test]
fn test_either_right() {
let val = right(10u);
fn f_left(_x: int) -> bool { false }
fn f_right(x: uint) -> bool { x == 10u }
fn f_left(&&_x: int) -> bool { false }
fn f_right(&&x: uint) -> bool { x == 10u }
assert (either(f_left, f_right, val));
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/stdtest/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ fn test_from_vec() {
#[test]
fn test_foldl() {
let l = from_vec([0, 1, 2, 3, 4]);
fn add(a: int, b: uint) -> uint { ret (a as uint) + b; }
fn add(&&a: int, &&b: uint) -> uint { ret (a as uint) + b; }
let rs = list::foldl(l, 0u, add);
assert (rs == 10u);
}

#[test]
fn test_find_success() {
let l = from_vec([0, 1, 2]);
fn match(i: int) -> option::t<int> {
fn match(&&i: int) -> option::t<int> {
ret if i == 2 { option::some(i) } else { option::none::<int> };
}
let rs = list::find(l, match);
Expand All @@ -35,7 +35,7 @@ fn test_find_success() {
#[test]
fn test_find_fail() {
let l = from_vec([0, 1, 2]);
fn match(_i: int) -> option::t<int> { ret option::none::<int>; }
fn match(&&_i: int) -> option::t<int> { ret option::none::<int>; }
let rs = list::find(l, match);
assert (rs == option::none::<int>);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/stdtest/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import std::option;
#[test]
fn test_simple() {
log "*** starting test_simple";
fn eq_uint(x: uint, y: uint) -> bool { ret x == y; }
fn eq_uint(&&x: uint, &&y: uint) -> bool { ret x == y; }
let hasher_uint: map::hashfn<uint> = util::id;
let eqer_uint: map::eqfn<uint> = eq_uint;
let hasher_str: map::hashfn<str> = str::hash;
Expand Down Expand Up @@ -83,7 +83,7 @@ fn test_simple() {
fn test_growth() {
log "*** starting test_growth";
let num_to_insert: uint = 64u;
fn eq_uint(x: uint, y: uint) -> bool { ret x == y; }
fn eq_uint(&&x: uint, &&y: uint) -> bool { ret x == y; }
log "uint -> uint";
let hasher_uint: map::hashfn<uint> = util::id;
let eqer_uint: map::eqfn<uint> = eq_uint;
Expand Down Expand Up @@ -157,8 +157,8 @@ fn test_growth() {
fn test_removal() {
log "*** starting test_removal";
let num_to_insert: uint = 64u;
fn eq(x: uint, y: uint) -> bool { ret x == y; }
fn hash(u: uint) -> uint {
fn eq(&&x: uint, &&y: uint) -> bool { ret x == y; }
fn hash(&&u: uint) -> uint {
// This hash function intentionally causes collisions between
// consecutive integer pairs.

Expand Down
4 changes: 2 additions & 2 deletions src/test/stdtest/qsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import std::int;

fn check_sort(v1: [mutable int], v2: [mutable int]) {
let len = std::vec::len::<int>(v1);
fn ltequal(a: int, b: int) -> bool { ret a <= b; }
fn ltequal(&&a: int, &&b: int) -> bool { ret a <= b; }
let f = ltequal;
std::sort::quick_sort::<int>(f, v1);
let i = 0u;
Expand Down Expand Up @@ -46,7 +46,7 @@ fn test_simple() {

let expected = [1, 2, 3];

fn lteq(a: int, b: int) -> bool { int::le(a, b) }
fn lteq(&&a: int, &&b: int) -> bool { int::le(a, b) }
sort::quick_sort(lteq, names);

let immut_names = vec::from_mut(names);
Expand Down
4 changes: 2 additions & 2 deletions src/test/stdtest/qsort3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std;

fn check_sort(v1: [mutable int], v2: [mutable int]) {
let len = std::vec::len::<int>(v1);
fn lt(a: int, b: int) -> bool { ret a < b; }
fn equal(a: int, b: int) -> bool { ret a == b; }
fn lt(&&a: int, &&b: int) -> bool { ret a < b; }
fn equal(&&a: int, &&b: int) -> bool { ret a == b; }
let f1 = lt;
let f2 = equal;
std::sort::quick_sort3::<int>(f1, f2, v1);
Expand Down
2 changes: 1 addition & 1 deletion src/test/stdtest/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std;

fn check_sort(v1: [int], v2: [int]) {
let len = std::vec::len::<int>(v1);
fn lteq(a: int, b: int) -> bool { ret a <= b; }
fn lteq(&&a: int, &&b: int) -> bool { ret a <= b; }
let f = lteq;
let v3 = std::sort::merge_sort::<int>(f, v1);
let i = 0u;
Expand Down
2 changes: 1 addition & 1 deletion src/test/stdtest/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn traverse_in_order() {
insert(m, 1, ());

let n = 0;
fn t(&n: int, k: int, _v: ()) { assert (n == k); n += 1; }
fn t(&n: int, &&k: int, &&_v: ()) { assert (n == k); n += 1; }
traverse(m, bind t(n, _, _));
}

Expand Down
24 changes: 12 additions & 12 deletions src/test/stdtest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import std::option::some;

fn square(n: uint) -> uint { ret n * n; }

fn square_alias(n: uint) -> uint { ret n * n; }
fn square_ref(&&n: uint) -> uint { ret n * n; }

pure fn is_three(n: uint) -> bool { ret n == 3u; }
pure fn is_three(&&n: uint) -> bool { ret n == 3u; }

pure fn is_odd(n: uint) -> bool { ret n % 2u == 1u; }
pure fn is_odd(&&n: uint) -> bool { ret n % 2u == 1u; }

fn square_if_odd(n: uint) -> option::t<uint> {
fn square_if_odd(&&n: uint) -> option::t<uint> {
ret if n % 2u == 1u { some(n * n) } else { none };
}

fn add(x: uint, y: uint) -> uint { ret x + y; }
fn add(&&x: uint, &&y: uint) -> uint { ret x + y; }

#[test]
fn test_unsafe_ptrs() {
Expand Down Expand Up @@ -211,15 +211,15 @@ fn test_grow_set() {
fn test_map() {
// Test on-stack map.
let v = [1u, 2u, 3u];
let w = vec::map(square_alias, v);
let w = vec::map(square_ref, v);
assert (vec::len(w) == 3u);
assert (w[0] == 1u);
assert (w[1] == 4u);
assert (w[2] == 9u);

// Test on-heap map.
v = [1u, 2u, 3u, 4u, 5u];
w = vec::map(square_alias, v);
w = vec::map(square_ref, v);
assert (vec::len(w) == 5u);
assert (w[0] == 1u);
assert (w[1] == 4u);
Expand All @@ -230,7 +230,7 @@ fn test_map() {

#[test]
fn test_map2() {
fn times(x: int, y: int) -> int { ret x * y; }
fn times(&&x: int, &&y: int) -> int { ret x * y; }
let f = times;
let v0 = [1, 2, 3, 4, 5];
let v1 = [5, 4, 3, 2, 1];
Expand All @@ -256,12 +256,12 @@ fn test_filter_map() {
assert (w[1] == 9u);
assert (w[2] == 25u);

fn halve(i: int) -> option::t<int> {
fn halve(&&i: int) -> option::t<int> {
if i % 2 == 0 {
ret option::some::<int>(i / 2);
} else { ret option::none::<int>; }
}
fn halve_for_sure(i: int) -> int { ret i / 2; }
fn halve_for_sure(&&i: int) -> int { ret i / 2; }
let all_even: [int] = [0, 2, 8, 6];
let all_odd1: [int] = [1, 7, 3];
let all_odd2: [int] = [];
Expand Down Expand Up @@ -335,8 +335,8 @@ fn test_position() {

#[test]
fn test_position_pred() {
fn less_than_three(i: int) -> bool { ret i < 3; }
fn is_eighteen(i: int) -> bool { ret i == 18; }
fn less_than_three(&&i: int) -> bool { ret i < 3; }
fn is_eighteen(&&i: int) -> bool { ret i == 18; }
let v1: [int] = [5, 4, 3, 2, 1];
assert (position_pred(less_than_three, v1) == option::some::<uint>(3u));
assert (position_pred(is_eighteen, v1) == option::none::<uint>);
Expand Down

0 comments on commit 41528dc

Please sign in to comment.