compile-fail tests, run-fail tests, and run-pass tests.
let file = file.clone();
debug!("inspecting file {}", file.display());
if is_test(config, &file) {
- let t = do make_test(config, &file) {
+ let t = make_test(config, &file, || {
match config.mode {
mode_codegen => make_metrics_test_closure(config, &file),
_ => make_test_closure(config, &file)
}
- };
+ });
tests.push(t)
}
}
let mut pp_exact = None;
let mut debugger_cmds = ~[];
let mut check_lines = ~[];
- do iter_header(testfile) |ln| {
+ iter_header(testfile, |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
None => ()
};
true
- };
+ });
return TestProps {
error_patterns: error_patterns,
compile_flags: compile_flags,
~"xfail-" + util::get_os(config.target)
}
- let val = do iter_header(testfile) |ln| {
+ let val = iter_header(testfile, |ln| {
if parse_name_directive(ln, "xfail-test") { false }
else if parse_name_directive(ln, xfail_target(config)) { false }
else if config.mode == common::mode_pretty &&
parse_name_directive(ln, "xfail-pretty") { false }
else { true }
- };
+ });
!val
}
}
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
- do parse_name_value_directive(line, ~"exec-env").map |nv| {
+ parse_name_value_directive(line, ~"exec-env").map(|nv| {
// nv is either FOO or FOO=BAR
let mut strs: ~[~str] = nv.splitn('=', 1).map(|s| s.to_owned()).collect();
}
n => fail!("Expected 1 or 2 strings, not {}", n)
}
- }
+ })
}
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
assert!(prog.ends_with(".exe"));
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";
- env = do env.map() |pair| {
+ env = env.map(|pair| {
let (k,v) = (*pair).clone();
if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) }
else { (k,v) }
- };
+ });
if prog.ends_with("rustc.exe") {
env.push((~"RUST_THREADS", ~"1"));
}
testfile: &Path,
ProcRes: &ProcRes) {
if props.error_patterns.is_empty() {
- do testfile.display().with_str |s| {
+ testfile.display().with_str(|s| {
fatal(~"no error pattern specified in " + s);
- }
+ })
}
if ProcRes.status.success() {
#[bench]
fn bench_capacity(b: &mut bh) {
let x = @[1, 2, 3];
- b.iter(|| capacity(x));
+ b.iter(|| {
+ let _ = capacity(x);
+ });
}
#[bench]
fn bench_build_sized(b: &mut bh) {
let len = 64;
- do b.iter {
+ b.iter(|| {
build(Some(len), |push| for i in range(0, 1024) { push(i) });
- }
+ });
}
#[bench]
fn bench_build(b: &mut bh) {
- do b.iter {
+ b.iter(|| {
for i in range(0, 95) {
build(None, |push| push(i));
}
- }
+ });
}
#[bench]
fn bench_append(b: &mut bh) {
let lhs = @[7, ..128];
let rhs = range(0, 256).to_owned_vec();
- b.iter(|| append(lhs, rhs))
+ b.iter(|| {
+ let _ = append(lhs, rhs);
+ })
}
#[bench]
fn bench_map(b: &mut bh) {
let elts = range(0, 256).to_owned_vec();
- b.iter(|| map(elts, |x| x*2))
+ b.iter(|| {
+ let _ = map(elts, |x| x*2);
+ })
}
#[bench]
fn bench_from_fn(b: &mut bh) {
- b.iter(|| from_fn(1024, |x| x));
+ b.iter(|| {
+ let _ = from_fn(1024, |x| x);
+ });
}
#[bench]
fn bench_from_elem(b: &mut bh) {
- b.iter(|| from_elem(1024, 0u64));
+ b.iter(|| {
+ let _ = from_elem(1024, 0u64);
+ });
}
#[bench]
#[bench]
fn bench_to_managed(b: &mut bh) {
let elts = range(0, 1024).to_owned_vec();
- b.iter(|| to_managed(elts));
+ b.iter(|| {
+ let _ = to_managed(elts);
+ });
}
#[bench]
fn bench_clone(b: &mut bh) {
let elts = to_managed(range(0, 1024).to_owned_vec());
- b.iter(|| elts.clone());
+ b.iter(|| {
+ let _ = elts.clone();
+ });
}
}
/// # Examples
///
/// ```
-/// do std::bool::all_values |x: bool| {
+/// std::bool::all_values(|x: bool| {
/// println(x.to_str());
-/// }
+/// })
/// ```
#[inline]
pub fn all_values(blk: |v: bool|) {
#[test]
fn test_bool_from_str() {
- do all_values |v| {
+ all_values(|v| {
assert!(Some(v) == FromStr::from_str(v.to_str()))
- }
+ });
}
#[test]
#[test]
fn test_bool_to_bit() {
- do all_values |v| {
+ all_values(|v| {
assert_eq!(v.to_bit::<u8>(), if v { 1u8 } else { 0u8 });
assert_eq!(v.to_bit::<uint>(), if v { 1u } else { 0u });
assert_eq!(v.to_bit::<int>(), if v { 1i } else { 0i });
- }
+ });
}
#[test]
priv nc: NonCopyable
}
-<<<<<<< HEAD
// Values [1, MAX-1] represent the number of `Ref` active
// (will not outgrow its range since `uint` is the size of the address space)
type BorrowFlag = uint;
fn test_escape_default() {
fn string(c: char) -> ~str {
let mut result = ~"";
- do escape_default(c) |c| { result.push_char(c); }
+ escape_default(c, |c| { result.push_char(c); });
return result;
}
assert_eq!(string('\n'), ~"\\n");
fn test_escape_unicode() {
fn string(c: char) -> ~str {
let mut result = ~"";
- do escape_unicode(c) |c| { result.push_char(c); }
+ escape_unicode(c, |c| { result.push_char(c); });
return result;
}
assert_eq!(string('\x00'), ~"\\x00");
fn nested_trap_test_inner() {
let mut inner_trapped = false;
- do sadness::cond.trap(|_j| {
+ sadness::cond.trap(|_j| {
debug!("nested_trap_test_inner: in handler");
inner_trapped = true;
0
- }).inside {
+ }).inside(|| {
debug!("nested_trap_test_inner: in protected block");
trouble(1);
- }
+ });
assert!(inner_trapped);
}
fn nested_trap_test_outer() {
let mut outer_trapped = false;
- do sadness::cond.trap(|_j| {
+ sadness::cond.trap(|_j| {
debug!("nested_trap_test_outer: in handler");
outer_trapped = true; 0
- }).inside {
+ }).inside(|| {
debug!("nested_guard_test_outer: in protected block");
nested_trap_test_inner();
trouble(1);
- }
+ });
assert!(outer_trapped);
}
fn nested_reraise_trap_test_inner() {
let mut inner_trapped = false;
- do sadness::cond.trap(|_j| {
+ sadness::cond.trap(|_j| {
debug!("nested_reraise_trap_test_inner: in handler");
inner_trapped = true;
let i = 10;
debug!("nested_reraise_trap_test_inner: handler re-raising");
sadness::cond.raise(i)
- }).inside {
+ }).inside(|| {
debug!("nested_reraise_trap_test_inner: in protected block");
trouble(1);
- }
+ });
assert!(inner_trapped);
}
fn nested_reraise_trap_test_outer() {
let mut outer_trapped = false;
- do sadness::cond.trap(|_j| {
+ sadness::cond.trap(|_j| {
debug!("nested_reraise_trap_test_outer: in handler");
outer_trapped = true; 0
- }).inside {
+ }).inside(|| {
debug!("nested_reraise_trap_test_outer: in protected block");
nested_reraise_trap_test_inner();
- }
+ });
assert!(outer_trapped);
}
fn test_default() {
let mut trapped = false;
- do sadness::cond.trap(|j| {
+ sadness::cond.trap(|j| {
debug!("test_default: in handler");
sadness::cond.raise_default(j, || { trapped=true; 5 })
- }).inside {
+ }).inside(|| {
debug!("test_default: in protected block");
trouble(1);
- }
+ });
assert!(trapped);
}
#[test]
fn test_conditions_are_public() {
let mut trapped = false;
- do sadness::cond.trap(|_| {
+ sadness::cond.trap(|_| {
trapped = true;
0
- }).inside {
+ }).inside(|| {
sadness::cond.raise(0);
- }
+ });
assert!(trapped);
}
}
#[bench]
fn bench_buffered_reader(bh: &mut Harness) {
- do bh.iter {
+ bh.iter(|| {
BufferedReader::new(NullStream);
- }
+ });
}
#[bench]
fn bench_buffered_writer(bh: &mut Harness) {
- do bh.iter {
+ bh.iter(|| {
BufferedWriter::new(NullStream);
- }
+ });
}
#[bench]
fn bench_buffered_stream(bh: &mut Harness) {
- do bh.iter {
+ bh.iter(|| {
BufferedStream::new(NullStream);
- }
+ });
}
}
#[test]
fn read_byte_error() {
let mut reader = ErroringReader;
- do io_error::cond.trap(|_| {
- }).inside {
+ io_error::cond.trap(|_| {
+ }).inside(|| {
let byte = reader.read_byte();
assert!(byte == None);
- }
+ });
}
#[test]
fn bytes_error() {
let reader = ErroringReader;
let mut it = reader.bytes();
- do io_error::cond.trap(|_| ()).inside {
+ io_error::cond.trap(|_| ()).inside(|| {
let byte = it.next();
assert!(byte == None);
- }
+ })
}
#[test]
#[test]
fn read_bytes_eof() {
let mut reader = MemReader::new(~[10, 11]);
- do io_error::cond.trap(|_| {
- }).inside {
+ io_error::cond.trap(|_| {
+ }).inside(|| {
assert!(reader.read_bytes(4) == ~[10, 11]);
- }
+ })
}
#[test]
fn push_bytes_eof() {
let mut reader = MemReader::new(~[10, 11]);
let mut buf = ~[8, 9];
- do io_error::cond.trap(|_| {
- }).inside {
+ io_error::cond.trap(|_| {
+ }).inside(|| {
reader.push_bytes(&mut buf, 4);
assert!(buf == ~[8, 9, 10, 11]);
- }
+ })
}
#[test]
count: 0,
};
let mut buf = ~[8, 9];
- do io_error::cond.trap(|_| { } ).inside {
+ io_error::cond.trap(|_| { } ).inside(|| {
reader.push_bytes(&mut buf, 4);
- }
+ });
assert!(buf == ~[8, 9, 10]);
}
count: 0,
};
let buf = @mut ~[8, 9];
- do (|| {
+ (|| {
reader.push_bytes(&mut *buf, 4);
- }).finally {
+ }).finally(|| {
// NB: Using rtassert here to trigger abort on failure since this is a should_fail test
// FIXME: #7049 This fails because buf is still borrowed
//rtassert!(*buf == ~[8, 9, 10]);
- }
+ })
}
#[test]
writer.write([0]);
let mut called = false;
- do io_error::cond.trap(|err| {
+ io_error::cond.trap(|err| {
assert_eq!(err.kind, OtherIoError);
called = true;
- }).inside {
+ }).inside(|| {
writer.write([0, 0]);
- }
+ });
assert!(called);
}
fn bind_error() {
do run_in_mt_newsched_task {
let mut called = false;
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
assert!(e.kind == PermissionDenied);
called = true;
- }).inside {
+ }).inside(|| {
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };
let listener = TcpListener::bind(addr);
assert!(listener.is_none());
- }
+ });
assert!(called);
}
}
fn connect_error() {
do run_in_mt_newsched_task {
let mut called = false;
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
let expected_error = if cfg!(unix) {
ConnectionRefused
} else {
};
assert_eq!(e.kind, expected_error);
called = true;
- }).inside {
+ }).inside(|| {
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };
let stream = TcpStream::connect(addr);
assert!(stream.is_none());
- }
+ });
assert!(called);
}
}
let mut buf = [0];
let nread = stream.read(buf);
assert!(nread.is_none());
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
if cfg!(windows) {
assert_eq!(e.kind, NotConnected);
} else {
fail!();
}
- }).inside {
+ }).inside(|| {
let nread = stream.read(buf);
assert!(nread.is_none());
- }
+ })
}
do spawntask {
let mut buf = [0];
let nread = stream.read(buf);
assert!(nread.is_none());
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
if cfg!(windows) {
assert_eq!(e.kind, NotConnected);
} else {
fail!();
}
- }).inside {
+ }).inside(|| {
let nread = stream.read(buf);
assert!(nread.is_none());
- }
+ })
}
do spawntask {
let buf = [0];
loop {
let mut stop = false;
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
// NB: ECONNRESET on linux, EPIPE on mac, ECONNABORTED
// on windows
assert!(e.kind == ConnectionReset ||
e.kind == ConnectionAborted,
"unknown error: {:?}", e);
stop = true;
- }).inside {
+ }).inside(|| {
stream.write(buf);
- }
+ });
if stop { break }
}
}
let buf = [0];
loop {
let mut stop = false;
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
// NB: ECONNRESET on linux, EPIPE on mac, ECONNABORTED
// on windows
assert!(e.kind == ConnectionReset ||
e.kind == ConnectionAborted,
"unknown error: {:?}", e);
stop = true;
- }).inside {
+ }).inside(|| {
stream.write(buf);
- }
+ });
if stop { break }
}
}
do spawntask {
port.take().recv();
- do max.times {
+ max.times(|| {
let mut stream = TcpStream::connect(addr);
stream.write([99]);
- }
+ });
}
}
}
do spawntask {
port.take().recv();
- do max.times {
+ max.times(|| {
let mut stream = TcpStream::connect(addr);
stream.write([99]);
- }
+ });
}
}
}
fn bind_error() {
do run_in_mt_newsched_task {
let mut called = false;
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
assert!(e.kind == PermissionDenied);
called = true;
- }).inside {
+ }).inside(|| {
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };
let socket = UdpSocket::bind(addr);
assert!(socket.is_none());
- }
+ });
assert!(called);
}
}
fn bind_error() {
do run_in_mt_newsched_task {
let mut called = false;
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
assert!(e.kind == PermissionDenied);
called = true;
- }).inside {
+ }).inside(|| {
let listener = UnixListener::bind(&("path/to/nowhere"));
assert!(listener.is_none());
- }
+ });
assert!(called);
}
}
fn connect_error() {
do run_in_mt_newsched_task {
let mut called = false;
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
assert_eq!(e.kind, OtherIoError);
called = true;
- }).inside {
+ }).inside(|| {
let stream = UnixStream::connect(&("path/to/nowhere"));
assert!(stream.is_none());
- }
+ });
assert!(called);
}
}
let buf = [0];
let mut stop = false;
while !stop{
- do io_error::cond.trap(|e| {
+ io_error::cond.trap(|e| {
assert!(e.kind == BrokenPipe || e.kind == NotConnected,
"unknown error {:?}", e);
stop = true;
- }).inside {
+ }).inside(|| {
server.write(buf);
- }
+ })
}
}, |_client| {
// drop the client
do spawntask {
let mut acceptor = UnixListener::bind(&path1).listen();
chan.take().send(());
- do times.times {
+ times.times(|| {
let mut client = acceptor.accept();
let mut buf = [0];
client.read(buf);
assert_eq!(buf[0], 100);
- }
+ })
}
do spawntask {
port.take().recv();
- do times.times {
+ times.times(|| {
let mut stream = UnixStream::connect(&path2);
stream.write([100]);
- }
+ })
}
}
}
let mut writer: Option<MemWriter> = None;
let mut called = false;
- do io_error::cond.trap(|err| {
+ io_error::cond.trap(|err| {
assert_eq!(err.kind, PreviousIoError);
called = true;
- }).inside {
+ }).inside(|| {
writer.write([0, 0, 0]);
- }
+ });
assert!(called);
let mut called = false;
- do io_error::cond.trap(|err| {
+ io_error::cond.trap(|err| {
assert_eq!(err.kind, PreviousIoError);
called = true;
- }).inside {
+ }).inside(|| {
writer.flush();
- }
+ });
assert!(called);
}
}
let mut buf = [];
let mut called = false;
- do io_error::cond.trap(|err| {
+ io_error::cond.trap(|err| {
assert_eq!(err.kind, PreviousIoError);
called = true;
- }).inside {
+ }).inside(|| {
reader.read(buf);
- }
+ });
assert!(called);
let mut called = false;
- do io_error::cond.trap(|err| {
+ io_error::cond.trap(|err| {
assert_eq!(err.kind, PreviousIoError);
called = true;
- }).inside {
+ }).inside(|| {
assert!(reader.eof());
- }
+ });
assert!(called);
}
}
fn test_rposition_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
- do v.iter().rposition |_elt| {
+ v.iter().rposition(|_elt| {
if i == 2 {
fail!()
}
i += 1;
false
- };
+ });
}
static key: Key<~int> = &Key;
set(key, ~1);
- do get(key) |v| {
- do get(key) |v| {
- do get(key) |v| {
+ get(key, |v| {
+ get(key, |v| {
+ get(key, |v| {
assert_eq!(**v.unwrap(), 1);
- }
+ });
assert_eq!(**v.unwrap(), 1);
- }
+ });
assert_eq!(**v.unwrap(), 1);
- }
+ });
set(key, ~2);
- do get(key) |v| {
+ get(key, |v| {
assert_eq!(**v.unwrap(), 2);
- }
+ })
}
#[test]
static key: Key<int> = &Key;
set(key, 1);
- do get_mut(key) |v| {
+ get_mut(key, |v| {
*v.unwrap() = 2;
- }
+ });
- do get(key) |v| {
+ get(key, |v| {
assert_eq!(*v.unwrap(), 2);
- }
+ })
}
#[test]
fn test_nested_get_set1() {
static key: Key<int> = &Key;
set(key, 4);
- do get(key) |_| {
+ get(key, |_| {
set(key, 4);
- }
+ })
}
#[test]
fn test_nested_get_mut2() {
static key: Key<int> = &Key;
set(key, 4);
- do get(key) |_| {
+ get(key, |_| {
get_mut(key, |_| {})
- }
+ })
}
#[test]
fn test_nested_get_mut3() {
static key: Key<int> = &Key;
set(key, 4);
- do get_mut(key) |_| {
+ get_mut(key, |_| {
get(key, |_| {})
- }
+ })
}
#[test]
fn test_nested_get_mut4() {
static key: Key<int> = &Key;
set(key, 4);
- do get_mut(key) |_| {
+ get_mut(key, |_| {
get_mut(key, |_| {})
- }
+ })
}
}
#[bench]
fn uint_to_str_rand(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new();
- do bh.iter {
+ bh.iter(|| {
rng.gen::<uint>().to_str();
- }
+ })
}
#[bench]
fn float_to_str_rand(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new();
- do bh.iter {
+ bh.iter(|| {
f64::to_str(rng.gen());
- }
+ })
}
}
use num::Times;
let ten = 10 as uint;
let mut accum = 0;
- do ten.times { accum += 1; }
+ ten.times(|| { accum += 1; });
assert!((accum == 10));
}
#[test]
fn test_option_while_some() {
let mut i = 0;
- do Some(10).while_some |j| {
+ Some(10).while_some(|j| {
i += 1;
if (j > 0) {
Some(j-1)
} else {
None
}
- }
+ });
assert_eq!(i, 11);
}
use path::null_byte::cond;
let mut handled = false;
- let mut p = do cond.trap(|v| {
+ let mut p = cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("foo/bar", 0));
(b!("/bar").to_owned())
- }).inside {
+ }).inside(|| {
Path::new(b!("foo/bar", 0))
- };
+ });
assert!(handled);
assert_eq!(p.as_vec(), b!("/bar"));
handled = false;
- do cond.trap(|v| {
+ cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
- }).inside {
+ }).inside(|| {
p.set_filename(b!("f", 0, "o"))
- };
+ });
assert!(handled);
assert_eq!(p.as_vec(), b!("/foo"));
handled = false;
- do cond.trap(|v| {
+ cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
- }).inside {
+ }).inside(|| {
p.push(b!("f", 0, "o"));
- };
+ });
assert!(handled);
assert_eq!(p.as_vec(), b!("/foo/foo"));
}
)
t!(~"new() w/nul" => {
- do cond.trap(|_| {
+ cond.trap(|_| {
(b!("null", 0).to_owned())
- }).inside {
+ }).inside(|| {
Path::new(b!("foo/bar", 0))
- };
+ });
})
t!(~"set_filename w/nul" => {
let mut p = Path::new(b!("foo/bar"));
- do cond.trap(|_| {
+ cond.trap(|_| {
(b!("null", 0).to_owned())
- }).inside {
+ }).inside(|| {
p.set_filename(b!("foo", 0))
- };
+ });
})
t!(~"push w/nul" => {
let mut p = Path::new(b!("foo/bar"));
- do cond.trap(|_| {
+ cond.trap(|_| {
(b!("null", 0).to_owned())
- }).inside {
+ }).inside(|| {
p.push(b!("foo", 0))
- };
+ });
})
}
{
let mut called = false;
let path = Path::new($path);
- do path.display().with_str |s| {
+ path.display().with_str(|s| {
assert_eq!(s, $exp);
called = true;
- };
+ });
assert!(called);
}
);
{
let mut called = false;
let path = Path::new($path);
- do path.filename_display().with_str |s| {
+ path.filename_display().with_str(|s| {
assert_eq!(s, $exp);
called = true;
-
- };
+ });
assert!(called);
}
)
use path::null_byte::cond;
let mut handled = false;
- let mut p = do cond.trap(|v| {
+ let mut p = cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("foo\\bar", 0));
(b!("\\bar").to_owned())
- }).inside {
+ }).inside(|| {
Path::new(b!("foo\\bar", 0))
- };
+ });
assert!(handled);
assert_eq!(p.as_vec(), b!("\\bar"));
handled = false;
- do cond.trap(|v| {
+ cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
- }).inside {
+ }).inside(|| {
p.set_filename(b!("f", 0, "o"))
- };
+ });
assert!(handled);
assert_eq!(p.as_vec(), b!("\\foo"));
handled = false;
- do cond.trap(|v| {
+ cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
- }).inside {
+ }).inside(|| {
p.push(b!("f", 0, "o"));
- };
+ });
assert!(handled);
assert_eq!(p.as_vec(), b!("\\foo\\foo"));
}
)
t!(~"from_vec() w\\nul" => {
- do cond.trap(|_| {
+ cond.trap(|_| {
(b!("null", 0).to_owned())
- }).inside {
+ }).inside(|| {
Path::new(b!("foo\\bar", 0))
- };
+ });
})
t!(~"set_filename w\\nul" => {
let mut p = Path::new(b!("foo\\bar"));
- do cond.trap(|_| {
+ cond.trap(|_| {
(b!("null", 0).to_owned())
- }).inside {
+ }).inside(|| {
p.set_filename(b!("foo", 0))
- };
+ });
})
t!(~"push w\\nul" => {
let mut p = Path::new(b!("foo\\bar"));
- do cond.trap(|_| {
+ cond.trap(|_| {
(b!("null", 0).to_owned())
- }).inside {
+ }).inside(|| {
p.push(b!("foo", 0))
- };
+ });
})
}
let mut called = false;
let path = Path::new("foo");
- do path.display().with_str |s| {
+ path.display().with_str(|s| {
assert_eq!(s, "foo");
called = true;
- };
+ });
assert!(called);
called = false;
let path = Path::new(b!("\\"));
- do path.filename_display().with_str |s| {
+ path.filename_display().with_str(|s| {
assert_eq!(s, "");
called = true;
- }
+ });
assert!(called);
}
fn test_position() {
use libc::c_char;
- do "hello".with_c_str |p| {
+ "hello".with_c_str(|p| {
unsafe {
assert!(2u == position(p, |c| *c == 'l' as c_char));
assert!(4u == position(p, |c| *c == 'o' as c_char));
assert!(5u == position(p, |c| *c == 0 as c_char));
}
- }
+ })
}
#[test]
fn test_buf_len() {
- do "hello".with_c_str |p0| {
- do "there".with_c_str |p1| {
- do "thing".with_c_str |p2| {
+ "hello".with_c_str(|p0| {
+ "there".with_c_str(|p1| {
+ "thing".with_c_str(|p2| {
let v = ~[p0, p1, p2, null()];
- do v.as_imm_buf |vp, len| {
+ v.as_imm_buf(|vp, len| {
assert_eq!(unsafe { buf_len(vp) }, 3u);
assert_eq!(len, 4u);
- }
- }
- }
- }
+ })
+ })
+ })
+ })
}
#[test]
one, two, three
];
- do arr.as_imm_buf |arr_ptr, arr_len| {
+ arr.as_imm_buf(|arr_ptr, arr_len| {
let mut ctr = 0;
let mut iteration_count = 0;
- do array_each_with_len(arr_ptr, arr_len) |e| {
+ array_each_with_len(arr_ptr, arr_len, |e| {
let actual = str::raw::from_c_str(e);
- let expected = do expected_arr[ctr].with_ref |buf| {
+ let expected = expected_arr[ctr].with_ref(|buf| {
str::raw::from_c_str(buf)
- };
+ });
debug!(
"test_ptr_array_each_with_len e: {}, a: {}",
expected, actual);
assert_eq!(actual, expected);
ctr += 1;
iteration_count += 1;
- }
+ });
assert_eq!(iteration_count, 3u);
- }
+ })
}
}
one, two, three
];
- do arr.as_imm_buf |arr_ptr, _| {
+ arr.as_imm_buf(|arr_ptr, _| {
let mut ctr = 0;
let mut iteration_count = 0;
- do array_each(arr_ptr) |e| {
+ array_each(arr_ptr, |e| {
let actual = str::raw::from_c_str(e);
- let expected = do expected_arr[ctr].with_ref |buf| {
+ let expected = expected_arr[ctr].with_ref(|buf| {
str::raw::from_c_str(buf)
- };
+ });
debug!(
"test_ptr_array_each e: {}, a: {}",
expected, actual);
assert_eq!(actual, expected);
ctr += 1;
iteration_count += 1;
- }
+ });
assert_eq!(iteration_count, 3);
- }
+ })
}
}
let gamma = Gamma::new(10., 1.0);
let mut rng = StdRng::new();
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
gamma.ind_sample(&mut rng);
}
- }
+ });
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
}
let gamma = Gamma::new(0.1, 1.0);
let mut rng = StdRng::new();
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
gamma.ind_sample(&mut rng);
}
- }
+ });
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
}
}
let mut rng = XorShiftRng::new();
let mut normal = Normal::new(-2.71828, 3.14159);
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
normal.sample(&mut rng);
}
- }
+ });
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
}
#[bench]
let mut rng = XorShiftRng::new();
let mut exp = Exp::new(2.71828 * 3.14159);
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
exp.sample(&mut rng);
}
- }
+ });
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
}
}
#[bench]
fn rand_xorshift(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new();
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
rng.gen::<uint>();
}
- }
+ });
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
}
#[bench]
fn rand_isaac(bh: &mut BenchHarness) {
let mut rng = IsaacRng::new();
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
rng.gen::<uint>();
}
- }
+ });
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
}
#[bench]
fn rand_isaac64(bh: &mut BenchHarness) {
let mut rng = Isaac64Rng::new();
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
rng.gen::<uint>();
}
- }
+ });
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
}
#[bench]
fn rand_std(bh: &mut BenchHarness) {
let mut rng = StdRng::new();
- do bh.iter {
+ bh.iter(|| {
for _ in range(0, RAND_BENCH_N) {
rng.gen::<uint>();
}
- }
+ });
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
}
fn rand_shuffle_100(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new();
let x : &mut[uint] = [1,..100];
- do bh.iter {
+ bh.iter(|| {
rng.shuffle_mut(x);
- }
+ })
}
}
///
/// Example:
///
- /// let res = do read_file(file).map |buf| {
+ /// let res = read_file(file).map(|buf| {
/// parse_bytes(buf)
- /// }
+ /// })
#[inline]
pub fn map<U>(self, op: |T| -> U) -> Result<U,E> {
match self {
pub fn test_impl_iter() {
let mut valid = false;
let okval = Ok::<~str, ~str>(~"a");
- do okval.iter().next().map |_| { valid = true; };
+ okval.iter().next().map(|_| { valid = true; });
assert!(valid);
let errval = Err::<~str, ~str>(~"b");
- do errval.iter().next().map |_| { valid = false; };
+ errval.iter().next().map(|_| { valid = false; });
assert!(valid);
}
pub fn test_impl_iter_err() {
let mut valid = true;
let okval = Ok::<~str, ~str>(~"a");
- do okval.iter_err().next().map |_| { valid = false };
+ okval.iter_err().next().map(|_| { valid = false });
assert!(valid);
valid = false;
let errval = Err::<~str, ~str>(~"b");
- do errval.iter_err().next().map |_| { valid = true };
+ errval.iter_err().next().map(|_| { valid = true });
assert!(valid);
}
total.times(|| {
port.recv();
- })
+ });
}
}
total.times(|| {
end_port.recv();
- })
+ });
}
}
do spawntask_random {
chan_clone.send(());
}
- })
+ });
}
let end_chan_clone = end_chan.clone();
do spawntask_random {
let recvd = port_clone.try_recv().is_some();
end_chan_clone.send(recvd);
}
- })
+ });
}
let mut recvd = 0;
let pipe_clone = pipe.clone();
let end_chan_clone = end_chan.clone();
do spawntask_random {
- do msgs.times {
+ msgs.times(|| {
pipe_clone.send(());
- }
- do msgs.times {
+ });
+ msgs.times(|| {
pipe_clone.recv();
- }
+ });
}
end_chan_clone.send(());
total.times(|| {
end_port.recv();
- })
+ });
}
}
} else {
"_rust_crate_map_toplevel"
};
- let sym = do rust_crate_map_toplevel.with_c_str |buf| {
+ let sym = rust_crate_map_toplevel.with_c_str(|buf| {
dl::symbol(module, buf)
- };
+ });
dl::close(module);
sym
};
let mut cnt = 0;
unsafe {
- do iter_crate_map(&root_crate) |entry| {
+ iter_crate_map(&root_crate, |entry| {
assert!(*entry.log_level == 3);
cnt += 1;
- }
+ });
assert!(cnt == 1);
}
}
let mut cnt = 0;
unsafe {
- do iter_crate_map(&root_crate) |entry| {
+ iter_crate_map(&root_crate, |entry| {
assert!(*entry.log_level == cnt);
cnt += 1;
- }
+ });
assert!(cnt == 4);
}
}
#[bench]
fn alloc_owned_small(bh: &mut BenchHarness) {
- do bh.iter {
+ bh.iter(|| {
~10;
- }
+ })
}
#[bench]
fn alloc_owned_big(bh: &mut BenchHarness) {
- do bh.iter {
+ bh.iter(|| {
~[10, ..1000];
- }
+ })
}
}
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
Local::put(task);
- let res = do Local::borrow |_task: &mut Task| {
+ let res = Local::borrow(|_task: &mut Task| {
true
- };
+ });
assert!(res)
let task: ~Task = Local::take();
cleanup_task(task);
#[bench]
fn alloc_managed_small(bh: &mut BenchHarness) {
- bh.iter(|| @10);
+ bh.iter(|| { @10; });
}
#[bench]
fn alloc_managed_big(bh: &mut BenchHarness) {
- bh.iter(|| @[10, ..1000]);
+ bh.iter(|| { @[10, ..1000]; });
}
}
use util;
do run_in_bare_thread {
- do stress_factor().times {
+ stress_factor().times(|| {
let sleepers = SleeperList::new();
let queue = WorkQueue::new();
let queues = ~[queue.clone()];
util::ignore(handle);
thread.join();
- }
+ })
}
}
do run_in_mt_newsched_task {
let mut ports = ~[];
- do 10.times {
+ 10.times(|| {
let (port, chan) = oneshot();
let chan_cell = Cell::new(chan);
do spawntask_later {
chan_cell.take().send(());
}
ports.push(port);
- }
+ });
while !ports.is_empty() {
ports.pop().recv();
fn dont_starve_1() {
use rt::comm::oneshot;
- do stress_factor().times {
+ stress_factor().times(|| {
do run_in_mt_newsched_task {
let (port, chan) = oneshot();
chan.send(());
}
- }
+ })
}
#[test]
fn dont_starve_2() {
use rt::comm::oneshot;
- do stress_factor().times {
+ stress_factor().times(|| {
do run_in_newsched_task {
let (port, chan) = oneshot();
let (_port2, chan2) = stream();
chan.send(());
}
- }
+ })
}
// Regression test for a logic bug that would cause single-threaded schedulers
use num::Times;
do spawn_sched(SingleThreaded) {
- do 5.times { deschedule(); }
+ 5.times(|| { deschedule(); })
}
do spawn { }
do spawn { }
let tube_clone = tube.clone();
let tube_clone_cell = Cell::new(tube_clone);
let sched: ~Scheduler = Local::take();
- do sched.deschedule_running_task_and_then |sched, task| {
+ sched.deschedule_running_task_and_then(|sched, task| {
let mut tube_clone = tube_clone_cell.take();
tube_clone.send(1);
sched.enqueue_blocked_task(task);
- }
+ });
assert!(tube.recv() == 1);
}
let tube_clone = tube.clone();
let tube_clone = Cell::new(tube_clone);
let sched: ~Scheduler = Local::take();
- do sched.deschedule_running_task_and_then |sched, task| {
+ sched.deschedule_running_task_and_then(|sched, task| {
let tube_clone = Cell::new(tube_clone.take());
do sched.event_loop.callback {
let mut tube_clone = tube_clone.take();
tube_clone.send(1);
}
sched.enqueue_blocked_task(task);
- }
+ });
assert!(tube.recv() == 1);
}
let tube_clone = tube.clone();
let tube_clone = Cell::new(tube_clone);
let sched: ~Scheduler = Local::take();
- do sched.deschedule_running_task_and_then |sched, task| {
+ sched.deschedule_running_task_and_then(|sched, task| {
callback_send(tube_clone.take(), 0);
fn callback_send(tube: Tube<int>, i: int) {
if i == 100 { return; }
let tube = Cell::new(Cell::new(tube));
- do Local::borrow |sched: &mut Scheduler| {
+ Local::borrow(|sched: &mut Scheduler| {
let tube = tube.take();
do sched.event_loop.callback {
let mut tube = tube.take();
tube.send(i);
callback_send(tube, i + 1);
}
- }
+ })
}
sched.enqueue_blocked_task(task);
- }
+ });
for i in range(0, MAX) {
let j = tube.recv();
do run_in_uv_task {
let (ports, _) = unzip(range(0u, 10).map(|_| stream::<int>()));
let (port, chan) = stream();
- do 10.times { chan.send(31337); }
+ 10.times(|| { chan.send(31337); });
let mut ports = ports;
let mut port = Some(port);
let order = [5u,0,4,3,2,6,9,8,7,1];
do run_in_uv_task {
// A bit of stress, since ordinarily this is just smoke and mirrors.
- do 4.times {
+ 4.times(|| {
let send_on_chans = send_on_chans.clone();
do task::spawn {
let mut ports = ~[];
// nondeterministic result, but should succeed
select(ports);
}
- }
+ })
}
}
}
Lorem ipsum dolor sit amet, consectetur. ");
assert_eq!(100, s.len());
- bh.iter(|| is_utf8(s));
+ bh.iter(|| {
+ let _ = is_utf8(s);
+ });
}
#[bench]
fn is_utf8_100_multibyte(bh: &mut BenchHarness) {
let s = bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
assert_eq!(100, s.len());
- bh.iter(|| is_utf8(s));
+ bh.iter(|| {
+ let _ = is_utf8(s);
+ });
}
#[bench]
fn bench_with_capacity(bh: &mut BenchHarness) {
- bh.iter(|| with_capacity(100));
+ bh.iter(|| {
+ let _ = with_capacity(100);
+ });
}
#[bench]
do run_in_uv_task {
do spawn {
- do with_task_name |name| {
+ with_task_name(|name| {
assert!(name.is_none());
- }
+ })
}
}
}
let mut t = task();
t.name(~"ada lovelace");
do t.spawn {
- do with_task_name |name| {
+ with_task_name(|name| {
assert!(name.unwrap() == "ada lovelace");
- }
+ })
}
}
}
let mut t = task();
t.name("ada lovelace");
do t.spawn {
- do with_task_name |name| {
+ with_task_name(|name| {
assert!(name.unwrap() == "ada lovelace");
- }
+ })
}
}
}
let mut t = task();
t.name("ada lovelace".into_send_str());
do t.spawn {
- do with_task_name |name| {
+ with_task_name(|name| {
assert!(name.unwrap() == "ada lovelace");
- }
+ })
}
}
}
#[cfg(test)]
fn get_sched_id() -> int {
- do Local::borrow |sched: &mut ::rt::sched::Scheduler| {
+ Local::borrow(|sched: &mut ::rt::sched::Scheduler| {
sched.sched_id() as int
- }
+ })
}
#[test]
// Testing that a task in one scheduler can block in foreign code
// without affecting other schedulers
- do 20u.times {
+ 20u.times(|| {
let (start_po, start_ch) = stream();
let (fin_po, fin_ch) = stream();
lock.unlock();
fin_po.recv();
lock.destroy();
- }
+ })
}
}
#[test]
fn test_avoid_copying_the_body_task_spawn() {
- do avoid_copying_the_body |f| {
+ avoid_copying_the_body(|f| {
let builder = task();
do builder.spawn || {
f();
}
- }
+ })
}
#[test]
fn test_avoid_copying_the_body_try() {
- do avoid_copying_the_body |f| {
+ avoid_copying_the_body(|f| {
do try || {
f()
};
- }
+ })
}
#[test]
# Example
```
-do || {
+(|| {
...
-}.finally {
+}).finally(|| {
always_run_this();
-}
+})
```
*/
#[test]
fn test_success() {
let mut i = 0;
- do (|| {
+ (|| {
i = 10;
- }).finally {
+ }).finally(|| {
assert!(!failing());
assert_eq!(i, 10);
i = 20;
- }
+ });
assert_eq!(i, 20);
}
#[should_fail]
fn test_fail() {
let mut i = 0;
- do (|| {
+ (|| {
i = 10;
fail!();
- }).finally {
+ }).finally(|| {
assert!(failing());
assert_eq!(i, 10);
- }
+ })
}
#[test]
fn test_retval() {
let closure: || -> int = || 10;
- let i = do closure.finally { };
+ let i = closure.finally(|| { });
assert_eq!(i, 10);
}
fn trait_vtable_method_call(bh: &mut BenchHarness) {
let s = Struct { field: 10 };
let t = &s as &Trait;
- do bh.iter {
+ bh.iter(|| {
t.method();
- }
+ });
}
#[bench]
fn trait_static_method_call(bh: &mut BenchHarness) {
let s = Struct { field: 10 };
- do bh.iter {
+ bh.iter(|| {
s.method();
- }
+ });
}
// Overhead of various match forms
#[bench]
fn match_option_some(bh: &mut BenchHarness) {
let x = Some(10);
- do bh.iter {
+ bh.iter(|| {
let _q = match x {
Some(y) => y,
None => 11
};
- }
+ });
}
#[bench]
fn match_vec_pattern(bh: &mut BenchHarness) {
let x = [1,2,3,4,5,6];
- do bh.iter {
+ bh.iter(|| {
let _q = match x {
[1,2,3,.._] => 10,
_ => 11
};
- }
+ });
}
}
#[bench]
fn concat(bh: &mut BenchHarness) {
let xss: &[~[uint]] = vec::from_fn(100, |i| range(0, i).collect());
- bh.iter(|| xss.concat_vec());
+ bh.iter(|| {
+ let _ = xss.concat_vec();
+ });
}
#[bench]
fn connect(bh: &mut BenchHarness) {
let xss: &[~[uint]] = vec::from_fn(100, |i| range(0, i).collect());
- bh.iter(|| xss.connect_vec(&0));
+ bh.iter(|| {
+ let _ = xss.connect_vec(&0);
+ });
}
#[bench]
}
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()
- }
+ })
}
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();
}
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); }
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
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();
}
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); }
+++ /dev/null
-// 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);
-}
let mut p = ~[1];
- do borrow(p) {
+ borrow(p, || {
p[0] = 5; //~ ERROR cannot assign to
- }
+ });
}
fn c() {
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`
},
_ => fail!()
}
- }
+ })
}
}
fn bar(f: &mut Foo) {
- do f.foo |a| {
+ f.foo(|a| {
f.n.insert(*a); //~ ERROR cannot borrow
- }
+ })
}
fn main() {
let mut v = ~3;
let mut x = &mut v;
- do 3.times {
+ 3.times(|| {
borrow(v); //~ ERROR cannot borrow
- }
+ });
*x = ~5;
}
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() {
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() {
q.impurem();
// ...but we still detect errors statically when we can.
- do q.blockm {
+ q.blockm(|| {
q.x = 10; //~ ERROR cannot assign
- }
+ })
}
fn main() {
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() {
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};
}
fn foo(x: &()) {
- do bar {
+ bar(|| {
let _ = x; //~ ERROR does not fulfill `'static`
- }
+ })
}
fn main() {
// 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);
let mut a = ~[];
a.push(3);
let mut a = ~[];
- do callback {
+ callback(|| {
a.push(3);
- }
+ });
let (mut a, b) = (1, 2);
a = 34;
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
unsafe {
unsafe fn what() -> ~[~str] { fail!() }
- do callback {
+ callback(|| {
what();
- }
+ });
}
}
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 => {}
}
- }
+ })
}
}
fn innocent_looking_victim() {
let mut x = Some(~"hello");
- do conspirator |f, writer| {
+ conspirator(|f, writer| {
if writer {
x = None;
} else {
None => fail!("oops"),
}
}
- }
+ })
}
fn conspirator(f: |&R, bool|) {
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
+ })
};
}
fn main() {
let x = arc::Arc::new(true);
- do foo {
+ foo(|| {
assert!(*x.get());
util::ignore(x);
- }
+ })
}
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
- }
+ })
}
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);
- }
+ })
}
}
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
}
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();
}
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();
}
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 { }
}
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();
}
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 { }
}
// 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);
// This should fail.
error!("ov1 0x{:x}", x[idx]);
- }
+ })
}
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
// 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());
}
}
pub fn main() {
- do 10000.times || {bitv_test()};
+ 10000.times(|| bitv_test());
}
// 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];
+fn add(x: proc(f64) -> f64) -> f64 {
+ x(10.0)
+}
+pub fn main() {
// Trailing expressions don't require parentheses:
- let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0;
+ let y = do add |x| { x + 10.0 } + 10.0;
- assert_eq!(y, 15.0);
+ assert_eq!(y, 30.0);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+fn f(_: proc()) -> proc(proc() -> uint) {
+ proc(_: proc() -> uint) {}
+}
+
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);
+ do do f {} { 20 };
}
// 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);
}
// 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();
}
// 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();
}
// 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];
}
// 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.");
// 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);
}
}
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() {
add_int(ints, 22);
add_int(ints, 44);
- do iter_ints(ints) |i| {
+ iter_ints(ints, |i| {
error!("int = {}", *i);
true
- };
+ });
error!("ints={:?}", ints);
}
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};
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)));
- }
+ })
}
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};
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)));
- }
+ })
}
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;
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)));
- }
+ })
}
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};
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)));
- }
+ })
}
//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);
- }
+ })
}
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));
- }
+ })
}
// 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);
- }
+ })
}
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) {
roundtrip::<C>();
roundtrip::<D>();
- do 20.times {
+ 20.times(|| {
roundtrip::<E>();
roundtrip::<F>();
roundtrip::<G<int>>();
- }
+ })
}
fn main() {
// check there's no segfaults
- do 20.times {
+ 20.times(|| {
rand::random::<A>();
rand::random::<B>();
rand::random::<C>();
rand::random::<D>();
- }
+ })
}
// no-reformat
// Testing various forms of `do` with empty arg lists
-fn f(_f: || -> bool) -> bool {
+fn f(_f: proc() -> bool) -> bool {
true
}
// 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 { }
+++ /dev/null
-// 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() {
-}
+++ /dev/null
-// 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) }
-}
// 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) }
// 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);
// 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);
}
pub fn main() {
- do 100u.times {
+ 100u.times(|| {
do task::spawn {
assert_eq!(count(5u), 16u);
};
- }
+ })
}
}
pub fn main() {
- do 10u.times {
+ 10u.times(|| {
do task::spawn {
let result = count(5u);
info!("result = {}", result);
assert_eq!(result, 16u);
};
- }
+ })
}
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);
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);
}
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);
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() {
+++ /dev/null
-// 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);
-}
impl socket {
pub fn set_identity(&self) {
- do closure {
- setsockopt_bytes(self.sock.clone())
- }
+ closure(|| setsockopt_bytes(self.sock.clone()))
}
}
{
&extra::json::List(ref interfaces) =>
{
- do interfaces.map |interface| {
+ interfaces.map(|interface| {
add_interface(store, managed_ip.clone(), (*interface).clone())
- }
+ })
}
_ =>
{
pub fn main() {
let mut x = 0;
- do 4096.times {
- x += 1;
- }
+ 4096.times(|| x += 1);
assert_eq!(x, 4096);
println!("x = {}", x);
}
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.
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")
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);
}
impl Fooable for uint {
fn yes(self) {
- do self.times {
- println("yes");
- }
+ self.times(|| println("yes"));
}
}
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);
}
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!()
}
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(||{});
}
fn main() {
let x = arc::Arc::new(true);
- do foo {
+ foo(|| {
assert!(*x.get());
util::ignore(x);
- }
+ })
}
#[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)]
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 }
}
fn has_one<'a>(x: &'a int) -> int {
- do with |y| { takes_two(x, y) }
+ with(|y| takes_two(x, y))
}
pub fn main() {
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"]);
}
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]>) {
}
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() { }
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;
// 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
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!()
}
// 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);
- }
+ })
}
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));
}
}
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)
- }
+ })
}
// 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();
- }
+ })
}