rust/src/test/run-pass/block-arg-in-parentheses.rs

22 lines
490 B
Rust
Raw Normal View History

fn w_semi(v: [int]) -> int {
vec::foldl(0, v) {|x,y| x+y};
-10
}
fn wo_paren(v: [int]) -> int {
// Perhaps surprising: this is parsed equivalently to w_semi()
vec::foldl(0, v) {|x,y| x+y} - 10
}
2011-12-29 11:49:33 -06:00
fn w_paren(v: [int]) -> int {
// Here the parentheses force interpretation as an expression:
(vec::foldl(0, v) {|x,y| x+y}) - 10
}
2011-12-29 11:49:33 -06:00
fn main() {
assert wo_paren([0, 1, 2, 3]) == -10;
assert w_semi([0, 1, 2, 3]) == -10;
assert w_paren([0, 1, 2, 3]) == -4;
2011-12-29 11:49:33 -06:00
}