diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index 1ac6c215d27..c40cec262f8 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -260,7 +260,7 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn { use core::cell::Cell; - let config = Cell(copy *config); - let testfile = Cell(testfile.to_str()); + let config = Cell::new(copy *config); + let testfile = Cell::new(testfile.to_str()); test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) }) } diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 6c838a82a2f..15c24052563 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -558,7 +558,7 @@ fn test_mutex_arc_condvar() { let arc = ~MutexARC(false); let arc2 = ~arc.clone(); let (p,c) = comm::oneshot(); - let (c,p) = (Cell(c), Cell(p)); + let (c,p) = (Cell::new(c), Cell::new(p)); do task::spawn || { // wait until parent gets in comm::recv_one(p.take()); diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs index 31218ca9a0a..e8239b9f7fd 100644 --- a/src/libextra/flatpipes.rs +++ b/src/libextra/flatpipes.rs @@ -660,7 +660,7 @@ mod test { #[test] #[ignore(reason = "ebml failure")] fn test_serializing_memory_stream() { - let writer = BytesWriter(); + let writer = BytesWriter::new(); let chan = serial::writer_chan(writer); chan.send(10); @@ -708,7 +708,7 @@ fn test_serializing_boxes() { #[test] fn test_pod_memory_stream() { - let writer = BytesWriter(); + let writer = BytesWriter::new(); let chan = pod::writer_chan(writer); chan.send(10); @@ -791,8 +791,8 @@ fn test_some_tcp_stream,F:Flattener>( let addr0 = ip::v4::parse_addr("127.0.0.1"); - let begin_connect_chan = Cell(begin_connect_chan); - let accept_chan = Cell(accept_chan); + let begin_connect_chan = Cell::new(begin_connect_chan); + let accept_chan = Cell::new(accept_chan); // The server task let addr = copy addr0; diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 25a3259c696..40cfeebd5dc 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -109,7 +109,7 @@ pub fn from_port(port: PortOne) -> Future { * waiting for the result to be received on the port. */ - let port = Cell(port); + let port = Cell::new(port); do from_fn { recv_one(port.take()) } @@ -137,7 +137,7 @@ pub fn spawn(blk: ~fn() -> A) -> Future { let (port, chan) = oneshot(); - let chan = Cell(chan); + let chan = Cell::new(chan); do task::spawn { let chan = chan.take(); send_one(chan, blk()); @@ -204,7 +204,7 @@ fn test_futurefail() { #[test] fn test_sendable_future() { let expected = "schlorf"; - let f = Cell(do spawn { expected }); + let f = Cell::new(do spawn { expected }); do task::spawn { let mut f = f.take(); let actual = f.get(); diff --git a/src/libextra/net_tcp.rs b/src/libextra/net_tcp.rs index 960319b9c3f..87ebfdfb797 100644 --- a/src/libextra/net_tcp.rs +++ b/src/libextra/net_tcp.rs @@ -1830,7 +1830,7 @@ fn run_tcp_test_server(server_ip: &str, server_port: uint, resp: ~str, let (server_po, server_ch) = stream::<~str>(); let server_ch = SharedChan::new(server_ch); let server_ip_addr = ip::v4::parse_addr(server_ip); - let resp_cell = Cell(resp); + let resp_cell = Cell::new(resp); let listen_result = listen(server_ip_addr, server_port, 128, iotask, // on_establish_cb -- called when listener is set up @@ -1842,7 +1842,7 @@ fn run_tcp_test_server(server_ip: &str, server_port: uint, resp: ~str, // risky to run this on the loop, but some users // will want the POWER |new_conn, kill_ch| { - let resp_cell2 = Cell(resp_cell.take()); + let resp_cell2 = Cell::new(resp_cell.take()); debug!("SERVER: new connection!"); let (cont_po, cont_ch) = stream(); let server_ch = server_ch.clone(); diff --git a/src/libextra/rc.rs b/src/libextra/rc.rs index 1ec72f2ea9f..96ad629ea83 100644 --- a/src/libextra/rc.rs +++ b/src/libextra/rc.rs @@ -105,7 +105,7 @@ mod test_rc { #[test] fn test_clone() { - let x = rc_from_owned(Cell(5)); + let x = rc_from_owned(Cell::new(5)); let y = x.clone(); do x.borrow().with_mut_ref |inner| { *inner = 20; @@ -115,7 +115,7 @@ fn test_clone() { #[test] fn test_deep_clone() { - let x = rc_from_owned(Cell(5)); + let x = rc_from_owned(Cell::new(5)); let y = x.deep_clone(); do x.borrow().with_mut_ref |inner| { *inner = 20; diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 79ecf4abbee..8f09ddea9ba 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -818,7 +818,7 @@ fn test_sem_runtime_friendly_blocking() { let s = ~semaphore(1); let s2 = ~s.clone(); let (p,c) = comm::stream(); - let child_data = Cell((s2, c)); + let child_data = Cell::new((s2, c)); do s.access { let (s2, c) = child_data.take(); do task::spawn || { @@ -999,7 +999,7 @@ fn test_mutex_killed_broadcast() { let mut sibling_convos = ~[]; for 2.times { let (p,c) = comm::stream(); - let c = Cell(c); + let c = Cell::new(c); sibling_convos.push(p); let mi = ~m2.clone(); // spawn sibling task diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 99903be8b22..6a9751b66e0 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -568,7 +568,7 @@ pub fn run_test(force_ignore: bool, fn run_test_inner(desc: TestDesc, monitor_ch: SharedChan, testfn: ~fn()) { - let testfn_cell = ::core::cell::Cell(testfn); + let testfn_cell = ::core::cell::Cell::new(testfn); do task::spawn { let mut result_future = None; // task::future_result(builder); diff --git a/src/libextra/timer.rs b/src/libextra/timer.rs index 4f662613b00..f2513366663 100644 --- a/src/libextra/timer.rs +++ b/src/libextra/timer.rs @@ -282,7 +282,7 @@ fn test_gl_timer_recv_timeout_after_time_passes() { for (times as uint).times { let mut rng = rand::rng(); - let expected = Cell(rng.gen_str(16u)); + let expected = Cell::new(rng.gen_str(16u)); let (test_po, test_ch) = stream::<~str>(); let hl_loop_clone = hl_loop.clone(); do task::spawn() { diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 5d494b1b916..b2fd998b73f 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -347,7 +347,7 @@ fn exec { let (port, chan) = oneshot(); let blk = replace(&mut bo, None).unwrap(); - let chan = Cell(chan); + let chan = Cell::new(chan); do task::spawn { let exe = Exec { diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 5fce4f2f731..6f453a79b68 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1425,7 +1425,7 @@ fn encode_hash(ebml_w: &mut writer::Encoder, hash: &str) { 0, 0, 0, 1 ]; pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] { - let wr = @io::BytesWriter(); + let wr = @io::BytesWriter::new(); let stats = Stats { inline_bytes: 0, attr_bytes: 0, diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index f99d096f03d..b004e608046 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -546,7 +546,7 @@ fn(&a, &b, &a) fn(&x, &y, &y) fn(&a, &a, &a) fn(&a,&b,&c) use util::common::indenter; use util::ppaux::note_and_explain_region; -use core::cell::{Cell, empty_cell}; +use core::cell::Cell; use core::hashmap::{HashMap, HashSet}; use core::to_bytes; use core::uint; @@ -633,7 +633,7 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings { RegionVarBindings { tcx: tcx, var_spans: ~[], - values: empty_cell(), + values: Cell::new_empty(), constraints: HashMap::new(), lubs: HashMap::new(), glbs: HashMap::new(), diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index ae7968a4d46..c4fc377bc8b 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -65,8 +65,8 @@ fn run(owner: SrvOwner, source: ~str, parse: Parser) -> T { let (po, ch) = stream(); - let source = Cell(source); - let parse = Cell(parse); + let source = Cell::new(source); + let parse = Cell::new(parse); do task::spawn { act(&po, source.take(), parse.take()); } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 4beb8583bae..691f0dfedc4 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -178,7 +178,7 @@ fn config_from_opts( } } }; - let process_output = Cell(process_output); + let process_output = Cell::new(process_output); let result = do result::chain(result) |config| { let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd()); let pandoc_cmd = maybe_find_pandoc( diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index d34aa7c9955..b17816d4e36 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -28,7 +28,7 @@ use syntax; pub fn mk_pass(writer_factory: WriterFactory) -> Pass { - let writer_factory = Cell(writer_factory); + let writer_factory = Cell::new(writer_factory); Pass { name: ~"markdown", f: |srv, doc| run(srv, doc, writer_factory.take()) diff --git a/src/librustdoc/text_pass.rs b/src/librustdoc/text_pass.rs index 7e5444af05c..96a67ea3243 100644 --- a/src/librustdoc/text_pass.rs +++ b/src/librustdoc/text_pass.rs @@ -23,7 +23,7 @@ use core::cell::Cell; pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass { - let op = Cell(op); + let op = Cell::new(op); Pass { name: copy name, f: |srv: astsrv::Srv, doc: doc::Doc| -> doc::Doc { diff --git a/src/librusti/rusti.rc b/src/librusti/rusti.rc index 08325ffb2a3..56a87eb8055 100644 --- a/src/librusti/rusti.rc +++ b/src/librusti/rusti.rc @@ -365,8 +365,8 @@ pub fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str, } } - let line = Cell(line); - let r = Cell(copy *repl); + let line = Cell::new(line); + let r = Cell::new(copy *repl); let result = do task::try { run(r.take(), line.take()) }; diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index ab4752ff847..e1d2b246dd3 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -29,17 +29,17 @@ pub struct Cell { priv value: Option } -/// Creates a new full cell with the given value. -pub fn Cell(value: T) -> Cell { - Cell { value: Some(value) } -} - -/// Creates a new empty cell with no value inside. -pub fn empty_cell() -> Cell { - Cell { value: None } -} - impl Cell { + /// Creates a new full cell with the given value. + pub fn new(value: T) -> Cell { + Cell { value: Some(value) } + } + + /// Creates a new empty cell with no value inside. + pub fn new_empty() -> Cell { + Cell { value: None } + } + /// Yields the value, failing if the cell is empty. pub fn take(&self) -> T { let this = unsafe { transmute_mut(self) }; @@ -83,7 +83,7 @@ pub fn with_mut_ref(&self, op: &fn(v: &mut T) -> R) -> R { #[test] fn test_basic() { - let value_cell = Cell(~10); + let value_cell = Cell::new(~10); assert!(!value_cell.is_empty()); let value = value_cell.take(); assert!(value == ~10); @@ -96,7 +96,7 @@ fn test_basic() { #[should_fail] #[ignore(cfg(windows))] fn test_take_empty() { - let value_cell = empty_cell::<~int>(); + let value_cell = Cell::new_empty::<~int>(); value_cell.take(); } @@ -104,14 +104,14 @@ fn test_take_empty() { #[should_fail] #[ignore(cfg(windows))] fn test_put_back_non_empty() { - let value_cell = Cell(~10); + let value_cell = Cell::new(~10); value_cell.put_back(~20); } #[test] fn test_with_ref() { let good = 6; - let c = Cell(~[1, 2, 3, 4, 5, 6]); + let c = Cell::new(~[1, 2, 3, 4, 5, 6]); let l = do c.with_ref() |v| { v.len() }; assert_eq!(l, good); } @@ -120,7 +120,7 @@ fn test_with_ref() { fn test_with_mut_ref() { let good = ~[1, 2, 3]; let v = ~[1, 2]; - let c = Cell(v); + let c = Cell::new(v); do c.with_mut_ref() |v| { v.push(3); } let v = c.take(); assert_eq!(v, good); diff --git a/src/libstd/io.rs b/src/libstd/io.rs index bfe82a015cd..8fe592db403 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -982,6 +982,12 @@ pub struct FILERes { f: *libc::FILE, } +impl FILERes { + pub fn new(f: *libc::FILE) -> FILERes { + FILERes { f: f } + } +} + impl Drop for FILERes { fn finalize(&self) { unsafe { @@ -990,15 +996,9 @@ fn finalize(&self) { } } -pub fn FILERes(f: *libc::FILE) -> FILERes { - FILERes { - f: f - } -} - pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader { if cleanup { - @Wrapper { base: f, cleanup: FILERes(f) } as @Reader + @Wrapper { base: f, cleanup: FILERes::new(f) } as @Reader } else { @f as @Reader } @@ -1183,7 +1183,7 @@ fn get_type(&self) -> WriterType { pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer { if cleanup { - @Wrapper { base: f, cleanup: FILERes(f) } as @Writer + @Wrapper { base: f, cleanup: FILERes::new(f) } as @Writer } else { @f as @Writer } @@ -1227,6 +1227,12 @@ pub struct FdRes { fd: fd_t, } +impl FdRes { + pub fn new(fd: fd_t) -> FdRes { + FdRes { fd: fd } + } +} + impl Drop for FdRes { fn finalize(&self) { unsafe { @@ -1235,15 +1241,9 @@ fn finalize(&self) { } } -pub fn FdRes(fd: fd_t) -> FdRes { - FdRes { - fd: fd - } -} - pub fn fd_writer(fd: fd_t, cleanup: bool) -> @Writer { if cleanup { - @Wrapper { base: fd, cleanup: FdRes(fd) } as @Writer + @Wrapper { base: fd, cleanup: FdRes::new(fd) } as @Writer } else { @fd as @Writer } @@ -1634,6 +1634,15 @@ pub struct BytesWriter { pos: @mut uint, } +impl BytesWriter { + pub fn new() -> BytesWriter { + BytesWriter { + bytes: @mut ~[], + pos: @mut 0 + } + } +} + impl Writer for BytesWriter { fn write(&self, v: &[u8]) { let v_len = v.len(); @@ -1673,15 +1682,8 @@ fn get_type(&self) -> WriterType { } } -pub fn BytesWriter() -> BytesWriter { - BytesWriter { - bytes: @mut ~[], - pos: @mut 0 - } -} - pub fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] { - let wr = @BytesWriter(); + let wr = @BytesWriter::new(); f(wr as @Writer); let @BytesWriter { bytes, _ } = wr; copy *bytes @@ -1762,6 +1764,12 @@ pub struct Res { arg: Arg, } + impl Res { + pub fn new(arg: Arg) -> Res { + Res { arg: arg } + } + } + #[unsafe_destructor] impl Drop for Res { fn finalize(&self) { @@ -1776,12 +1784,6 @@ fn finalize(&self) { } } - pub fn Res(arg: Arg) -> Res{ - Res { - arg: arg - } - } - pub struct Arg { val: t, opt_level: Option, @@ -1793,7 +1795,7 @@ pub struct Arg { // outer res pub fn FILE_res_sync(file: &FILERes, opt_level: Option, blk: &fn(v: Res<*libc::FILE>)) { - blk(Res(Arg { + blk(Res::new(Arg { val: file.f, opt_level: opt_level, fsync_fn: |file, l| { unsafe { @@ -1806,7 +1808,7 @@ pub fn FILE_res_sync(file: &FILERes, opt_level: Option, // fsync fd after executing blk pub fn fd_res_sync(fd: &FdRes, opt_level: Option, blk: &fn(v: Res)) { - blk(Res(Arg { + blk(Res::new(Arg { val: fd.fd, opt_level: opt_level, fsync_fn: |fd, l| os::fsync_fd(fd, l) as int })); @@ -1818,7 +1820,7 @@ pub fn fd_res_sync(fd: &FdRes, opt_level: Option, // Call o.fsync after executing blk pub fn obj_sync(o: @FSyncable, opt_level: Option, blk: &fn(v: Res<@FSyncable>)) { - blk(Res(Arg { + blk(Res::new(Arg { val: o, opt_level: opt_level, fsync_fn: |o, l| o.fsync(l) })); @@ -1993,7 +1995,7 @@ fn buffered_file_writer_bad_name() { #[test] fn bytes_buffer_overwrite() { - let wr = BytesWriter(); + let wr = BytesWriter::new(); wr.write([0u8, 1u8, 2u8, 3u8]); assert!(*wr.bytes == ~[0u8, 1u8, 2u8, 3u8]); wr.seek(-2, SeekCur); diff --git a/src/libstd/option.rs b/src/libstd/option.rs index b9d04edd8a3..2386a779235 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -437,7 +437,7 @@ fn test_option_dance() { } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_option_too_much_dance() { - let mut y = Some(util::NonCopyable()); + let mut y = Some(util::NonCopyable::new()); let _y2 = y.swap_unwrap(); let _y3 = y.swap_unwrap(); } diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 54db03b6069..8a8f31bbdfa 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -309,8 +309,8 @@ pub struct Port { pub fn stream() -> (Port, Chan) { let (pone, cone) = oneshot(); - let port = Port { next: Cell(pone) }; - let chan = Chan { next: Cell(cone) }; + let port = Port { next: Cell::new(pone) }; + let chan = Chan { next: Cell::new(cone) }; return (port, chan); } @@ -483,7 +483,7 @@ fn oneshot_single_thread_peek_open() { fn oneshot_multi_task_recv_then_send() { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let port_cell = Cell(port); + let port_cell = Cell::new(port); do spawntask_immediately { assert!(port_cell.take().recv() == ~10); } @@ -496,8 +496,8 @@ fn oneshot_multi_task_recv_then_send() { fn oneshot_multi_task_recv_then_close() { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let port_cell = Cell(port); - let chan_cell = Cell(chan); + let port_cell = Cell::new(port); + let chan_cell = Cell::new(chan); do spawntask_later { let _cell = chan_cell.take(); } @@ -513,7 +513,7 @@ fn oneshot_multi_thread_close_stress() { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let port_cell = Cell(port); + let port_cell = Cell::new(port); let _thread = do spawntask_thread { let _p = port_cell.take(); }; @@ -527,8 +527,8 @@ fn oneshot_multi_thread_send_close_stress() { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let chan_cell = Cell(chan); - let port_cell = Cell(port); + let chan_cell = Cell::new(chan); + let port_cell = Cell::new(port); let _thread1 = do spawntask_thread { let _p = port_cell.take(); }; @@ -545,17 +545,17 @@ fn oneshot_multi_thread_recv_close_stress() { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::(); - let chan_cell = Cell(chan); - let port_cell = Cell(port); + let chan_cell = Cell::new(chan); + let port_cell = Cell::new(port); let _thread1 = do spawntask_thread { - let port_cell = Cell(port_cell.take()); + let port_cell = Cell::new(port_cell.take()); let res = do spawntask_try { port_cell.take().recv(); }; assert!(res.is_err()); }; let _thread2 = do spawntask_thread { - let chan_cell = Cell(chan_cell.take()); + let chan_cell = Cell::new(chan_cell.take()); do spawntask { chan_cell.take(); } @@ -569,8 +569,8 @@ fn oneshot_multi_thread_send_recv_stress() { for stress_factor().times { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); - let chan_cell = Cell(chan); - let port_cell = Cell(port); + let chan_cell = Cell::new(chan); + let port_cell = Cell::new(port); let _thread1 = do spawntask_thread { chan_cell.take().send(~10); }; @@ -593,7 +593,7 @@ fn stream_send_recv_stress() { fn send(chan: Chan<~int>, i: int) { if i == 10 { return } - let chan_cell = Cell(chan); + let chan_cell = Cell::new(chan); let _thread = do spawntask_thread { let chan = chan_cell.take(); chan.send(~i); @@ -604,7 +604,7 @@ fn send(chan: Chan<~int>, i: int) { fn recv(port: Port<~int>, i: int) { if i == 10 { return } - let port_cell = Cell(port); + let port_cell = Cell::new(port); let _thread = do spawntask_thread { let port = port_cell.take(); assert!(port.recv() == ~i); diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs index fcbf31e87f2..7d6d89ce997 100644 --- a/src/libstd/rt/io/extensions.rs +++ b/src/libstd/rt/io/extensions.rs @@ -604,7 +604,7 @@ fn read_byte() { #[test] fn read_byte_0_bytes() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -652,7 +652,7 @@ fn read_bytes() { #[test] fn read_bytes_partial() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -691,7 +691,7 @@ fn push_bytes() { #[test] fn push_bytes_partial() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -725,7 +725,7 @@ fn push_bytes_eof() { #[test] fn push_bytes_error() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -754,7 +754,7 @@ fn push_bytes_fail_reset_len() { // push_bytes unsafely sets the vector length. This is testing that // upon failure the length is reset correctly. let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -779,7 +779,7 @@ fn push_bytes_fail_reset_len() { #[test] fn read_to_end() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { @@ -806,7 +806,7 @@ fn read_to_end() { #[ignore(cfg(windows))] fn read_to_end_error() { let mut reader = MockReader::new(); - let count = Cell(0); + let count = Cell::new(0); reader.read = |buf| { do count.with_mut_ref |count| { if *count == 0 { diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs index f7c03c13a58..3607f781da3 100644 --- a/src/libstd/rt/io/net/tcp.rs +++ b/src/libstd/rt/io/net/tcp.rs @@ -287,7 +287,7 @@ fn multiple_connect_interleaved_greedy_schedule() { do spawntask_immediately { let mut listener = TcpListener::bind(addr); for int::range(0, MAX) |i| { - let stream = Cell(listener.accept()); + let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection do spawntask_immediately { @@ -326,7 +326,7 @@ fn multiple_connect_interleaved_lazy_schedule() { do spawntask_immediately { let mut listener = TcpListener::bind(addr); for int::range(0, MAX) |_| { - let stream = Cell(listener.accept()); + let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection do spawntask_later { diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 80d797e8c65..0db903f81ee 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -79,7 +79,7 @@ pub unsafe fn borrow(f: &fn(&mut T)) { // XXX: Need a different abstraction from 'finally' here to avoid unsafety let unsafe_ptr = cast::transmute_mut_region(&mut *value); - let value_cell = Cell(value); + let value_cell = Cell::new(value); do (|| { f(unsafe_ptr); diff --git a/src/libstd/rt/message_queue.rs b/src/libstd/rt/message_queue.rs index fb1a5334646..5b60543344d 100644 --- a/src/libstd/rt/message_queue.rs +++ b/src/libstd/rt/message_queue.rs @@ -30,7 +30,7 @@ pub fn new() -> MessageQueue { pub fn push(&mut self, value: T) { unsafe { - let value = Cell(value); + let value = Cell::new(value); self.queue.with(|q| q.push(value.take()) ); } } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index f6017b92807..f9f433b9416 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -194,7 +194,7 @@ pub fn context() -> RuntimeContext { return OldTaskContext; } else { if Local::exists::() { - let context = ::cell::empty_cell(); + let context = ::cell::Cell::new_empty(); do Local::borrow:: |sched| { if sched.in_task_context() { context.put_back(TaskContext); @@ -231,7 +231,7 @@ fn test_context() { let sched = Local::take::(); do sched.deschedule_running_task_and_then() |task| { assert_eq!(context(), SchedulerContext); - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { sched.enqueue_task(task.take()); } diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 064eb63afc6..929b44f79b5 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -146,7 +146,7 @@ pub fn terminate_current_task(~self) { rtdebug!("ending running task"); do self.deschedule_running_task_and_then |dead_task| { - let dead_task = Cell(dead_task); + let dead_task = Cell::new(dead_task); do Local::borrow:: |sched| { dead_task.take().recycle(&mut sched.stack_pool); } @@ -159,7 +159,7 @@ pub fn schedule_new_task(~self, task: ~Coroutine) { assert!(self.in_task_context()); do self.switch_running_tasks_and_then(task) |last_task| { - let last_task = Cell(last_task); + let last_task = Cell::new(last_task); do Local::borrow:: |sched| { sched.enqueue_task(last_task.take()); } @@ -170,7 +170,7 @@ pub fn schedule_task(~self, task: ~Coroutine) { assert!(self.in_task_context()); do self.switch_running_tasks_and_then(task) |last_task| { - let last_task = Cell(last_task); + let last_task = Cell::new(last_task); do Local::borrow:: |sched| { sched.enqueue_task(last_task.take()); } @@ -462,7 +462,7 @@ fn test_swap_tasks_then() { }; // Context switch directly to the new task do sched.switch_running_tasks_and_then(task2) |task1| { - let task1 = Cell(task1); + let task1 = Cell::new(task1); do Local::borrow:: |sched| { sched.enqueue_task(task1.take()); } @@ -516,7 +516,7 @@ fn test_block_task() { let sched = Local::take::(); assert!(sched.in_task_context()); do sched.deschedule_running_task_and_then() |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { assert!(!sched.in_task_context()); sched.enqueue_task(task.take()); @@ -539,7 +539,7 @@ fn test_io_callback() { let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { let mut sched = Local::take::(); - let task = Cell(task); + let task = Cell::new(task); do sched.event_loop.callback_ms(10) { rtdebug!("in callback"); let mut sched = Local::take::(); diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index c60ae2bfeff..453eab09730 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -25,7 +25,7 @@ pub fn run_in_newsched_task(f: ~fn()) { use unstable::run_in_bare_thread; use rt::uv::uvio::UvEventLoop; - let f = Cell(f); + let f = Cell::new(f); do run_in_bare_thread { let mut sched = ~UvEventLoop::new_scheduler(); @@ -46,7 +46,7 @@ pub fn spawntask(f: ~fn()) { ~Task::without_unwinding(), f); do sched.switch_running_tasks_and_then(task) |task| { - let task = Cell(task); + let task = Cell::new(task); let sched = Local::take::(); sched.schedule_new_task(task.take()); } @@ -61,7 +61,7 @@ pub fn spawntask_immediately(f: ~fn()) { ~Task::without_unwinding(), f); do sched.switch_running_tasks_and_then(task) |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { sched.enqueue_task(task.take()); } @@ -96,7 +96,7 @@ pub fn spawntask_random(f: ~fn()) { if run_now { do sched.switch_running_tasks_and_then(task) |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |sched| { sched.enqueue_task(task.take()); } @@ -120,10 +120,10 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> { let failed_ptr: *mut bool = &mut failed; // Switch to the scheduler - let f = Cell(Cell(f)); + let f = Cell::new(Cell::new(f)); let sched = Local::take::(); do sched.deschedule_running_task_and_then() |old_task| { - let old_task = Cell(old_task); + let old_task = Cell::new(old_task); let f = f.take(); let mut sched = Local::take::(); let new_task = ~do Coroutine::new(&mut sched.stack_pool) { @@ -134,7 +134,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> { unsafe { *failed_ptr = task::failing(); } let sched = Local::take::(); do sched.switch_running_tasks_and_then(old_task.take()) |new_task| { - let new_task = Cell(new_task); + let new_task = Cell::new(new_task); do Local::borrow:: |sched| { sched.enqueue_task(new_task.take()); } @@ -153,7 +153,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread { use rt::sched::*; use rt::uv::uvio::UvEventLoop; - let f = Cell(f); + let f = Cell::new(f); let thread = do Thread::start { let mut sched = ~UvEventLoop::new_scheduler(); let task = ~Coroutine::with_task(&mut sched.stack_pool, diff --git a/src/libstd/rt/tube.rs b/src/libstd/rt/tube.rs index b2f475a6966..03e11dfad1d 100644 --- a/src/libstd/rt/tube.rs +++ b/src/libstd/rt/tube.rs @@ -105,7 +105,7 @@ fn simple_test() { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone_cell = Cell(tube_clone); + let tube_clone_cell = Cell::new(tube_clone); let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { let mut tube_clone = tube_clone_cell.take(); @@ -123,7 +123,7 @@ fn blocking_test() { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone = Cell(Cell(Cell(tube_clone))); + let tube_clone = Cell::new(Cell::new(Cell::new(tube_clone))); let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { let tube_clone = tube_clone.take(); @@ -151,7 +151,7 @@ fn many_blocking_test() { do run_in_newsched_task { let mut tube: Tube = Tube::new(); let tube_clone = tube.clone(); - let tube_clone = Cell(tube_clone); + let tube_clone = Cell::new(tube_clone); let sched = Local::take::(); do sched.deschedule_running_task_and_then |task| { callback_send(tube_clone.take(), 0); @@ -159,7 +159,7 @@ fn many_blocking_test() { fn callback_send(tube: Tube, i: int) { if i == 100 { return; } - let tube = Cell(Cell(tube)); + let tube = Cell::new(Cell::new(tube)); do Local::borrow:: |sched| { let tube = tube.take(); do sched.event_loop.callback { diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 563d7fd1e81..4571747cebf 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -374,7 +374,7 @@ fn listen() { let client_tcp_watcher = TcpWatcher::new(&mut loop_); let mut client_tcp_watcher = client_tcp_watcher.as_stream(); server_stream_watcher.accept(client_tcp_watcher); - let count_cell = Cell(0); + let count_cell = Cell::new(0); let server_stream_watcher = server_stream_watcher; rtdebug!("starting read"); let alloc: AllocCallback = |size| { @@ -414,11 +414,11 @@ fn listen() { let mut stream_watcher = stream_watcher; let msg = ~[0, 1, 2, 3, 4, 5, 6 ,7 ,8, 9]; let buf = slice_to_uv_buf(msg); - let msg_cell = Cell(msg); + let msg_cell = Cell::new(msg); do stream_watcher.write(buf) |stream_watcher, status| { rtdebug!("writing"); assert!(status.is_none()); - let msg_cell = Cell(msg_cell.take()); + let msg_cell = Cell::new(msg_cell.take()); stream_watcher.close(||ignore(msg_cell.take())); } } diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 1d4f65f1517..964ee460c1d 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -11,7 +11,7 @@ use option::*; use result::*; use ops::Drop; -use cell::{Cell, empty_cell}; +use cell::Cell; use cast::transmute; use clone::Clone; use rt::io::IoError; @@ -115,7 +115,7 @@ impl IoFactory for UvIoFactory { fn tcp_connect(&mut self, addr: IpAddr) -> Result<~RtioTcpStreamObject, IoError> { // Create a cell in the task to hold the result. We will fill // the cell before resuming the task. - let result_cell = empty_cell(); + let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); @@ -129,7 +129,7 @@ fn tcp_connect(&mut self, addr: IpAddr) -> Result<~RtioTcpStreamObject, IoError> assert!(!scheduler.in_task_context()); } let mut tcp_watcher = TcpWatcher::new(self.uv_loop()); - let task_cell = Cell(task); + let task_cell = Cell::new(task); // Wait for a connection do tcp_watcher.connect(addr) |stream_watcher, status| { @@ -146,7 +146,7 @@ fn tcp_connect(&mut self, addr: IpAddr) -> Result<~RtioTcpStreamObject, IoError> scheduler.resume_task_immediately(task_cell.take()); } else { rtdebug!("status is some"); - let task_cell = Cell(task_cell.take()); + let task_cell = Cell::new(task_cell.take()); do stream_watcher.close { let res = Err(uv_error_to_io_error(status.get())); unsafe { (*result_cell_ptr).put_back(res); } @@ -168,7 +168,7 @@ fn tcp_bind(&mut self, addr: IpAddr) -> Result<~RtioTcpListenerObject, IoError> Err(uverr) => { let scheduler = Local::take::(); do scheduler.deschedule_running_task_and_then |task| { - let task_cell = Cell(task); + let task_cell = Cell::new(task); do watcher.as_stream().close { let scheduler = Local::take::(); scheduler.resume_task_immediately(task_cell.take()); @@ -204,7 +204,7 @@ fn finalize(&self) { let watcher = self.watcher(); let scheduler = Local::take::(); do scheduler.deschedule_running_task_and_then |task| { - let task_cell = Cell(task); + let task_cell = Cell::new(task); do watcher.as_stream().close { let scheduler = Local::take::(); scheduler.resume_task_immediately(task_cell.take()); @@ -225,9 +225,9 @@ fn accept(&mut self) -> Result<~RtioTcpStreamObject, IoError> { self.listening = true; let server_tcp_watcher = self.watcher(); - let incoming_streams_cell = Cell(self.incoming_streams.clone()); + let incoming_streams_cell = Cell::new(self.incoming_streams.clone()); - let incoming_streams_cell = Cell(incoming_streams_cell.take()); + let incoming_streams_cell = Cell::new(incoming_streams_cell.take()); let mut server_tcp_watcher = server_tcp_watcher; do server_tcp_watcher.listen |server_stream_watcher, status| { let maybe_stream = if status.is_none() { @@ -266,7 +266,7 @@ fn finalize(&self) { let watcher = self.watcher(); let scheduler = Local::take::(); do scheduler.deschedule_running_task_and_then |task| { - let task_cell = Cell(task); + let task_cell = Cell::new(task); do watcher.close { let scheduler = Local::take::(); scheduler.resume_task_immediately(task_cell.take()); @@ -277,7 +277,7 @@ fn finalize(&self) { impl RtioTcpStream for UvTcpStream { fn read(&mut self, buf: &mut [u8]) -> Result { - let result_cell = empty_cell(); + let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); @@ -290,7 +290,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result { assert!(!scheduler.in_task_context()); } let mut watcher = watcher; - let task_cell = Cell(task); + let task_cell = Cell::new(task); // XXX: We shouldn't reallocate these callbacks every // call to read let alloc: AllocCallback = |_| unsafe { @@ -324,7 +324,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result { } fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { - let result_cell = empty_cell(); + let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); assert!(scheduler.in_task_context()); @@ -332,7 +332,7 @@ fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { let buf_ptr: *&[u8] = &buf; do scheduler.deschedule_running_task_and_then |task| { let mut watcher = watcher; - let task_cell = Cell(task); + let task_cell = Cell::new(task); let buf = unsafe { slice_to_uv_buf(*buf_ptr) }; do watcher.write(buf) |_watcher, status| { let result = if status.is_none() { @@ -425,7 +425,7 @@ fn test_read_and_block() { // will trigger a read callback while we are // not ready for it do scheduler.deschedule_running_task_and_then |task| { - let task = Cell(task); + let task = Cell::new(task); do Local::borrow:: |scheduler| { scheduler.enqueue_task(task.take()); } diff --git a/src/libstd/rt/uvio.rs b/src/libstd/rt/uvio.rs index c7467364b4d..070ccf7fb44 100644 --- a/src/libstd/rt/uvio.rs +++ b/src/libstd/rt/uvio.rs @@ -16,7 +16,7 @@ use super::rtio::*; use ops::Drop; use old_iter::CopyableIter; -use cell::{Cell, empty_cell}; +use cell::Cell; use cast::transmute; use super::sched::{Scheduler, local_sched}; @@ -103,7 +103,7 @@ impl IoFactory for UvIoFactory { fn connect(&mut self, addr: IpAddr) -> Option<~StreamObject> { // Create a cell in the task to hold the result. We will fill // the cell before resuming the task. - let result_cell = empty_cell(); + let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = local_sched::take(); @@ -117,7 +117,7 @@ fn connect(&mut self, addr: IpAddr) -> Option<~StreamObject> { assert!(!scheduler.in_task_context()); } let mut tcp_watcher = TcpWatcher::new(self.uv_loop()); - let task_cell = Cell(task); + let task_cell = Cell::new(task); // Wait for a connection do tcp_watcher.connect(addr) |stream_watcher, status| { @@ -175,7 +175,7 @@ impl TcpListener for UvTcpListener { fn listen(&mut self) -> Option<~StreamObject> { rtdebug!("entering listen"); - let result_cell = empty_cell(); + let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let server_tcp_watcher = self.watcher(); @@ -184,7 +184,7 @@ fn listen(&mut self) -> Option<~StreamObject> { assert!(scheduler.in_task_context()); do scheduler.deschedule_running_task_and_then |task| { - let task_cell = Cell(task); + let task_cell = Cell::new(task); let mut server_tcp_watcher = server_tcp_watcher; do server_tcp_watcher.listen |server_stream_watcher, status| { let maybe_stream = if status.is_none() { @@ -239,7 +239,7 @@ fn finalize(&self) { impl Stream for UvStream { fn read(&mut self, buf: &mut [u8]) -> Result { - let result_cell = empty_cell(); + let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = local_sched::take(); @@ -252,7 +252,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result { assert!(!scheduler.in_task_context()); } let mut watcher = watcher; - let task_cell = Cell(task); + let task_cell = Cell::new(task); // XXX: We shouldn't reallocate these callbacks every // call to read let alloc: AllocCallback = |_| unsafe { @@ -286,7 +286,7 @@ fn read(&mut self, buf: &mut [u8]) -> Result { } fn write(&mut self, buf: &[u8]) -> Result<(), ()> { - let result_cell = empty_cell(); + let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = local_sched::take(); assert!(scheduler.in_task_context()); @@ -294,7 +294,7 @@ fn write(&mut self, buf: &[u8]) -> Result<(), ()> { let buf_ptr: *&[u8] = &buf; do scheduler.deschedule_running_task_and_then |task| { let mut watcher = watcher; - let task_cell = Cell(task); + let task_cell = Cell::new(task); let buf = unsafe { &*buf_ptr }; // XXX: OMGCOPIES let buf = buf.to_vec(); @@ -390,7 +390,7 @@ fn test_read_and_block() { // will trigger a read callback while we are // not ready for it do scheduler.deschedule_running_task_and_then |task| { - let task = Cell(task); + let task = Cell::new(task); do local_sched::borrow |scheduler| { scheduler.task_queue.push_back(task.take()); } diff --git a/src/libstd/rt/work_queue.rs b/src/libstd/rt/work_queue.rs index 58d36113f0e..cfffc55a58c 100644 --- a/src/libstd/rt/work_queue.rs +++ b/src/libstd/rt/work_queue.rs @@ -30,7 +30,7 @@ pub fn new() -> WorkQueue { pub fn push(&mut self, value: T) { unsafe { - let value = Cell(value); + let value = Cell::new(value); self.queue.with(|q| q.unshift(value.take()) ); } } diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 7c9639bb8f3..223afbce091 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -308,7 +308,7 @@ pub fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) { f } }; - let prev_gen_body = Cell(prev_gen_body); + let prev_gen_body = Cell::new(prev_gen_body); let next_gen_body = { let f: ~fn(~fn()) -> ~fn() = |body| { let prev_gen_body = prev_gen_body.take(); @@ -354,7 +354,7 @@ pub fn spawn(&mut self, f: ~fn()) { /// Runs a task, while transfering ownership of one argument to the child. pub fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { - let arg = Cell(arg); + let arg = Cell::new(arg); do self.spawn { f(arg.take()); } @@ -791,9 +791,9 @@ struct Wrapper { fn test_add_wrapper() { let (po, ch) = stream::<()>(); let mut b0 = task(); - let ch = Cell(ch); + let ch = Cell::new(ch); do b0.add_wrapper |body| { - let ch = Cell(ch.take()); + let ch = Cell::new(ch.take()); let result: ~fn() = || { let ch = ch.take(); body(); @@ -890,10 +890,10 @@ fn test_spawn_sched_childs_on_default_sched() { // Assuming tests run on the default scheduler let default_id = unsafe { rt::rust_get_sched_id() }; - let ch = Cell(ch); + let ch = Cell::new(ch); do spawn_sched(SingleThreaded) { let parent_sched_id = unsafe { rt::rust_get_sched_id() }; - let ch = Cell(ch.take()); + let ch = Cell::new(ch.take()); do spawn { let ch = ch.take(); let child_sched_id = unsafe { rt::rust_get_sched_id() }; diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 35cf6de3a15..87e9296657f 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -594,7 +594,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { gen_child_taskgroup(opts.linked, opts.supervised); unsafe { - let child_data = Cell((child_tg, ancestors, f)); + let child_data = Cell::new((child_tg, ancestors, f)); // Being killed with the unsafe task/closure pointers would leak them. do unkillable { // Agh. Get move-mode items into the closure. FIXME (#2829) @@ -636,7 +636,7 @@ fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc, notify_chan: Option>, f: ~fn()) -> ~fn() { - let child_data = Cell((child_arc, ancestors)); + let child_data = Cell::new((child_arc, ancestors)); let result: ~fn() = || { // Agh. Get move-mode items into the closure. FIXME (#2829) let mut (child_arc, ancestors) = child_data.take(); diff --git a/src/libstd/unstable/weak_task.rs b/src/libstd/unstable/weak_task.rs index d5c5230cef8..7819fe00597 100644 --- a/src/libstd/unstable/weak_task.rs +++ b/src/libstd/unstable/weak_task.rs @@ -39,7 +39,7 @@ pub unsafe fn weaken_task(f: &fn(Port)) { let service = global_data_clone_create(global_data_key, create_global_service); let (shutdown_port, shutdown_chan) = stream::(); - let shutdown_port = Cell(shutdown_port); + let shutdown_port = Cell::new(shutdown_port); let task = get_task_id(); // Expect the weak task service to be alive assert!(service.try_send(RegisterWeakTask(task, shutdown_chan))); @@ -68,7 +68,7 @@ fn create_global_service() -> ~WeakTaskService { debug!("creating global weak task service"); let (port, chan) = stream::(); - let port = Cell(port); + let port = Cell::new(port); let chan = SharedChan::new(chan); let chan_clone = chan.clone(); @@ -76,7 +76,7 @@ fn create_global_service() -> ~WeakTaskService { task.unlinked(); do task.spawn { debug!("running global weak task service"); - let port = Cell(port.take()); + let port = Cell::new(port.take()); do (|| { let port = port.take(); // The weak task service is itself a weak task @@ -192,7 +192,7 @@ fn test_select_stream_and_oneshot() { use either::{Left, Right}; let (port, chan) = stream(); - let port = Cell(port); + let port = Cell::new(port); let (waitport, waitchan) = stream(); do spawn { unsafe { diff --git a/src/libstd/util.rs b/src/libstd/util.rs index e8e68ddd632..376ead608bc 100644 --- a/src/libstd/util.rs +++ b/src/libstd/util.rs @@ -79,13 +79,15 @@ pub struct NonCopyable { priv i: (), } +impl NonCopyable { + /// Creates a dummy non-copyable structure and returns it for use. + pub fn new() -> NonCopyable { NonCopyable { i: () } } +} + impl Drop for NonCopyable { fn finalize(&self) { } } -/// Creates a dummy non-copyable structure and returns it for use. -pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } } - /// A type with no inhabitants pub enum Void { } @@ -152,7 +154,7 @@ pub fn test_swap() { } #[test] pub fn test_replace() { - let mut x = Some(NonCopyable()); + let mut x = Some(NonCopyable::new()); let y = replace(&mut x, None); assert!(x.is_none()); assert!(y.is_some()); diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 3d3a6a68beb..c0e147b2db5 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -84,7 +84,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_chan, num_port) = init(); - let mut num_chan = Cell(num_chan); + let mut num_chan = Cell::new(num_chan); let start = time::precise_time_s(); @@ -94,8 +94,8 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan.take()); - let num_port = Cell(num_port); + let num_chan2 = Cell::new(num_chan.take()); + let num_port = Cell::new(num_port); let new_future = do future::spawn() { let num_chan = num_chan2.take(); let num_port1 = num_port.take(); diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 2cc9e8882c7..d7b05ea6350 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -74,7 +74,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_port, num_chan) = ring::init(); - let mut num_chan = Cell(num_chan); + let mut num_chan = Cell::new(num_chan); let start = time::precise_time_s(); @@ -84,8 +84,8 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (num_port, new_chan) = ring::init(); - let num_chan2 = Cell(num_chan.take()); - let num_port = Cell(num_port); + let num_chan2 = Cell::new(num_chan.take()); + let num_port = Cell::new(num_port); let new_future = do future::spawn || { let num_chan = num_chan2.take(); let num_port1 = num_port.take(); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 46ca59f2d31..9aaf565f368 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -80,7 +80,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_chan, num_port) = init(); - let mut num_chan = Cell(num_chan); + let mut num_chan = Cell::new(num_chan); let start = time::precise_time_s(); @@ -90,8 +90,8 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan.take()); - let num_port = Cell(num_port); + let num_chan2 = Cell::new(num_chan.take()); + let num_port = Cell::new(num_port); let new_future = do future::spawn { let num_chan = num_chan2.take(); let num_port1 = num_port.take(); diff --git a/src/test/bench/pingpong.rs b/src/test/bench/pingpong.rs index 9a8c0656e84..63e4174a0fc 100644 --- a/src/test/bench/pingpong.rs +++ b/src/test/bench/pingpong.rs @@ -91,7 +91,7 @@ pub fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()); } @@ -112,7 +112,7 @@ pub fn spawn_service_recv( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()) } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index dcde474ace3..53b47b12144 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -160,7 +160,7 @@ fn rendezvous(nn: uint, set: ~[color]) { let to_rendezvous = to_rendezvous.clone(); let to_rendezvous_log = to_rendezvous_log.clone(); let (from_rendezvous, to_creature) = stream(); - let from_rendezvous = Cell(from_rendezvous); + let from_rendezvous = Cell::new(from_rendezvous); do task::spawn || { creature(ii, col, from_rendezvous.take(), to_rendezvous.clone(), to_rendezvous_log.clone()); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 78923c8cc96..e5732b7d580 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -27,7 +27,7 @@ fn child_generation(gens_left: uint, c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - let c = Cell(c); + let c = Cell::new(c); do task::spawn_supervised { let c = c.take(); if gens_left & 1 == 1 { diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 9847efd2dd5..5e18a40a99c 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -29,7 +29,7 @@ fn foo(x: Port<()>) -> foo { } } - let x = Cell(foo(Port(@()))); + let x = Cell::new(foo(Port(@()))); do task::spawn { let y = x.take(); //~ ERROR value has non-owned type diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index d51470cf9bd..4ef83e405be 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -318,8 +318,8 @@ pub fn main() { // Commented out because of option::get error let (client_, server_) = pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); + let client_ = Cell::new(client_); + let server_ = Cell::new(server_); task::spawn {|client_| let client__ = client_.take(); diff --git a/src/test/run-pass/pipe-detect-term.rs b/src/test/run-pass/pipe-detect-term.rs index a347fde422c..abee0f36330 100644 --- a/src/test/run-pass/pipe-detect-term.rs +++ b/src/test/run-pass/pipe-detect-term.rs @@ -32,7 +32,7 @@ pub fn main() { let iotask = &uv::global_loop::get(); let (port, chan) = oneshot::init(); - let port = Cell(port); + let port = Cell::new(port); do spawn { match try_recv(port.take()) { Some(*) => { fail!() } diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 8a0589f55ea..ab17607c4d7 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -113,8 +113,8 @@ pub fn server(chan: ::pingpong::server::ping) { pub fn main() { let (server_, client_) = ::pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); + let client_ = Cell::new(client_); + let server_ = Cell::new(server_); do task::spawn { let client__ = client_.take(); test::client(client__); diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index c993dafa489..a4268f9456b 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -51,8 +51,8 @@ pub fn server(chan: ::pingpong::server::ping) { pub fn main() { let (server_, client_) = pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); + let client_ = Cell::new(client_); + let server_ = Cell::new(server_); do task::spawn { let client__ = client_.take(); diff --git a/src/test/run-pass/pipe-select.rs b/src/test/run-pass/pipe-select.rs index 8e28d3d12d9..0a860d0a1e2 100644 --- a/src/test/run-pass/pipe-select.rs +++ b/src/test/run-pass/pipe-select.rs @@ -43,7 +43,7 @@ pub fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()); } diff --git a/src/test/run-pass/pipe-sleep.rs b/src/test/run-pass/pipe-sleep.rs index a6a81229e28..dc88f36ba11 100644 --- a/src/test/run-pass/pipe-sleep.rs +++ b/src/test/run-pass/pipe-sleep.rs @@ -42,7 +42,7 @@ pub fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = Cell(server); + let server = Cell::new(server); do task::spawn { service(server.take()); } diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index d9f491297ea..2399aa5b035 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -23,7 +23,7 @@ fn test05() { error!(*three + n); // will copy x into the closure assert_eq!(*three, 3); }; - let fn_to_send = Cell(fn_to_send); + let fn_to_send = Cell::new(fn_to_send); task::spawn(|| { test05_start(fn_to_send.take()); }); diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 6d35a9228b0..2025a5c304c 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -55,7 +55,7 @@ fn wrapper(c: Chan, f: &fn()) { *b = true; } let (p, c) = stream(); - let c = Cell(c); + let c = Cell::new(c); do task::spawn_unlinked { let ccc = c.take(); wrapper(ccc, f)