test: Remove non-procedure uses of do from compiletest, libstd tests,
compile-fail tests, run-fail tests, and run-pass tests.
This commit is contained in:
parent
8ceb374ab7
commit
f571e46ddb
128 changed files with 579 additions and 641 deletions
|
|
@ -15,7 +15,7 @@ condition! {
|
|||
}
|
||||
|
||||
pub fn guard(k: extern fn() -> int, x: int) -> int {
|
||||
do oops::cond.trap(|i| i*x).inside {
|
||||
oops::cond.trap(|i| i*x).inside(|| {
|
||||
k()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ use extra::arc;
|
|||
fn main() {
|
||||
let x = ~arc::RWArc::new(1);
|
||||
let mut y = None;
|
||||
do x.write_cond |_one, cond| {
|
||||
y = Some(cond);
|
||||
}
|
||||
x.write_cond(|_one, cond| y = Some(cond));
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ use extra::arc;
|
|||
fn main() {
|
||||
let x = ~arc::RWArc::new(1);
|
||||
let mut y = None;
|
||||
do x.write_downgrade |write_mode| {
|
||||
x.write_downgrade(|write_mode| {
|
||||
y = Some(x.downgrade(write_mode));
|
||||
//~^ ERROR cannot infer an appropriate lifetime
|
||||
}
|
||||
});
|
||||
y.unwrap();
|
||||
// Adding this line causes a method unification failure instead
|
||||
// do (&option::unwrap(y)).read |state| { assert!(*state == 1); }
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ use extra::arc;
|
|||
fn main() {
|
||||
let x = ~arc::RWArc::new(1);
|
||||
let mut y = None; //~ ERROR lifetime of variable does not enclose its declaration
|
||||
do x.write |one| {
|
||||
y = Some(one);
|
||||
}
|
||||
x.write(|one| y = Some(one));
|
||||
*y.unwrap() = 2;
|
||||
//~^ ERROR lifetime of return value does not outlive the function call
|
||||
//~^^ ERROR dereference of reference outside its lifetime
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ use extra::arc;
|
|||
fn main() {
|
||||
let x = ~arc::RWArc::new(1);
|
||||
let mut y = None;
|
||||
do x.write_downgrade |write_mode| {
|
||||
do (&write_mode).write_cond |_one, cond| {
|
||||
x.write_downgrade(|write_mode| {
|
||||
(&write_mode).write_cond(|_one, cond| {
|
||||
y = Some(cond);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ use extra::arc;
|
|||
fn main() {
|
||||
let x = ~arc::RWArc::new(1);
|
||||
let mut y = None;
|
||||
do x.write_downgrade |write_mode| {
|
||||
y = Some(write_mode);
|
||||
}
|
||||
x.write_downgrade(|write_mode| y = Some(write_mode));
|
||||
y.unwrap();
|
||||
// Adding this line causes a method unification failure instead
|
||||
// do (&option::unwrap(y)).write |state| { assert!(*state == 1); }
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn compute1() -> f64 {
|
||||
let v = ~[0f64, 1.0, 2.0, 3.0];
|
||||
|
||||
do v.iter().fold(0.0) |x, y| { x + *y } - 10.0
|
||||
//~^ ERROR mismatched types: expected `()`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = compute1();
|
||||
info!("{:?}", x);
|
||||
assert_eq!(x, -4f64);
|
||||
}
|
||||
|
|
@ -32,9 +32,9 @@ fn b() {
|
|||
|
||||
let mut p = ~[1];
|
||||
|
||||
do borrow(p) {
|
||||
borrow(p, || {
|
||||
p[0] = 5; //~ ERROR cannot assign to
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn c() {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl X {
|
|||
|
||||
fn main() {
|
||||
let mut x = X(Right(main));
|
||||
do (&mut x).with |opt| {
|
||||
(&mut x).with(|opt| {
|
||||
match opt {
|
||||
&Right(ref f) => {
|
||||
x = X(Left((0,0))); //~ ERROR cannot assign to `x`
|
||||
|
|
@ -26,5 +26,5 @@ fn main() {
|
|||
},
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ impl Foo {
|
|||
}
|
||||
|
||||
fn bar(f: &mut Foo) {
|
||||
do f.foo |a| {
|
||||
f.foo(|a| {
|
||||
f.n.insert(*a); //~ ERROR cannot borrow
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ fn block_overarching_alias_mut() {
|
|||
|
||||
let mut v = ~3;
|
||||
let mut x = &mut v;
|
||||
do 3.times {
|
||||
3.times(|| {
|
||||
borrow(v); //~ ERROR cannot borrow
|
||||
}
|
||||
});
|
||||
*x = ~5;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ fn borrow(v: &int, f: |x: &int|) {
|
|||
|
||||
fn box_imm() {
|
||||
let mut v = ~3;
|
||||
do borrow(v) |w| {
|
||||
borrow(v, |w| {
|
||||
v = ~4; //~ ERROR cannot assign to `v` because it is borrowed
|
||||
assert_eq!(*v, 3);
|
||||
assert_eq!(*w, 4);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ fn a() {
|
|||
p.impurem();
|
||||
|
||||
// But in this case we do not honor the loan:
|
||||
do p.blockm {
|
||||
p.blockm(|| {
|
||||
p.x = 10; //~ ERROR cannot assign
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn b() {
|
||||
|
|
@ -52,9 +52,9 @@ fn c() {
|
|||
q.impurem();
|
||||
|
||||
// ...but we still detect errors statically when we can.
|
||||
do q.blockm {
|
||||
q.blockm(|| {
|
||||
q.x = 10; //~ ERROR cannot assign
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -18,15 +18,14 @@ fn takes_imm_elt(_v: &int, f: ||) {
|
|||
|
||||
fn has_mut_vec_and_does_not_try_to_change_it() {
|
||||
let mut v = ~[1, 2, 3];
|
||||
do takes_imm_elt(&v[0]) {
|
||||
}
|
||||
takes_imm_elt(&v[0], || {})
|
||||
}
|
||||
|
||||
fn has_mut_vec_but_tries_to_change_it() {
|
||||
let mut v = ~[1, 2, 3];
|
||||
do takes_imm_elt(&v[0]) {
|
||||
takes_imm_elt(&v[0], || {
|
||||
v[1] = 4; //~ ERROR cannot assign
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ fn main() {
|
|||
while cond() {
|
||||
if cond() { break }
|
||||
if cond() { continue }
|
||||
do foo {
|
||||
foo(|| {
|
||||
if cond() { break } //~ ERROR: `break` inside of a closure
|
||||
if cond() { continue } //~ ERROR: `continue` inside of a closure
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let rs: Foo = Foo{t: pth};
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ fn bar(blk: ||:'static) {
|
|||
}
|
||||
|
||||
fn foo(x: &()) {
|
||||
do bar {
|
||||
bar(|| {
|
||||
let _ = x; //~ ERROR does not fulfill `'static`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f(f: |int| -> bool) -> bool { f(10i) }
|
||||
fn f(f: proc(int) -> bool) -> bool { f(10i) }
|
||||
|
||||
fn main() {
|
||||
assert!(do f() |i| { i == 10i } == 10i);
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ fn main() {
|
|||
let mut a = ~[];
|
||||
a.push(3);
|
||||
let mut a = ~[];
|
||||
do callback {
|
||||
callback(|| {
|
||||
a.push(3);
|
||||
}
|
||||
});
|
||||
let (mut a, b) = (1, 2);
|
||||
a = 34;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ unsafe fn unsf() {}
|
|||
fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
||||
fn bad2() { unsafe { bad1() } } //~ ERROR: unnecessary `unsafe` block
|
||||
unsafe fn bad3() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
||||
fn bad4() { unsafe { do callback {} } } //~ ERROR: unnecessary `unsafe` block
|
||||
fn bad4() { unsafe { callback(||{}) } } //~ ERROR: unnecessary `unsafe` block
|
||||
unsafe fn bad5() { unsafe { unsf() } } //~ ERROR: unnecessary `unsafe` block
|
||||
fn bad6() {
|
||||
unsafe { // don't put the warning here
|
||||
|
|
@ -50,9 +50,9 @@ fn good2() {
|
|||
unsafe {
|
||||
unsafe fn what() -> ~[~str] { fail!() }
|
||||
|
||||
do callback {
|
||||
callback(|| {
|
||||
what();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ fn f(s: &S, g: |&S|) {
|
|||
fn main() {
|
||||
let s = S { x: ~Bar(~42) };
|
||||
loop {
|
||||
do f(&s) |hellothere| {
|
||||
f(&s, |hellothere| {
|
||||
match hellothere.x {
|
||||
~Foo(_) => {}
|
||||
~Bar(x) => println(x.to_str()), //~ ERROR cannot move out
|
||||
~Baz => {}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct R<'self> {
|
|||
|
||||
fn innocent_looking_victim() {
|
||||
let mut x = Some(~"hello");
|
||||
do conspirator |f, writer| {
|
||||
conspirator(|f, writer| {
|
||||
if writer {
|
||||
x = None;
|
||||
} else {
|
||||
|
|
@ -33,7 +33,7 @@ fn innocent_looking_victim() {
|
|||
None => fail!("oops"),
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn conspirator(f: |&R, bool|) {
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ fn test_mutex_arc_nested() {
|
|||
let arc2 = ~MutexArc::new(*arc);
|
||||
|
||||
do task::spawn || {
|
||||
do (*arc2).access |mutex| { //~ ERROR instantiating a type parameter with an incompatible type
|
||||
}
|
||||
(*arc2).access(|mutex| { //~ ERROR instantiating a type parameter with an incompatible type
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ fn foo(blk: once ||) {
|
|||
|
||||
fn main() {
|
||||
let x = arc::Arc::new(true);
|
||||
do foo {
|
||||
foo(|| {
|
||||
assert!(*x.get());
|
||||
util::ignore(x);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ fn foo(blk: ||) {
|
|||
|
||||
fn main() {
|
||||
let x = arc::Arc::new(true);
|
||||
do foo {
|
||||
foo(|| {
|
||||
assert!(*x.get());
|
||||
util::ignore(x); //~ ERROR cannot move out of captured outer variable
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ fn wants_static_fn(_x: 'static ||) {}
|
|||
|
||||
fn main() {
|
||||
let i = 3;
|
||||
do wants_static_fn { //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
|
||||
wants_static_fn(|| { //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
|
||||
info!("i={}", i);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ fn with<T>(f: |x: &int| -> T) -> T {
|
|||
}
|
||||
|
||||
fn manip<'a>(x: &'a int) -> int {
|
||||
let z = do with |y| { select(x, y) };
|
||||
let z = with(|y| { select(x, y) });
|
||||
//~^ ERROR cannot infer an appropriate lifetime
|
||||
*z
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ use extra::sync;
|
|||
fn main() {
|
||||
let m = ~sync::Mutex::new();
|
||||
let mut cond = None;
|
||||
do m.lock_cond |c| {
|
||||
m.lock_cond(|c| {
|
||||
cond = Some(c);
|
||||
}
|
||||
});
|
||||
cond.unwrap().signal();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ use extra::sync;
|
|||
fn main() {
|
||||
let x = ~sync::RWLock::new();
|
||||
let mut y = None;
|
||||
do x.write_cond |cond| {
|
||||
x.write_cond(|cond| {
|
||||
y = Some(cond);
|
||||
}
|
||||
});
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ use extra::sync;
|
|||
fn main() {
|
||||
let x = ~sync::RWLock::new();
|
||||
let mut y = None;
|
||||
do x.write_downgrade |write_mode| {
|
||||
x.write_downgrade(|write_mode| {
|
||||
y = Some(x.downgrade(write_mode));
|
||||
}
|
||||
})
|
||||
// Adding this line causes a method unification failure instead
|
||||
// do (&option::unwrap(y)).read { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ use extra::sync;
|
|||
fn main() {
|
||||
let x = ~sync::RWLock::new();
|
||||
let mut y = None;
|
||||
do x.write_downgrade |write_mode| {
|
||||
do (&write_mode).write_cond |cond| {
|
||||
x.write_downgrade(|write_mode| {
|
||||
(&write_mode).write_cond(|cond| {
|
||||
y = Some(cond);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ use extra::sync;
|
|||
fn main() {
|
||||
let x = ~sync::RWLock::new();
|
||||
let mut y = None;
|
||||
do x.write_downgrade |write_mode| {
|
||||
x.write_downgrade(|write_mode| {
|
||||
y = Some(write_mode);
|
||||
}
|
||||
});
|
||||
// Adding this line causes a method unification failure instead
|
||||
// do (&option::unwrap(y)).write { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn main() {
|
|||
// huge).
|
||||
|
||||
let x = ~[1u,2u,3u];
|
||||
do x.as_imm_buf |p, _len| {
|
||||
x.as_imm_buf(|p, _len| {
|
||||
let base = p as uint;
|
||||
let idx = base / mem::size_of::<uint>();
|
||||
error!("ov1 base = 0x{:x}", base);
|
||||
|
|
@ -32,5 +32,5 @@ fn main() {
|
|||
|
||||
// This should fail.
|
||||
error!("ov1 0x{:x}", x[idx]);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,14 +30,17 @@ impl<A> iterable<A> for ~[A] {
|
|||
|
||||
fn length<A, T: iterable<A>>(x: T) -> uint {
|
||||
let mut len = 0;
|
||||
do x.iterate() |_y| { len += 1; true };
|
||||
x.iterate(|_y| {
|
||||
len += 1;
|
||||
true
|
||||
});
|
||||
return len;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let x = ~[0,1,2,3];
|
||||
// Call a method
|
||||
do x.iterate() |y| { assert!(x[*y] == *y); true };
|
||||
x.iterate(|y| { assert!(x[*y] == *y); true });
|
||||
// Call a parameterized function
|
||||
assert_eq!(length(x.clone()), x.len());
|
||||
// Call a parameterized function, with type arguments that require
|
||||
|
|
@ -47,7 +50,7 @@ pub fn main() {
|
|||
// Now try it with a type that *needs* to be borrowed
|
||||
let z = [0,1,2,3];
|
||||
// Call a method
|
||||
do z.iterate() |y| { assert!(z[*y] == *y); true };
|
||||
z.iterate(|y| { assert!(z[*y] == *y); true });
|
||||
// Call a parameterized function
|
||||
assert_eq!(length::<int, &[int]>(z), z.len());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,5 +20,5 @@ fn bitv_test() {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
do 10000.times || {bitv_test()};
|
||||
10000.times(|| bitv_test());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
|
||||
|
||||
// Trailing expressions don't require parentheses:
|
||||
let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
|
||||
|
||||
assert_eq!(y, 15.0);
|
||||
fn add(x: proc(f64) -> f64) -> f64 {
|
||||
x(10.0)
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
// Trailing expressions don't require parentheses:
|
||||
let y = do add |x| { x + 10.0 } + 10.0;
|
||||
|
||||
assert_eq!(y, 30.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
fn f(i: || -> uint) -> uint { i() }
|
||||
let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
|
||||
let z = do do v.iter().fold(f) |x, _y| { x } { 22u };
|
||||
assert_eq!(z, 22u);
|
||||
fn f(_: proc()) -> proc(proc() -> uint) {
|
||||
proc(_: proc() -> uint) {}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
do do f {} { 20 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f(_: proc()) -> proc(uint) -> uint {
|
||||
proc(x: uint) { x }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
fn f(i: uint) -> uint { i }
|
||||
let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
|
||||
let z = do v.iter().fold(f) |x, _y| { x } (22u);
|
||||
let z = do f {} (22u);
|
||||
assert_eq!(z, 22u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,28 +8,31 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn w_semi(v: ~[int]) -> int {
|
||||
fn f(_: proc(int, int) -> int) -> int {
|
||||
10
|
||||
}
|
||||
|
||||
fn w_semi() {
|
||||
// the semicolon causes compiler not to
|
||||
// complain about the ignored return value:
|
||||
do v.iter().fold(0) |x,y| { x+*y };
|
||||
-10
|
||||
do f |x, y| { x+y };
|
||||
}
|
||||
|
||||
fn w_paren1(v: ~[int]) -> int {
|
||||
(do v.iter().fold(0) |x,y| { x+*y }) - 10
|
||||
fn w_paren1() -> int {
|
||||
(do f |x, y| { x+y }) - 10
|
||||
}
|
||||
|
||||
fn w_paren2(v: ~[int]) -> int {
|
||||
(do v.iter().fold(0) |x,y| { x+*y} - 10)
|
||||
fn w_paren2() -> int {
|
||||
(do f |x, y| { x+y } - 10)
|
||||
}
|
||||
|
||||
fn w_ret(v: ~[int]) -> int {
|
||||
return do v.iter().fold(0) |x,y| { x+*y } - 10;
|
||||
fn w_ret() -> int {
|
||||
return do f |x, y| { x+y } - 10;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(w_semi(~[0, 1, 2, 3]), -10);
|
||||
assert_eq!(w_paren1(~[0, 1, 2, 3]), -4);
|
||||
assert_eq!(w_paren2(~[0, 1, 2, 3]), -4);
|
||||
assert_eq!(w_ret(~[0, 1, 2, 3]), -4);
|
||||
w_semi();
|
||||
w_paren1();
|
||||
w_paren2();
|
||||
w_ret();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn call_any(f: || -> uint) -> uint {
|
||||
fn call_any(f: proc() -> uint) -> uint {
|
||||
return f();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn inty(fun: proc(int) -> int) -> int {
|
||||
fun(100)
|
||||
}
|
||||
|
||||
fn booly(fun: proc(bool) -> bool) -> bool {
|
||||
fun(true)
|
||||
}
|
||||
|
||||
// Check usage and precedence of block arguments in expressions:
|
||||
pub fn main() {
|
||||
let v = ~[-1.0f64, 0.0, 1.0, 2.0, 3.0];
|
||||
|
|
@ -18,28 +26,27 @@ pub fn main() {
|
|||
}
|
||||
|
||||
// Usable at all:
|
||||
let mut any_negative = do v.iter().any |e| { e.is_negative() };
|
||||
assert!(any_negative);
|
||||
do inty |x| { x };
|
||||
|
||||
// Higher precedence than assignments:
|
||||
any_negative = do v.iter().any |e| { e.is_negative() };
|
||||
assert!(any_negative);
|
||||
let result = do inty |e| { e };
|
||||
assert_eq!(result, 100);
|
||||
|
||||
// Higher precedence than unary operations:
|
||||
let abs_v = do v.iter().map |e| { e.abs() }.collect::<~[f64]>();
|
||||
assert!(do abs_v.iter().all |e| { e.is_positive() });
|
||||
assert!(!do abs_v.iter().any |e| { e.is_negative() });
|
||||
let stringy = do inty |e| { e }.to_str();
|
||||
assert!(do booly |_| { true });
|
||||
assert!(!do booly |_| { false });
|
||||
|
||||
// Usable in funny statement-like forms:
|
||||
if !do v.iter().any |e| { e.is_positive() } {
|
||||
if !do booly |_| { true } {
|
||||
assert!(false);
|
||||
}
|
||||
match do v.iter().all |e| { e.is_negative() } {
|
||||
match do booly |_| { false } {
|
||||
true => { fail!("incorrect answer."); }
|
||||
false => { }
|
||||
}
|
||||
match 3 {
|
||||
_ if do v.iter().any |e| { e.is_negative() } => {
|
||||
_ if do booly |_| { true } => {
|
||||
}
|
||||
_ => {
|
||||
fail!("wrong answer.");
|
||||
|
|
@ -48,15 +55,19 @@ pub fn main() {
|
|||
|
||||
|
||||
// Lower precedence than binary operations:
|
||||
let w = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
|
||||
let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
|
||||
let z = 10.0 + do v.iter().fold(0.0) |x, y| { x + *y };
|
||||
let w = do inty |_| { 10 } + 10;
|
||||
let y = do inty |_| { 10 } + 10;
|
||||
let z = 10 + do inty |_| { 10 };
|
||||
assert_eq!(w, y);
|
||||
assert_eq!(y, z);
|
||||
|
||||
// In the tail of a block
|
||||
let w =
|
||||
if true { do abs_v.iter().any |e| { e.is_positive() } }
|
||||
else { false };
|
||||
let w = if true {
|
||||
do booly |_| {
|
||||
true
|
||||
}
|
||||
} else {
|
||||
false
|
||||
};
|
||||
assert!(w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ fn borrow(x: &int, f: |x: &int|) {
|
|||
}
|
||||
|
||||
fn test1(x: @~int) {
|
||||
do borrow(&*(*x).clone()) |p| {
|
||||
borrow(&*(*x).clone(), |p| {
|
||||
let x_a = ptr::to_unsafe_ptr(&**x);
|
||||
assert!((x_a as uint) != borrow::to_uint(p));
|
||||
assert_eq!(unsafe{*x_a}, *p);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ pub fn main() {
|
|||
add_int(ints, 22);
|
||||
add_int(ints, 44);
|
||||
|
||||
do iter_ints(ints) |i| {
|
||||
iter_ints(ints, |i| {
|
||||
error!("int = {}", *i);
|
||||
true
|
||||
};
|
||||
});
|
||||
|
||||
error!("ints={:?}", ints);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ struct F { f: ~int }
|
|||
|
||||
pub fn main() {
|
||||
let mut x = @F {f: ~3};
|
||||
do borrow(x.f) |b_x| {
|
||||
borrow(x.f, |b_x| {
|
||||
assert_eq!(*b_x, 3);
|
||||
assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
|
||||
x = @F {f: ~4};
|
||||
|
|
@ -32,5 +32,5 @@ pub fn main() {
|
|||
ptr::to_unsafe_ptr(&(*b_x)) as uint);
|
||||
assert_eq!(*b_x, 3);
|
||||
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ struct F { f: ~int }
|
|||
|
||||
pub fn main() {
|
||||
let mut x = ~@F{f: ~3};
|
||||
do borrow(x.f) |b_x| {
|
||||
borrow(x.f, |b_x| {
|
||||
assert_eq!(*b_x, 3);
|
||||
assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
|
||||
*x = @F{f: ~4};
|
||||
|
|
@ -32,5 +32,5 @@ pub fn main() {
|
|||
ptr::to_unsafe_ptr(&(*b_x)) as uint);
|
||||
assert_eq!(*b_x, 3);
|
||||
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn borrow(x: &int, f: |x: &int|) {
|
|||
|
||||
pub fn main() {
|
||||
let mut x = @3;
|
||||
do borrow(x) |b_x| {
|
||||
borrow(x, |b_x| {
|
||||
assert_eq!(*b_x, 3);
|
||||
assert_eq!(ptr::to_unsafe_ptr(&(*x)), ptr::to_unsafe_ptr(&(*b_x)));
|
||||
x = @22;
|
||||
|
|
@ -30,5 +30,5 @@ pub fn main() {
|
|||
ptr::to_unsafe_ptr(&(*b_x)) as uint);
|
||||
assert_eq!(*b_x, 3);
|
||||
assert!(ptr::to_unsafe_ptr(&(*x)) != ptr::to_unsafe_ptr(&(*b_x)));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ struct F { f: ~int }
|
|||
|
||||
pub fn main() {
|
||||
let mut x = @F {f: ~3};
|
||||
do borrow((*x).f) |b_x| {
|
||||
borrow((*x).f, |b_x| {
|
||||
assert_eq!(*b_x, 3);
|
||||
assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
|
||||
x = @F {f: ~4};
|
||||
|
|
@ -32,5 +32,5 @@ pub fn main() {
|
|||
ptr::to_unsafe_ptr(&(*b_x)) as uint);
|
||||
assert_eq!(*b_x, 3);
|
||||
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ pub fn main() {
|
|||
//let bt0 = sys::frame_address();
|
||||
//info!("%?", bt0);
|
||||
|
||||
do 3u.to(10u) |i| {
|
||||
3u.to(10u, |i| {
|
||||
println!("{}", i);
|
||||
|
||||
//let bt1 = sys::frame_address();
|
||||
//info!("%?", bt1);
|
||||
//assert!(bt0 == bt1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ extern mod cci_iter_lib;
|
|||
pub fn main() {
|
||||
//let bt0 = sys::rusti::frame_address(1u32);
|
||||
//info!("%?", bt0);
|
||||
do cci_iter_lib::iter([1, 2, 3]) |i| {
|
||||
cci_iter_lib::iter([1, 2, 3], |i| {
|
||||
println!("{}", *i);
|
||||
//assert!(bt0 == sys::rusti::frame_address(2u32));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ pub fn main() {
|
|||
// actually working.
|
||||
//let bt0 = sys::frame_address();
|
||||
//info!("%?", bt0);
|
||||
do iter(~[1u, 2u, 3u]) |i| {
|
||||
iter(~[1u, 2u, 3u], |i| {
|
||||
println!("{}", i);
|
||||
|
||||
//let bt1 = sys::frame_address();
|
||||
//info!("%?", bt1);
|
||||
|
||||
//assert!(bt0 != bt1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ fn test_destroy_twice() {
|
|||
|
||||
let mut p = run::Process::new(PROG, [], run::ProcessOptions::new());
|
||||
p.destroy(); // this shouldnt crash...
|
||||
do io::io_error::cond.trap(|_| {}).inside {
|
||||
io::io_error::cond.trap(|_| {}).inside(|| {
|
||||
p.destroy(); // ...and nor should this (and nor should the destructor)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn test_destroy_actually_kills(force: bool) {
|
||||
|
|
|
|||
|
|
@ -71,9 +71,9 @@ pub fn main() {
|
|||
roundtrip::<C>();
|
||||
roundtrip::<D>();
|
||||
|
||||
do 20.times {
|
||||
20.times(|| {
|
||||
roundtrip::<E>();
|
||||
roundtrip::<F>();
|
||||
roundtrip::<G<int>>();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,10 @@ enum D {
|
|||
|
||||
fn main() {
|
||||
// check there's no segfaults
|
||||
do 20.times {
|
||||
20.times(|| {
|
||||
rand::random::<A>();
|
||||
rand::random::<B>();
|
||||
rand::random::<C>();
|
||||
rand::random::<D>();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// no-reformat
|
||||
// Testing various forms of `do` with empty arg lists
|
||||
|
||||
fn f(_f: || -> bool) -> bool {
|
||||
fn f(_f: proc() -> bool) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
// Testing that we can drop the || in do exprs
|
||||
|
||||
fn f(_f: || -> bool) -> bool { true }
|
||||
fn f(_f: proc() -> bool) -> bool { true }
|
||||
|
||||
fn d(_f: ||) { }
|
||||
fn d(_f: proc()) { }
|
||||
|
||||
pub fn main() {
|
||||
do d { }
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f(_f: ||) {
|
||||
}
|
||||
|
||||
fn g() {
|
||||
// `f || { }` is considered pure, so `do f { }` should be too
|
||||
do f { }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f(f: |int|) { f(10) }
|
||||
|
||||
pub fn main() {
|
||||
do f() |i| { assert!(i == 10) }
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f(f: |int|) { f(10) }
|
||||
fn f(f: proc(int)) { f(10) }
|
||||
|
||||
pub fn main() {
|
||||
do f() |i| { assert!(i == 10) }
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f(f: |int| -> int) -> int { f(10) }
|
||||
fn f(f: proc(int) -> int) -> int { f(10) }
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(do f() |i| { i }, 10);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f(f: |int| -> int) -> int { f(10) }
|
||||
fn f(f: proc(int) -> int) -> int { f(10) }
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(do f |i| { i }, 10);
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ fn count(n: uint) -> uint {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
do 100u.times {
|
||||
100u.times(|| {
|
||||
do task::spawn {
|
||||
assert_eq!(count(5u), 16u);
|
||||
};
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ fn count(n: uint) -> uint {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
do 10u.times {
|
||||
10u.times(|| {
|
||||
do task::spawn {
|
||||
let result = count(5u);
|
||||
info!("result = {}", result);
|
||||
assert_eq!(result, 16u);
|
||||
};
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ fn two(it: |int|) { it(0); it(1); }
|
|||
pub fn main() {
|
||||
let mut a: ~[int] = ~[-1, -1, -1, -1];
|
||||
let mut p: int = 0;
|
||||
do two |i| {
|
||||
do two |j| { a[p] = 10 * i + j; p += 1; }
|
||||
}
|
||||
two(|i| {
|
||||
two(|j| { a[p] = 10 * i + j; p += 1; })
|
||||
});
|
||||
assert_eq!(a[0], 0);
|
||||
assert_eq!(a[1], 1);
|
||||
assert_eq!(a[2], 10);
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ fn pairs(it: |(int, int)|) {
|
|||
pub fn main() {
|
||||
let mut i: int = 10;
|
||||
let mut j: int = 0;
|
||||
do pairs() |p| {
|
||||
pairs(|p| {
|
||||
let (_0, _1) = p;
|
||||
info!("{}", _0);
|
||||
info!("{}", _1);
|
||||
assert_eq!(_0 + 10, i);
|
||||
i += 1;
|
||||
j = _1;
|
||||
};
|
||||
});
|
||||
assert_eq!(j, 45);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
pub fn main() {
|
||||
let mut sum: int = 0;
|
||||
do first_ten |i| { info!("main"); info!("{}", i); sum = sum + i; }
|
||||
first_ten(|i| { info!("main"); info!("{}", i); sum = sum + i; });
|
||||
info!("sum");
|
||||
info!("{}", sum);
|
||||
assert_eq!(sum, 45);
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ mod libc {
|
|||
|
||||
fn strlen(str: ~str) -> uint {
|
||||
// C string is terminated with a zero
|
||||
do str.with_c_str |buf| {
|
||||
str.with_c_str(|buf| {
|
||||
unsafe {
|
||||
libc::my_strlen(buf) as uint
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn plus_one(f: || -> int) -> int {
|
||||
return f() + 1;
|
||||
}
|
||||
|
||||
fn ret_plus_one() -> extern fn(|| -> int) -> int {
|
||||
return plus_one;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let z = do (ret_plus_one()) || { 2 };
|
||||
assert_eq!(z, 3);
|
||||
}
|
||||
|
|
@ -19,9 +19,7 @@ impl Drop for socket {
|
|||
|
||||
impl socket {
|
||||
pub fn set_identity(&self) {
|
||||
do closure {
|
||||
setsockopt_bytes(self.sock.clone())
|
||||
}
|
||||
closure(|| setsockopt_bytes(self.sock.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, extra::jso
|
|||
{
|
||||
&extra::json::List(ref interfaces) =>
|
||||
{
|
||||
do interfaces.map |interface| {
|
||||
interfaces.map(|interface| {
|
||||
add_interface(store, managed_ip.clone(), (*interface).clone())
|
||||
}
|
||||
})
|
||||
}
|
||||
_ =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
pub fn main() {
|
||||
let mut x = 0;
|
||||
do 4096.times {
|
||||
x += 1;
|
||||
}
|
||||
4096.times(|| x += 1);
|
||||
assert_eq!(x, 4096);
|
||||
println!("x = {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,11 +64,9 @@ impl Drop for AsciiArt {
|
|||
fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt {
|
||||
// Use an anonymous function to build a vector of vectors containing
|
||||
// blank characters for each position in our canvas.
|
||||
let lines = do vec::build(Some(height)) |push| {
|
||||
do height.times {
|
||||
push(vec::from_elem(width, '.'));
|
||||
}
|
||||
};
|
||||
let lines = vec::build(Some(height), |push| {
|
||||
height.times(|| push(vec::from_elem(width, '.')))
|
||||
});
|
||||
|
||||
// Rust code often returns values by omitting the trailing semi-colon
|
||||
// instead of using an explicit return statement.
|
||||
|
|
@ -101,7 +99,7 @@ impl AsciiArt {
|
|||
impl ToStr for AsciiArt {
|
||||
fn to_str(&self) -> ~str {
|
||||
// Convert each line into a string.
|
||||
let lines = do self.lines.map |line| {str::from_chars(*line)};
|
||||
let lines = self.lines.map(|line| str::from_chars(*line));
|
||||
|
||||
// Concatenate the lines together using a new-line.
|
||||
lines.connect("\n")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
pub fn main() {
|
||||
let mut count = 0;
|
||||
do 999_999.times() {
|
||||
count += 1;
|
||||
}
|
||||
999_999.times(|| count += 1);
|
||||
assert_eq!(count, 999_999);
|
||||
println!("{}", count);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ trait Fooable {
|
|||
|
||||
impl Fooable for uint {
|
||||
fn yes(self) {
|
||||
do self.times {
|
||||
println("yes");
|
||||
}
|
||||
self.times(|| println("yes"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@ fn swap(f: |~[int]| -> ~[int]) -> ~[int] {
|
|||
|
||||
pub fn main() {
|
||||
let v = swap(|mut x| { x.push(4); x });
|
||||
let w = do swap |mut x| { x.push(4); x };
|
||||
let w = swap(|mut x| { x.push(4); x });
|
||||
assert_eq!(v, w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub fn main() {
|
|||
let x = Some(unstable::sync::Exclusive::new(true));
|
||||
match x {
|
||||
Some(ref z) if z.with(|b| *b) => {
|
||||
do z.with |b| { assert!(*b); }
|
||||
z.with(|b| assert!(*b));
|
||||
},
|
||||
_ => fail!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ fn g(_g: ||) { }
|
|||
pub fn main() {
|
||||
assert_eq!(f(10, |a| a), 10);
|
||||
g(||());
|
||||
assert_eq!(do f(10) |a| { a }, 10);
|
||||
do g() { }
|
||||
assert_eq!(f(10, |a| a), 10);
|
||||
g(||{});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ fn foo(blk: once ||) {
|
|||
|
||||
fn main() {
|
||||
let x = arc::Arc::new(true);
|
||||
do foo {
|
||||
foo(|| {
|
||||
assert!(*x.get());
|
||||
util::ignore(x);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,16 +37,12 @@ impl<V:TyVisitor + movable_ptr> ptr_visit_adaptor<V> {
|
|||
|
||||
#[inline(always)]
|
||||
pub fn bump(&mut self, sz: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
((p as uint) + sz) as *c_void
|
||||
};
|
||||
self.inner.move_ptr(|p| ((p as uint) + sz) as *c_void)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn align(&mut self, a: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
align(p as uint, a) as *c_void
|
||||
};
|
||||
self.inner.move_ptr(|p| align(p as uint, a) as *c_void)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -501,15 +497,11 @@ impl TyVisitor for my_visitor {
|
|||
fn visit_bot(&mut self) -> bool { true }
|
||||
fn visit_nil(&mut self) -> bool { true }
|
||||
fn visit_bool(&mut self) -> bool {
|
||||
do self.get::<bool>() |b| {
|
||||
self.vals.push(b.to_str());
|
||||
};
|
||||
self.get::<bool>(|b| self.vals.push(b.to_str()));
|
||||
true
|
||||
}
|
||||
fn visit_int(&mut self) -> bool {
|
||||
do self.get::<int>() |i| {
|
||||
self.vals.push(i.to_str());
|
||||
};
|
||||
self.get::<int>(|i| self.vals.push(i.to_str()));
|
||||
true
|
||||
}
|
||||
fn visit_i8(&mut self) -> bool { true }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ fn with<T>(f: |x: &int| -> T) -> T {
|
|||
}
|
||||
|
||||
fn has_one<'a>(x: &'a int) -> int {
|
||||
do with |y| { takes_two(x, y) }
|
||||
with(|y| takes_two(x, y))
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -31,20 +31,20 @@ fn rename_directory() {
|
|||
let test_file = &old_path.join("temp.txt");
|
||||
|
||||
/* Write the temp input file */
|
||||
let ostream = do test_file.with_c_str |fromp| {
|
||||
do "w+b".with_c_str |modebuf| {
|
||||
let ostream = test_file.with_c_str(|fromp| {
|
||||
"w+b".with_c_str(|modebuf| {
|
||||
libc::fopen(fromp, modebuf)
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
assert!((ostream as uint != 0u));
|
||||
let s = ~"hello";
|
||||
do "hello".with_c_str |buf| {
|
||||
"hello".with_c_str(|buf| {
|
||||
let write_len = libc::fwrite(buf as *libc::c_void,
|
||||
1u as libc::size_t,
|
||||
(s.len() + 1u) as libc::size_t,
|
||||
ostream);
|
||||
assert_eq!(write_len, (s.len() + 1) as libc::size_t)
|
||||
}
|
||||
});
|
||||
assert_eq!(libc::fclose(ostream), (0u as libc::c_int));
|
||||
|
||||
let new_path = tmpdir.join_many(["quux", "blat"]);
|
||||
|
|
|
|||
|
|
@ -93,9 +93,9 @@ fn check_legs(arc: arc::Arc<~[~Pet:Freeze+Send]>) {
|
|||
}
|
||||
fn check_names(arc: arc::Arc<~[~Pet:Freeze+Send]>) {
|
||||
for pet in arc.get().iter() {
|
||||
do pet.name |name| {
|
||||
pet.name(|name| {
|
||||
assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
fn check_pedigree(arc: arc::Arc<~[~Pet:Freeze+Send]>) {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ fn range_(lo: uint, hi: uint, it: |uint|) {
|
|||
}
|
||||
|
||||
fn create_index<T>(_index: ~[S<T>], _hash_fn: extern fn(T) -> uint) {
|
||||
do range_(0u, 256u) |_i| {
|
||||
range_(0u, 256u, |_i| {
|
||||
let _bucket: ~[T] = ~[];
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn main() { }
|
||||
|
|
|
|||
|
|
@ -26,16 +26,16 @@ pub fn main() {
|
|||
|
||||
unsafe {
|
||||
// Call with just the named parameter
|
||||
do "Hello World\n".with_c_str |c| {
|
||||
"Hello World\n".with_c_str(|c| {
|
||||
check("Hello World\n", |s| sprintf(s, c));
|
||||
}
|
||||
});
|
||||
|
||||
// Call with variable number of arguments
|
||||
do "%d %f %c %s\n".with_c_str |c| {
|
||||
do check("42 42.500000 a %d %f %c %s\n\n") |s| {
|
||||
"%d %f %c %s\n".with_c_str(|c| {
|
||||
check("42 42.500000 a %d %f %c %s\n\n", |s| {
|
||||
sprintf(s, c, 42i, 42.5f64, 'a' as c_int, c);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Make a function pointer
|
||||
let x: extern "C" unsafe fn(*mut c_char, *c_char, ...) -> c_int = sprintf;
|
||||
|
|
@ -43,16 +43,16 @@ pub fn main() {
|
|||
// A function that takes a function pointer
|
||||
unsafe fn call(p: extern "C" unsafe fn(*mut c_char, *c_char, ...) -> c_int) {
|
||||
// Call with just the named parameter via fn pointer
|
||||
do "Hello World\n".with_c_str |c| {
|
||||
"Hello World\n".with_c_str(|c| {
|
||||
check("Hello World\n", |s| p(s, c));
|
||||
}
|
||||
});
|
||||
|
||||
// Call with variable number of arguments
|
||||
do "%d %f %c %s\n".with_c_str |c| {
|
||||
do check("42 42.500000 a %d %f %c %s\n\n") |s| {
|
||||
"%d %f %c %s\n".with_c_str(|c| {
|
||||
check("42 42.500000 a %d %f %c %s\n\n", |s| {
|
||||
p(s, c, 42i, 42.5f64, 'a' as c_int, c);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Pass sprintf directly
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub fn main() {
|
|||
let x = Some(unstable::sync::Exclusive::new(true));
|
||||
match x {
|
||||
Some(ref z) if z.with(|b| *b) => {
|
||||
do z.with |b| { assert!(*b); }
|
||||
z.with(|b| assert!(*b));
|
||||
},
|
||||
_ => fail!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ use xc_conditions::trouble;
|
|||
// there's no cross-crate-ness to test in that case.
|
||||
|
||||
pub fn main() {
|
||||
do oops::cond.trap(|_i| 12345).inside {
|
||||
oops::cond.trap(|_i| 12345).inside(|| {
|
||||
let x = trouble();
|
||||
assert_eq!(x,12345);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,5 @@ extern mod xc_conditions_2;
|
|||
use xcc = xc_conditions_2;
|
||||
|
||||
pub fn main() {
|
||||
do xcc::oops::cond.trap(|_| 1).inside {
|
||||
xcc::oops::cond.raise(1);
|
||||
}
|
||||
xcc::oops::cond.trap(|_| 1).inside(|| xcc::oops::cond.raise(1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ impl xcc::Thunk<xcc::Color> for SThunk {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
do xcc::oops::cond.trap(|_| xcc::Red).inside {
|
||||
xcc::oops::cond.trap(|_| xcc::Red).inside(|| {
|
||||
let t = SThunk { x : 10 };
|
||||
assert_eq!(xcc::callback(t), xcc::Red)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ pub fn main() {
|
|||
|
||||
// Previously this fail'd because there were two addresses that were being
|
||||
// used when declaring constants.
|
||||
do other::test::cond.trap(|_| {
|
||||
}).inside {
|
||||
other::test::cond.trap(|_| {
|
||||
}).inside(|| {
|
||||
other::raise();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue