From b0522a497ccfcc7b124d77121d8f076af7f09b71 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 22 Apr 2013 14:27:30 -0700 Subject: librustc: Remove `ptr::addr_of`. --- src/libstd/dbg.rs | 16 +++------ src/libstd/net_ip.rs | 12 ++++--- src/libstd/net_tcp.rs | 81 ++++++++++++++++++++++---------------------- src/libstd/priority_queue.rs | 4 +-- src/libstd/sync.rs | 4 +-- src/libstd/timer.rs | 2 +- src/libstd/uv_global_loop.rs | 2 +- src/libstd/uv_iotask.rs | 11 +++--- src/libstd/uv_ll.rs | 74 +++++++++++++++++++--------------------- 9 files changed, 98 insertions(+), 108 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs index 0b297e9e6ba..34dd6390ecc 100644 --- a/src/libstd/dbg.rs +++ b/src/libstd/dbg.rs @@ -11,7 +11,6 @@ //! Unsafe debugging functions for inspecting values. use core::cast::transmute; -use core::ptr; use core::sys; pub mod rustrt { @@ -37,36 +36,31 @@ pub fn debug_tydesc() { pub fn debug_opaque(x: T) { unsafe { - rustrt::debug_opaque(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_opaque(sys::get_type_desc::(), transmute(&x)); } } pub fn debug_box(x: @T) { unsafe { - rustrt::debug_box(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_box(sys::get_type_desc::(), transmute(&x)); } } pub fn debug_tag(x: T) { unsafe { - rustrt::debug_tag(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_tag(sys::get_type_desc::(), transmute(&x)); } } pub fn debug_fn(x: T) { unsafe { - rustrt::debug_fn(sys::get_type_desc::(), - ptr::addr_of(&x) as *()); + rustrt::debug_fn(sys::get_type_desc::(), transmute(&x)); } } pub unsafe fn ptr_cast(x: @T) -> @U { transmute( - rustrt::debug_ptrcast(sys::get_type_desc::(), - transmute(x))) + rustrt::debug_ptrcast(sys::get_type_desc::(), transmute(x))) } /// Triggers a debugger breakpoint diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index aa1903e4a21..bf1b9dc0cda 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -110,18 +110,18 @@ enum IpGetAddrErr { * object in the case of failure */ pub fn get_addr(node: &str, iotask: &iotask) - -> result::Result<~[IpAddr], IpGetAddrErr> { + -> result::Result<~[IpAddr], IpGetAddrErr> { let (output_po, output_ch) = stream(); let mut output_ch = Some(SharedChan::new(output_ch)); do str::as_buf(node) |node_ptr, len| { let output_ch = output_ch.swap_unwrap(); debug!("slice len %?", len); let handle = create_uv_getaddrinfo_t(); - let handle_ptr = ptr::addr_of(&handle); + let handle_ptr: *uv_getaddrinfo_t = &handle; let handle_data = GetAddrData { output_ch: output_ch.clone() }; - let handle_data_ptr = ptr::addr_of(&handle_data); + let handle_data_ptr: *GetAddrData = &handle_data; do interact(iotask) |loop_ptr| { unsafe { let result = uv_getaddrinfo( @@ -189,7 +189,8 @@ pub mod v4 { impl AsUnsafeU32 for Ipv4Rep { // this is pretty dastardly, i know unsafe fn as_u32(&self) -> u32 { - *((ptr::addr_of(self)) as *u32) + let this: &mut u32 = transmute(self); + *this } } pub fn parse_to_ipv4_rep(ip: &str) -> result::Result { @@ -297,7 +298,8 @@ struct GetAddrData { output_ch: SharedChan> } -extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, +extern fn get_addr_cb(handle: *uv_getaddrinfo_t, + status: libc::c_int, res: *addrinfo) { unsafe { debug!("in get_addr_cb"); diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index ee109047cb1..764152d6812 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -156,7 +156,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, result_ch: result_ch, closed_signal_ch: closed_signal_ch }; - let conn_data_ptr = ptr::addr_of(&conn_data); + let conn_data_ptr: *ConnectReqData = &conn_data; let (reader_po, reader_ch) = stream::>(); let reader_ch = SharedChan::new(reader_ch); let stream_handle_ptr = malloc_uv_tcp_t(); @@ -173,7 +173,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, }, iotask: iotask.clone() }; - let socket_data_ptr = ptr::addr_of(&(*socket_data)); + let socket_data_ptr: *TcpSocketData = &*socket_data; // get an unsafe representation of our stream_handle_ptr that // we can send into the interact cb to be handled in libuv.. debug!("stream_handle_ptr outside interact %?", @@ -187,8 +187,8 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, 0i32 => { debug!("tcp_init successful"); debug!("dealing w/ ipv4 connection.."); - let connect_req_ptr = - ptr::addr_of(&((*socket_data_ptr).connect_req)); + let connect_req_ptr: *uv::ll::uv_connect_t = + &(*socket_data_ptr).connect_req; let addr_str = ip::format_addr(&input_ip); let connect_result = match input_ip { ip::Ipv4(ref addr) => { @@ -205,7 +205,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, uv::ll::tcp_connect( connect_req_ptr, stream_handle_ptr, - ptr::addr_of(&in_addr), + &in_addr, tcp_connect_on_connect_cb) } ip::Ipv6(ref addr) => { @@ -215,7 +215,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, uv::ll::tcp_connect6( connect_req_ptr, stream_handle_ptr, - ptr::addr_of(&in_addr), + &in_addr, tcp_connect_on_connect_cb) } }; @@ -303,9 +303,8 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, * `TcpErrData` value as the `Err` variant */ pub fn write(sock: &TcpSocket, raw_write_data: ~[u8]) - -> result::Result<(), TcpErrData> -{ - let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data))); + -> result::Result<(), TcpErrData> { + let socket_data_ptr: *TcpSocketData = &*sock.socket_data; write_common_impl(socket_data_ptr, raw_write_data) } @@ -343,7 +342,7 @@ pub fn write(sock: &TcpSocket, raw_write_data: ~[u8]) pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8]) -> future::Future> { - let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data))); + let socket_data_ptr: *TcpSocketData = &*sock.socket_data; do future_spawn { let data_copy = copy(raw_write_data); write_common_impl(socket_data_ptr, data_copy) @@ -366,9 +365,10 @@ pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8]) * `TcpErrData` record */ pub fn read_start(sock: &TcpSocket) - -> result::Result<@Port< - result::Result<~[u8], TcpErrData>>, TcpErrData> { - let socket_data = ptr::addr_of(&(*(sock.socket_data))); + -> result::Result<@Port>, + TcpErrData> { + let socket_data: *TcpSocketData = &*sock.socket_data; read_start_common_impl(socket_data) } @@ -380,7 +380,7 @@ pub fn read_start(sock: &TcpSocket) * * `sock` - a `net::tcp::TcpSocket` that you wish to stop reading on */ pub fn read_stop(sock: &TcpSocket) -> result::Result<(), TcpErrData> { - let socket_data = ptr::addr_of(&(*sock.socket_data)); + let socket_data: *TcpSocketData = &*sock.socket_data; read_stop_common_impl(socket_data) } @@ -400,8 +400,8 @@ pub fn read_stop(sock: &TcpSocket) -> result::Result<(), TcpErrData> { * read attempt. Pass `0u` to wait indefinitely */ pub fn read(sock: &TcpSocket, timeout_msecs: uint) - -> result::Result<~[u8],TcpErrData> { - let socket_data = ptr::addr_of(&(*(sock.socket_data))); + -> result::Result<~[u8],TcpErrData> { + let socket_data: *TcpSocketData = &*sock.socket_data; read_common_impl(socket_data, timeout_msecs) } @@ -435,8 +435,8 @@ pub fn read(sock: &TcpSocket, timeout_msecs: uint) * read attempt. Pass `0u` to wait indefinitely */ fn read_future(sock: &TcpSocket, timeout_msecs: uint) - -> future::Future> { - let socket_data = ptr::addr_of(&(*(sock.socket_data))); + -> future::Future> { + let socket_data: *TcpSocketData = &*sock.socket_data; do future_spawn { read_common_impl(socket_data, timeout_msecs) } @@ -534,8 +534,8 @@ pub fn accept(new_conn: TcpNewConnection) ipv6: (*server_data_ptr).ipv6, iotask : iotask.clone() }; - let client_socket_data_ptr = ptr::addr_of( - &(*client_socket_data)); + let client_socket_data_ptr: *TcpSocketData = + &*client_socket_data; let client_stream_handle_ptr = (*client_socket_data_ptr).stream_handle_ptr; @@ -661,7 +661,7 @@ fn listen_common(host_ip: ip::IpAddr, let (kill_po, kill_ch) = stream::>(); let kill_ch = SharedChan::new(kill_ch); let server_stream = uv::ll::tcp_t(); - let server_stream_ptr = ptr::addr_of(&server_stream); + let server_stream_ptr: *uv::ll::uv_tcp_t = &server_stream; let server_data: TcpListenFcData = TcpListenFcData { server_stream_ptr: server_stream_ptr, stream_closed_ch: stream_closed_ch, @@ -674,7 +674,7 @@ fn listen_common(host_ip: ip::IpAddr, }, mut active: true }; - let server_data_ptr = ptr::addr_of(&server_data); + let server_data_ptr: *TcpListenFcData = &server_data; let (setup_po, setup_ch) = stream(); @@ -699,16 +699,14 @@ fn listen_common(host_ip: ip::IpAddr, let in_addr = uv::ll::ip4_addr( addr_str, port as int); - uv::ll::tcp_bind(server_stream_ptr, - ptr::addr_of(&in_addr)) + uv::ll::tcp_bind(server_stream_ptr, &in_addr) } ip::Ipv6(ref addr) => { debug!("addr: %?", addr); let in_addr = uv::ll::ip6_addr( addr_str, port as int); - uv::ll::tcp_bind6(server_stream_ptr, - ptr::addr_of(&in_addr)) + uv::ll::tcp_bind6(server_stream_ptr, &in_addr) } }; match bind_result { @@ -856,12 +854,12 @@ pub impl TcpSocket { if self.socket_data.ipv6 { let addr = uv::ll::ip6_addr("", 0); uv::ll::tcp_getpeername6(self.socket_data.stream_handle_ptr, - ptr::addr_of(&addr)); + &addr); ip::Ipv6(addr) } else { let addr = uv::ll::ip4_addr("", 0); uv::ll::tcp_getpeername(self.socket_data.stream_handle_ptr, - ptr::addr_of(&addr)); + &addr); ip::Ipv4(addr) } } @@ -973,13 +971,12 @@ impl io::Reader for TcpSocketBuf { impl io::Writer for TcpSocketBuf { pub fn write(&self, data: &const [u8]) { unsafe { - let socket_data_ptr = - ptr::addr_of(&(*((*(self.data)).sock).socket_data)); + let socket_data_ptr: *TcpSocketData = + &(*((*(self.data)).sock).socket_data); let w_result = write_common_impl(socket_data_ptr, - vec::slice(data, - 0, - vec::len(data) - ).to_vec()); + vec::slice(data, + 0, + data.len()).to_vec()); if w_result.is_err() { let err_data = w_result.get_err(); debug!( @@ -1012,7 +1009,7 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) { let close_data = TcpSocketCloseData { closed_ch: closed_ch }; - let close_data_ptr = ptr::addr_of(&close_data); + let close_data_ptr: *TcpSocketCloseData = &close_data; let stream_handle_ptr = (*socket_data).stream_handle_ptr; do iotask::interact(&(*socket_data).iotask) |loop_ptr| { unsafe { @@ -1150,19 +1147,21 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData, raw_write_data: ~[u8]) -> result::Result<(), TcpErrData> { unsafe { - let write_req_ptr = ptr::addr_of(&((*socket_data_ptr).write_req)); + let write_req_ptr: *uv::ll::uv_write_t = + &(*socket_data_ptr).write_req; let stream_handle_ptr = (*socket_data_ptr).stream_handle_ptr; - let write_buf_vec = ~[ uv::ll::buf_init( - vec::raw::to_ptr(raw_write_data), - vec::len(raw_write_data)) ]; - let write_buf_vec_ptr = ptr::addr_of(&write_buf_vec); + let write_buf_vec = ~[ + uv::ll::buf_init(vec::raw::to_ptr(raw_write_data), + raw_write_data.len()) + ]; + let write_buf_vec_ptr: *~[uv::ll::uv_buf_t] = &write_buf_vec; let (result_po, result_ch) = stream::(); let result_ch = SharedChan::new(result_ch); let write_data = WriteReqData { result_ch: result_ch }; - let write_data_ptr = ptr::addr_of(&write_data); + let write_data_ptr: *WriteReqData = &write_data; do iotask::interact(&(*socket_data_ptr).iotask) |loop_ptr| { unsafe { debug!("in interact cb for tcp::write %?", diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 60f25c2a270..6f408823410 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -151,7 +151,7 @@ pub impl PriorityQueue { priv fn siftup(&mut self, start: uint, mut pos: uint) { unsafe { - let new = *addr_of(&self.data[pos]); + let new = *ptr::to_unsafe_ptr(&self.data[pos]); while pos > start { let parent = (pos - 1) >> 1; @@ -171,7 +171,7 @@ pub impl PriorityQueue { priv fn siftdown_range(&mut self, mut pos: uint, end: uint) { unsafe { let start = pos; - let new = *addr_of(&self.data[pos]); + let new = *ptr::to_unsafe_ptr(&self.data[pos]); let mut child = 2 * pos + 1; while child < end { diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 58e5352890f..21a6153380c 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -828,7 +828,7 @@ mod tests { let m = ~Mutex(); let m2 = m.clone(); let mut sharedstate = ~0; - let ptr = ptr::addr_of(&(*sharedstate)); + let ptr: *int = &*sharedstate; do task::spawn || { let sharedstate: &mut int = unsafe { cast::transmute(ptr) }; @@ -1106,7 +1106,7 @@ mod tests { let (p,c) = comm::stream(); let x2 = (*x).clone(); let mut sharedstate = ~0; - let ptr = ptr::addr_of(&(*sharedstate)); + let ptr: *int = &*sharedstate; do task::spawn || { let sharedstate: &mut int = unsafe { cast::transmute(ptr) }; diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 69e01d4e4db..b19b2f2889e 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -42,7 +42,7 @@ pub fn delayed_send(iotask: &IoTask, let (timer_done_po, timer_done_ch) = stream::<()>(); let timer_done_ch = SharedChan::new(timer_done_ch); let timer = uv::ll::timer_t(); - let timer_ptr = ptr::addr_of(&timer); + let timer_ptr: *uv::ll::uv_timer_t = &timer; do iotask::interact(iotask) |loop_ptr| { unsafe { let init_result = uv::ll::timer_init(loop_ptr, timer_ptr); diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 2ab5ce8698c..e49cee434f8 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -162,7 +162,7 @@ mod test { debug!("EXIT_CH_PTR newly created exit_ch_ptr: %?", exit_ch_ptr); let timer_handle = ll::timer_t(); - let timer_ptr = ptr::addr_of(&timer_handle); + let timer_ptr: *ll::uv_timer_t = &timer_handle; do iotask::interact(iotask) |loop_ptr| { unsafe { debug!(~"user code inside interact loop!!!"); diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 309ae32dc59..e19010e8552 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -17,10 +17,9 @@ use ll = uv_ll; +use core::comm::{stream, Port, Chan, SharedChan}; use core::libc::c_void; use core::libc; -use core::comm::{stream, Port, Chan, SharedChan}; -use core::ptr::addr_of; /// Used to abstract-away direct interaction with a libuv loop. pub struct IoTask { @@ -106,7 +105,7 @@ fn run_loop(iotask_ch: &Chan) { // set up the special async handle we'll use to allow multi-task // communication with this loop let async = ll::async_t(); - let async_handle = addr_of(&async); + let async_handle: *ll::uv_async_t = &async; // associate the async handle with the loop ll::async_init(loop_ptr, async_handle, wake_up_cb); @@ -118,11 +117,11 @@ fn run_loop(iotask_ch: &Chan) { async_handle: async_handle, msg_po: msg_po }; - ll::set_data_for_uv_handle(async_handle, addr_of(&data)); + ll::set_data_for_uv_handle(async_handle, &data); // Send out a handle through which folks can talk to us // while we dwell in the I/O loop - let iotask = IoTask{ + let iotask = IoTask { async_handle: async_handle, op_chan: SharedChan::new(msg_ch) }; @@ -223,7 +222,7 @@ struct AhData { #[cfg(test)] fn impl_uv_iotask_async(iotask: &IoTask) { let async_handle = ll::async_t(); - let ah_ptr = ptr::addr_of(&async_handle); + let ah_ptr: *ll::uv_async_t = &async_handle; let (exit_po, exit_ch) = stream::<()>(); let ah_data = AhData { iotask: iotask.clone(), diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index fb40596b888..8e5b3274bbb 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1021,19 +1021,17 @@ pub unsafe fn async_send(async_handle: *uv_async_t) { } pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t { let out_buf = uv_buf_t { base: ptr::null(), len: 0 as libc::size_t }; - let out_buf_ptr = ptr::addr_of(&out_buf); + let out_buf_ptr: *uv_buf_t = &out_buf; rustrt::rust_uv_buf_init(out_buf_ptr, input, len as size_t); return out_buf; } -pub unsafe fn ip4_addr(ip: &str, port: int) --> sockaddr_in { +pub unsafe fn ip4_addr(ip: &str, port: int) -> sockaddr_in { do str::as_c_str(ip) |ip_buf| { rustrt::rust_uv_ip4_addr(ip_buf as *u8, port as libc::c_int) } } -pub unsafe fn ip6_addr(ip: &str, port: int) --> sockaddr_in6 { +pub unsafe fn ip6_addr(ip: &str, port: int) -> sockaddr_in6 { do str::as_c_str(ip) |ip_buf| { rustrt::rust_uv_ip6_addr(ip_buf as *u8, port as libc::c_int) @@ -1183,7 +1181,7 @@ pub unsafe fn free_base_of_buf(buf: uv_buf_t) { pub unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(&err); + let err_ptr: *uv_err_t = &err; let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); return fmt!("LIBUV ERROR: name: %s msg: %s", @@ -1192,7 +1190,7 @@ pub unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str { pub unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(&err); + let err_ptr: *uv_err_t = &err; let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); uv_err_data { err_name: err_name, err_msg: err_msg } @@ -1347,9 +1345,9 @@ mod test { unsafe { let test_loop = loop_new(); let tcp_handle = tcp_t(); - let tcp_handle_ptr = ptr::addr_of(&tcp_handle); + let tcp_handle_ptr: *uv_tcp_t = &tcp_handle; let connect_handle = connect_t(); - let connect_req_ptr = ptr::addr_of(&connect_handle); + let connect_req_ptr: *uv_connect_t = &connect_handle; // this is the persistent payload of data that we // need to pass around to get this example to work. @@ -1365,43 +1363,42 @@ mod test { // this is the enclosing record, we'll pass a ptr to // this to C.. let write_handle = write_t(); - let write_handle_ptr = ptr::addr_of(&write_handle); + let write_handle_ptr: *uv_write_t = &write_handle; debug!("tcp req: tcp stream: %d write_handle: %d", tcp_handle_ptr as int, write_handle_ptr as int); let client_data = request_wrapper { write_req: write_handle_ptr, - req_buf: ptr::addr_of(&req_msg), + req_buf: &req_msg, read_chan: client_chan }; - let tcp_init_result = tcp_init( - test_loop as *libc::c_void, tcp_handle_ptr); - if (tcp_init_result == 0i32) { + let tcp_init_result = tcp_init(test_loop as *libc::c_void, + tcp_handle_ptr); + if (tcp_init_result == 0) { debug!(~"sucessful tcp_init_result"); debug!(~"building addr..."); let addr = ip4_addr(ip, port); // FIXME ref #2064 - let addr_ptr = ptr::addr_of(&addr); + let addr_ptr: *sockaddr_in = &addr; debug!("after build addr in rust. port: %u", - addr.sin_port as uint); + addr.sin_port as uint); // this should set up the connection request.. debug!("b4 call tcp_connect connect cb: %u ", - on_connect_cb as uint); - let tcp_connect_result = tcp_connect( - connect_req_ptr, tcp_handle_ptr, - addr_ptr, on_connect_cb); - if (tcp_connect_result == 0i32) { + on_connect_cb as uint); + let tcp_connect_result = tcp_connect(connect_req_ptr, + tcp_handle_ptr, + addr_ptr, + on_connect_cb); + if (tcp_connect_result == 0) { // not set the data on the connect_req // until its initialized - set_data_for_req( - connect_req_ptr as *libc::c_void, - ptr::addr_of(&client_data) as *libc::c_void); - set_data_for_uv_handle( - tcp_handle_ptr as *libc::c_void, - ptr::addr_of(&client_data) as *libc::c_void); + set_data_for_req(connect_req_ptr as *libc::c_void, + transmute(&client_data)); + set_data_for_uv_handle(tcp_handle_ptr as *libc::c_void, + transmute(&client_data)); debug!(~"before run tcp req loop"); run(test_loop); debug!(~"after run tcp req loop"); @@ -1607,37 +1604,37 @@ mod test { unsafe { let test_loop = loop_new(); let tcp_server = tcp_t(); - let tcp_server_ptr = ptr::addr_of(&tcp_server); + let tcp_server_ptr: *uv_tcp_t = &tcp_server; let tcp_client = tcp_t(); - let tcp_client_ptr = ptr::addr_of(&tcp_client); + let tcp_client_ptr: *uv_tcp_t = &tcp_client; let server_write_req = write_t(); - let server_write_req_ptr = ptr::addr_of(&server_write_req); + let server_write_req_ptr: *uv_write_t = &server_write_req; let resp_str_bytes = str::to_bytes(server_resp_msg); let resp_msg_ptr: *u8 = vec::raw::to_ptr(resp_str_bytes); debug!("resp_msg ptr: %u", resp_msg_ptr as uint); let resp_msg = ~[ - buf_init(resp_msg_ptr, vec::len(resp_str_bytes)) + buf_init(resp_msg_ptr, resp_str_bytes.len()) ]; let continue_async_handle = async_t(); - let continue_async_handle_ptr = - ptr::addr_of(&continue_async_handle); + let continue_async_handle_ptr: *uv_async_t = + &continue_async_handle; let async_data = async_handle_data { continue_chan: continue_chan }; - let async_data_ptr = ptr::addr_of(&async_data); + let async_data_ptr: *async_handle_data = &async_data; let server_data = tcp_server_data { client: tcp_client_ptr, server: tcp_server_ptr, server_kill_msg: kill_server_msg, - server_resp_buf: ptr::addr_of(&resp_msg), + server_resp_buf: &resp_msg, server_chan: server_chan, server_write_req: server_write_req_ptr }; - let server_data_ptr = ptr::addr_of(&server_data); + let server_data_ptr: *tcp_server_data = &server_data; set_data_for_uv_handle(tcp_server_ptr as *libc::c_void, server_data_ptr as *libc::c_void); @@ -1647,11 +1644,10 @@ mod test { if (tcp_init_result == 0i32) { let server_addr = ip4_addr(server_ip, server_port); // FIXME ref #2064 - let server_addr_ptr = ptr::addr_of(&server_addr); + let server_addr_ptr: *sockaddr_in = &server_addr; // uv_tcp_bind() - let bind_result = tcp_bind(tcp_server_ptr, - server_addr_ptr); + let bind_result = tcp_bind(tcp_server_ptr, server_addr_ptr); if (bind_result == 0i32) { debug!(~"successful uv_tcp_bind, listening"); -- cgit 1.4.1-3-g733a5 From 876483dcf4bdcd0001cc25812060bc04cf367f60 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 26 Apr 2013 14:04:39 -0700 Subject: test: Fix tests. --- src/libcore/cast.rs | 4 +-- src/libcore/option.rs | 4 +-- src/libcore/rt/thread.rs | 8 ++--- src/libcore/rt/uv/mod.rs | 16 +++++---- src/libcore/sys.rs | 2 +- src/librustc/middle/trans/foreign.rs | 20 +++++------ src/librustc/middle/typeck/check/mod.rs | 8 ++--- src/libstd/sync.rs | 44 ++++++++++++++---------- src/libstd/uv_ll.rs | 4 +-- src/libsyntax/ext/pipes/pipec.rs | 4 ++- src/llvm | 2 +- src/test/bench/graph500-bfs.rs | 8 ++--- src/test/bench/msgsend-pipes-shared.rs | 4 +-- src/test/bench/msgsend-pipes.rs | 4 +-- src/test/bench/shootout-k-nucleotide-pipes.rs | 8 ++--- src/test/bench/shootout-pfib.rs | 8 ++--- src/test/compile-fail/arg-style-mismatch.rs | 15 -------- src/test/compile-fail/liveness-move-from-args.rs | 22 ------------ src/test/compile-fail/mode-inference-fail.rs | 21 ----------- src/test/compile-fail/mutable-arguments.rs | 35 ------------------- src/test/run-pass/alt-pattern-drop.rs | 4 +-- src/test/run-pass/cci_iter_exe.rs | 2 +- src/test/run-pass/cci_nested_exe.rs | 16 ++++----- src/test/run-pass/class-implement-traits.rs | 1 - src/test/run-pass/enum-alignment.rs | 5 ++- src/test/run-pass/regions-mock-trans.rs | 2 +- src/test/run-pass/sendfn-spawn-with-fn-arg.rs | 5 ++- src/test/run-pass/static-method-test.rs | 8 ++--- src/test/run-pass/task-comm-0.rs | 6 ++-- src/test/run-pass/task-comm-13.rs | 4 +-- src/test/run-pass/task-comm-7.rs | 10 +++--- 31 files changed, 114 insertions(+), 190 deletions(-) delete mode 100644 src/test/compile-fail/arg-style-mismatch.rs delete mode 100644 src/test/compile-fail/liveness-move-from-args.rs delete mode 100644 src/test/compile-fail/mode-inference-fail.rs delete mode 100644 src/test/compile-fail/mutable-arguments.rs (limited to 'src/libstd') diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 0c960d4a308..6fb737d3770 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -178,8 +178,8 @@ mod tests { let box = @~"box box box"; // refcount 1 bump_box_refcount(box); // refcount 2 let ptr: *int = transmute(box); // refcount 2 - let _box1: @~str = reinterpret_cast(&ptr); - let _box2: @~str = reinterpret_cast(&ptr); + let _box1: @~str = ::cast::transmute_copy(&ptr); + let _box2: @~str = ::cast::transmute_copy(&ptr); assert!(*_box1 == ~"box box box"); assert!(*_box2 == ~"box box box"); // Will destroy _box1 and _box2. Without the bump, this would diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 0fae64c0930..17192b4257b 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -482,10 +482,10 @@ pub impl Option { fn test_unwrap_ptr() { unsafe { let x = ~0; - let addr_x: *int = transmute(&*x); + let addr_x: *int = ::cast::transmute(&*x); let opt = Some(x); let y = opt.unwrap(); - let addr_y: *int = transmute(&*y); + let addr_y: *int = ::cast::transmute(&*y); assert!(addr_x == addr_y); } } diff --git a/src/libcore/rt/thread.rs b/src/libcore/rt/thread.rs index 910e445f47b..0f1ae09bd94 100644 --- a/src/libcore/rt/thread.rs +++ b/src/libcore/rt/thread.rs @@ -21,10 +21,10 @@ pub struct Thread { pub impl Thread { fn start(main: ~fn()) -> Thread { - fn substart(main: &fn()) -> *raw_thread { - unsafe { rust_raw_thread_start(&main) } + fn substart(main: &~fn()) -> *raw_thread { + unsafe { rust_raw_thread_start(main) } } - let raw = substart(main); + let raw = substart(&main); Thread { main: main, raw_thread: raw @@ -39,6 +39,6 @@ impl Drop for Thread { } extern { - pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread; + pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread; pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread); } diff --git a/src/libcore/rt/uv/mod.rs b/src/libcore/rt/uv/mod.rs index 4cbc8d70569..cb7925abdcd 100644 --- a/src/libcore/rt/uv/mod.rs +++ b/src/libcore/rt/uv/mod.rs @@ -366,14 +366,15 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf { /// Transmute an owned vector to a Buf pub fn vec_to_uv_buf(v: ~[u8]) -> Buf { - let data = unsafe { malloc(v.len() as size_t) } as *u8; - assert!(data.is_not_null()); - do vec::as_imm_buf(v) |b, l| { - let data = data as *mut u8; - unsafe { ptr::copy_memory(data, b, l) } + unsafe { + let data = malloc(v.len() as size_t) as *u8; + assert!(data.is_not_null()); + do vec::as_imm_buf(v) |b, l| { + let data = data as *mut u8; + ptr::copy_memory(data, b, l) + } + uvll::buf_init(data, v.len()) } - let buf = unsafe { uvll::buf_init(data, v.len()) }; - return buf; } /// Transmute a Buf that was once a ~[u8] back to ~[u8] @@ -384,6 +385,7 @@ pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> { return Some(v); } else { // No buffer + rtdebug!("No buffer!"); return None; } } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 0173620dc51..8cad0a22886 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -154,7 +154,7 @@ pub fn pref_align_of_val(_val: &T) -> uint { #[inline(always)] pub fn refcount(t: @T) -> uint { unsafe { - let ref_ptr: *uint = cast::transmute(t); + let ref_ptr: *uint = cast::transmute_copy(&t); *ref_ptr - 1 } } diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 587f13ad65e..c45ba64c584 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -729,16 +729,16 @@ pub fn trans_intrinsic(ccx: @CrateContext, _ => fail!(~"transmute has non-expr arg"), }; let pluralize = |n| if 1u == n { "" } else { "s" }; - ccx.sess.span_err(sp, - fmt!("transmute called on types with \ - different sizes: %s (%u bit%s) to \ - %s (%u bit%s)", - ty_to_str(ccx.tcx, in_type), - in_type_size, - pluralize(in_type_size), - ty_to_str(ccx.tcx, out_type), - out_type_size, - pluralize(out_type_size))); + ccx.sess.span_fatal(sp, + fmt!("transmute called on types with \ + different sizes: %s (%u bit%s) to \ + %s (%u bit%s)", + ty_to_str(ccx.tcx, in_type), + in_type_size, + pluralize(in_type_size), + ty_to_str(ccx.tcx, out_type), + out_type_size, + pluralize(out_type_size))); } if !ty::type_is_nil(out_type) { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 7ce34bba29c..b9f3de873cf 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3467,11 +3467,11 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { ~[ arg(ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), - ty::mk_int(tcx))), + ty::mk_int())), arg(ty::mk_int()), arg(ty::mk_int()) ], - ty::mk_int(tcx)) + ty::mk_int()) } ~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" | ~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" | @@ -3480,7 +3480,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { ~[ arg(ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), - ty::mk_int(tcx))), + ty::mk_int())), arg(ty::mk_int()) ], ty::mk_int()) @@ -3550,7 +3550,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { })), arg(ty::mk_u64()) ], - ty::mk_nil(tcx)) + ty::mk_nil()) } ~"sqrtf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), ~"sqrtf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 21a6153380c..e86ec793188 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -828,18 +828,22 @@ mod tests { let m = ~Mutex(); let m2 = m.clone(); let mut sharedstate = ~0; - let ptr: *int = &*sharedstate; - do task::spawn || { - let sharedstate: &mut int = - unsafe { cast::transmute(ptr) }; - access_shared(sharedstate, m2, 10); - c.send(()); + { + let ptr: *int = &*sharedstate; + do task::spawn || { + let sharedstate: &mut int = + unsafe { cast::transmute(ptr) }; + access_shared(sharedstate, m2, 10); + c.send(()); + } } - access_shared(sharedstate, m, 10); - let _ = p.recv(); + { + access_shared(sharedstate, m, 10); + let _ = p.recv(); - assert!(*sharedstate == 20); + assert!(*sharedstate == 20); + } fn access_shared(sharedstate: &mut int, m: &Mutex, n: uint) { for n.times { @@ -1106,17 +1110,21 @@ mod tests { let (p,c) = comm::stream(); let x2 = (*x).clone(); let mut sharedstate = ~0; - let ptr: *int = &*sharedstate; - do task::spawn || { - let sharedstate: &mut int = - unsafe { cast::transmute(ptr) }; - access_shared(sharedstate, &x2, mode1, 10); - c.send(()); + { + let ptr: *int = &*sharedstate; + do task::spawn || { + let sharedstate: &mut int = + unsafe { cast::transmute(ptr) }; + access_shared(sharedstate, &x2, mode1, 10); + c.send(()); + } } - access_shared(sharedstate, x, mode2, 10); - let _ = p.recv(); + { + access_shared(sharedstate, x, mode2, 10); + let _ = p.recv(); - assert!(*sharedstate == 20); + assert!(*sharedstate == 20); + } fn access_shared(sharedstate: &mut int, x: &RWlock, mode: RWlockMode, n: uint) { diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 8e5b3274bbb..8d7a97e2e48 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1396,9 +1396,9 @@ mod test { // not set the data on the connect_req // until its initialized set_data_for_req(connect_req_ptr as *libc::c_void, - transmute(&client_data)); + &client_data); set_data_for_uv_handle(tcp_handle_ptr as *libc::c_void, - transmute(&client_data)); + &client_data); debug!(~"before run tcp req loop"); run(test_loop); debug!(~"after run tcp req loop"); diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 9c309c1b9f9..3311c61de8b 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -365,7 +365,9 @@ impl gen_init for protocol { |s| ext_cx.parse_stmt( fmt!("data.%s.set_buffer(buffer)", s.name))), - ext_cx.parse_expr(fmt!("&(data.%s)", self.states[0].name)))); + ext_cx.parse_expr(fmt!( + "::core::ptr::to_unsafe_ptr(&(data.%s))", + self.states[0].name)))); quote_expr!({ let buffer = $buffer; diff --git a/src/llvm b/src/llvm index 2e9f0d21fe3..56dd407f4f9 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6 +Subproject commit 56dd407f4f97a01b8df6554c569170d2fc276fcb diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 2629c916fce..c8555ab1286 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -225,7 +225,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { } /// A parallel version of the bfs function. -fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { +fn pbfs(graph: &arc::ARC, key: node_id) -> bfs_result { // This works by doing functional updates of a color vector. enum color { @@ -236,7 +236,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { black(node_id) }; - let graph_vec = arc::get(&graph); // FIXME #3387 requires this temp + let graph_vec = arc::get(graph); // FIXME #3387 requires this temp let mut colors = do vec::from_fn(graph_vec.len()) |i| { if i as node_id == key { gray(key) @@ -271,7 +271,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { let color_vec = arc::get(&color); // FIXME #3387 requires this temp colors = do par::mapi(*color_vec) { let colors = arc::clone(&color); - let graph = arc::clone(&graph); + let graph = arc::clone(graph); let result: ~fn(+x: uint, +y: &color) -> color = |i, c| { let colors = arc::get(&colors); let graph = arc::get(&graph); @@ -496,7 +496,7 @@ fn main() { } let start = time::precise_time_s(); - let bfs_tree = pbfs(graph_arc, *root); + let bfs_tree = pbfs(&graph_arc, *root); let stop = time::precise_time_s(); total_par += stop - start; diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index ded0a305e99..3833c884652 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -34,7 +34,7 @@ enum request { stop } -fn server(requests: Port, responses: comm::Chan) { +fn server(requests: &Port, responses: &comm::Chan) { let mut count = 0u; let mut done = false; while !done { @@ -76,7 +76,7 @@ fn run(args: &[~str]) { }; } do task::spawn || { - server(from_parent, to_parent); + server(&from_parent, &to_parent); } for vec::each(worker_results) |r| { diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 03348b45610..c4044d45f36 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -30,7 +30,7 @@ enum request { stop } -fn server(requests: PortSet, responses: Chan) { +fn server(requests: &PortSet, responses: &Chan) { let mut count = 0; let mut done = false; while !done { @@ -73,7 +73,7 @@ fn run(args: &[~str]) { }; } do task::spawn || { - server(from_parent, to_parent); + server(&from_parent, &to_parent); } for vec::each(worker_results) |r| { diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index bb763cebb44..4cd7b58ce12 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -104,8 +104,8 @@ fn windows_with_carry(bb: &[u8], nn: uint, } fn make_sequence_processor(sz: uint, - from_parent: comm::Port<~[u8]>, - to_parent: comm::Chan<~str>) { + from_parent: &comm::Port<~[u8]>, + to_parent: &comm::Chan<~str>) { let mut freqs: HashMap<~[u8], uint> = HashMap::new(); let mut carry: ~[u8] = ~[]; let mut total: uint = 0u; @@ -140,7 +140,7 @@ fn make_sequence_processor(sz: uint, // given a FASTA file on stdin, process sequence THREE fn main() { let args = os::args(); - let rdr = if os::getenv(~"RUST_BENCH").is_some() { + let rdr = if os::getenv(~"RUST_BENCH").is_some() { // FIXME: Using this compile-time env variable is a crummy way to // get to this massive data set, but include_bin! chokes on it (#2598) let path = Path(env!("CFG_SRC_DIR")) @@ -168,7 +168,7 @@ fn main() { let (from_parent, to_child) = comm::stream(); do task::spawn_with(from_parent) |from_parent| { - make_sequence_processor(sz, from_parent, to_parent_); + make_sequence_processor(sz, &from_parent, &to_parent_); }; to_child diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index ba970602833..acb8a6bcbee 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -30,7 +30,7 @@ use core::result; use core::result::{Ok, Err}; fn fib(n: int) -> int { - fn pfib(c: Chan, n: int) { + fn pfib(c: &Chan, n: int) { if n == 0 { c.send(0); } else if n <= 2 { @@ -38,15 +38,15 @@ fn fib(n: int) -> int { } else { let p = PortSet::new(); let ch = p.chan(); - task::spawn(|| pfib(ch, n - 1) ); + task::spawn(|| pfib(&ch, n - 1) ); let ch = p.chan(); - task::spawn(|| pfib(ch, n - 2) ); + task::spawn(|| pfib(&ch, n - 2) ); c.send(p.recv() + p.recv()); } } let (p, ch) = stream(); - let _t = task::spawn(|| pfib(ch, n) ); + let _t = task::spawn(|| pfib(&ch, n) ); p.recv() } diff --git a/src/test/compile-fail/arg-style-mismatch.rs b/src/test/compile-fail/arg-style-mismatch.rs deleted file mode 100644 index 2efc16de830..00000000000 --- a/src/test/compile-fail/arg-style-mismatch.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern: mismatched types - -fn f(&&_x: int) {} -fn g(_a: &fn(+v: int)) {} -fn main() { g(f); } diff --git a/src/test/compile-fail/liveness-move-from-args.rs b/src/test/compile-fail/liveness-move-from-args.rs deleted file mode 100644 index c60848e5cc6..00000000000 --- a/src/test/compile-fail/liveness-move-from-args.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn take(_x: ~int) { } - -fn from_by_ref_arg(&&x: ~int) { - take(x); //~ ERROR illegal move from argument `x`, which is not copy or move mode -} - -fn from_copy_arg(+x: ~int) { - take(x); -} - -fn main() { -} diff --git a/src/test/compile-fail/mode-inference-fail.rs b/src/test/compile-fail/mode-inference-fail.rs deleted file mode 100644 index 9fe464131cc..00000000000 --- a/src/test/compile-fail/mode-inference-fail.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// In this test, the mode gets inferred to ++ due to the apply_int(), -// but then we get a failure in the generic apply(). - -fn apply(f: &fn(A) -> A, a: A) -> A { f(a) } -fn apply_int(f: &fn(int) -> int, a: int) -> int { f(a) } - -fn main() { - let f = {|i| i}; - assert!(apply_int(f, 2) == 2); - assert!(apply(f, 2) == 2); //~ ERROR expected argument mode && -} diff --git a/src/test/compile-fail/mutable-arguments.rs b/src/test/compile-fail/mutable-arguments.rs deleted file mode 100644 index 39e47fb1aab..00000000000 --- a/src/test/compile-fail/mutable-arguments.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Note: it would be nice to give fewer warnings in these cases. - -fn mutate_by_mut_ref(x: &mut uint) { - *x = 0; -} - -fn mutate_by_ref(&&x: uint) { - //~^ WARNING unused variable: `x` - x = 0; //~ ERROR assigning to argument -} - -fn mutate_by_copy(+x: uint) { - //~^ WARNING unused variable: `x` - x = 0; //~ ERROR assigning to argument - //~^ WARNING value assigned to `x` is never read -} - -fn mutate_by_move(+x: uint) { - //~^ WARNING unused variable: `x` - x = 0; //~ ERROR assigning to argument - //~^ WARNING value assigned to `x` is never read -} - -fn main() { -} diff --git a/src/test/run-pass/alt-pattern-drop.rs b/src/test/run-pass/alt-pattern-drop.rs index 8e71d8d4a67..d9f3f10a11b 100644 --- a/src/test/run-pass/alt-pattern-drop.rs +++ b/src/test/run-pass/alt-pattern-drop.rs @@ -25,7 +25,7 @@ fn foo(s: @int) { _ => { debug!("?"); fail!(); } } debug!(::core::sys::refcount(s)); - assert!((::core::sys::refcount(s) == count + 1u)); + assert_eq!(::core::sys::refcount(s), count + 1u); let _ = ::core::sys::refcount(s); // don't get bitten by last-use. } @@ -39,5 +39,5 @@ pub fn main() { debug!("%u", ::core::sys::refcount(s)); let count2 = ::core::sys::refcount(s); let _ = ::core::sys::refcount(s); // don't get bitten by last-use. - assert!(count == count2); + assert_eq!(count, count2); } diff --git a/src/test/run-pass/cci_iter_exe.rs b/src/test/run-pass/cci_iter_exe.rs index cdee58daa20..cb713adcb28 100644 --- a/src/test/run-pass/cci_iter_exe.rs +++ b/src/test/run-pass/cci_iter_exe.rs @@ -17,7 +17,7 @@ pub fn main() { //let bt0 = sys::rusti::frame_address(1u32); //debug!("%?", bt0); do cci_iter_lib::iter(~[1, 2, 3]) |i| { - io::print(fmt!("%d", i)); + io::print(fmt!("%d", *i)); //assert!(bt0 == sys::rusti::frame_address(2u32)); } } diff --git a/src/test/run-pass/cci_nested_exe.rs b/src/test/run-pass/cci_nested_exe.rs index f6bfa25d94d..847d8a4d1f9 100644 --- a/src/test/run-pass/cci_nested_exe.rs +++ b/src/test/run-pass/cci_nested_exe.rs @@ -16,14 +16,14 @@ use cci_nested_lib::*; pub fn main() { let lst = new_int_alist(); - alist_add(lst, 22, ~"hi"); - alist_add(lst, 44, ~"ho"); - assert!(alist_get(lst, 22) == ~"hi"); - assert!(alist_get(lst, 44) == ~"ho"); + alist_add(&lst, 22, ~"hi"); + alist_add(&lst, 44, ~"ho"); + assert!(alist_get(&lst, 22) == ~"hi"); + assert!(alist_get(&lst, 44) == ~"ho"); let lst = new_int_alist_2(); - alist_add(lst, 22, ~"hi"); - alist_add(lst, 44, ~"ho"); - assert!(alist_get(lst, 22) == ~"hi"); - assert!(alist_get(lst, 44) == ~"ho"); + alist_add(&lst, 22, ~"hi"); + alist_add(&lst, 44, ~"ho"); + assert!(alist_get(&lst, 22) == ~"hi"); + assert!(alist_get(&lst, 44) == ~"ho"); } diff --git a/src/test/run-pass/class-implement-traits.rs b/src/test/run-pass/class-implement-traits.rs index 9709515a75a..1c0a09d52cf 100644 --- a/src/test/run-pass/class-implement-traits.rs +++ b/src/test/run-pass/class-implement-traits.rs @@ -68,5 +68,4 @@ pub fn main() { for uint::range(1u, 10u) |_i| { make_speak(copy nyan); } - assert!((nyan.eat())); } diff --git a/src/test/run-pass/enum-alignment.rs b/src/test/run-pass/enum-alignment.rs index 8883e50622f..cf92515e010 100644 --- a/src/test/run-pass/enum-alignment.rs +++ b/src/test/run-pass/enum-alignment.rs @@ -14,7 +14,10 @@ fn addr_of(ptr: &T) -> uint { } fn is_aligned(ptr: &T) -> bool { - (ptr::to_unsafe_ptr(ptr) % sys::min_align_of::()) == 0 + unsafe { + let addr: uint = ::cast::transmute(ptr); + (addr % sys::min_align_of::()) == 0 + } } pub fn main() { diff --git a/src/test/run-pass/regions-mock-trans.rs b/src/test/run-pass/regions-mock-trans.rs index 5a125ef9e0f..c46e41ab0eb 100644 --- a/src/test/run-pass/regions-mock-trans.rs +++ b/src/test/run-pass/regions-mock-trans.rs @@ -26,7 +26,7 @@ struct Ccx { fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> { unsafe { cast::transmute(libc::malloc(sys::size_of::>() - as libc::size_t)); + as libc::size_t)) } } 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 a91a6a92820..afed0bd9ac3 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::cell::Cell; + pub fn main() { test05(); } fn test05_start(&&f: ~fn(int)) { @@ -20,7 +22,8 @@ fn test05() { error!(*three + n); // will copy x into the closure assert!((*three == 3)); }; + let fn_to_send = Cell(fn_to_send); task::spawn(|| { - test05_start(fn_to_send); + test05_start(fn_to_send.take()); }); } diff --git a/src/test/run-pass/static-method-test.rs b/src/test/run-pass/static-method-test.rs index eed83ec34b3..973897cd145 100644 --- a/src/test/run-pass/static-method-test.rs +++ b/src/test/run-pass/static-method-test.rs @@ -58,10 +58,10 @@ fn build>(builder: &fn(push: &fn(+v: A))) -> B { /// Apply a function to each element of an iterable and return the results fn map, U, BU: buildable> - (v: IT, f: &fn(T) -> U) -> BU { + (v: IT, f: &fn(&T) -> U) -> BU { do build |push| { for v.each() |elem| { - push(f(*elem)); + push(f(elem)); } } } @@ -78,9 +78,9 @@ pub fn main() { let v: @[int] = seq_range(0, 10); assert!(v == @[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - let v: @[int] = map(&[1,2,3], |x| 1+x); + let v: @[int] = map(&[1,2,3], |&x| 1+x); assert!(v == @[2, 3, 4]); - let v: ~[int] = map(&[1,2,3], |x| 1+x); + let v: ~[int] = map(&[1,2,3], |&x| 1+x); assert!(v == ~[2, 3, 4]); assert!(bool_like::select(true, 9, 14) == 9); diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index 2380302c8bc..6fc29fa32db 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -17,7 +17,7 @@ use core::comm::Port; pub fn main() { test05(); } -fn test05_start(ch : Chan) { +fn test05_start(ch : &Chan) { ch.send(10); error!("sent 10"); ch.send(20); @@ -28,8 +28,8 @@ fn test05_start(ch : Chan) { fn test05() { let (po, ch) = comm::stream(); - task::spawn(|| test05_start(ch) ); - let mut value = po.recv(); + task::spawn(|| test05_start(&ch) ); + let mut value: int = po.recv(); error!(value); value = po.recv(); error!(value); diff --git a/src/test/run-pass/task-comm-13.rs b/src/test/run-pass/task-comm-13.rs index a01a33e589b..f22328a3e1b 100644 --- a/src/test/run-pass/task-comm-13.rs +++ b/src/test/run-pass/task-comm-13.rs @@ -12,7 +12,7 @@ extern mod std; -fn start(c: comm::Chan, start: int, number_of_messages: int) { +fn start(c: &comm::Chan, start: int, number_of_messages: int) { let mut i: int = 0; while i < number_of_messages { c.send(start + i); i += 1; } } @@ -20,6 +20,6 @@ fn start(c: comm::Chan, start: int, number_of_messages: int) { pub fn main() { debug!("Check that we don't deadlock."); let (p, ch) = comm::stream(); - task::try(|| start(ch, 0, 10) ); + task::try(|| start(&ch, 0, 10) ); debug!("Joined task"); } diff --git a/src/test/run-pass/task-comm-7.rs b/src/test/run-pass/task-comm-7.rs index 6ff0d1663fe..12f9a113dfc 100644 --- a/src/test/run-pass/task-comm-7.rs +++ b/src/test/run-pass/task-comm-7.rs @@ -14,7 +14,7 @@ extern mod std; pub fn main() { test00(); } -fn test00_start(c: comm::Chan, start: int, number_of_messages: int) { +fn test00_start(c: &comm::Chan, start: int, number_of_messages: int) { let mut i: int = 0; while i < number_of_messages { c.send(start + i); i += 1; } } @@ -27,19 +27,19 @@ fn test00() { let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 0, number_of_messages); + test00_start(&c, number_of_messages * 0, number_of_messages); } let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 1, number_of_messages); + test00_start(&c, number_of_messages * 1, number_of_messages); } let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 2, number_of_messages); + test00_start(&c, number_of_messages * 2, number_of_messages); } let c = p.chan(); do task::spawn || { - test00_start(c, number_of_messages * 3, number_of_messages); + test00_start(&c, number_of_messages * 3, number_of_messages); } let mut i: int = 0; -- cgit 1.4.1-3-g733a5 From 37abf4bad0eda08cf4ef756310443329fa28f6cf Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 26 Apr 2013 18:52:15 -0700 Subject: librustc: Forbid type implementations on typedefs. --- src/libcore/comm.rs | 75 +++++++++++++++++++----- src/libcore/path.rs | 21 ++----- src/librustc/middle/typeck/coherence.rs | 101 ++++++++++++++++++++------------ src/libstd/future.rs | 13 ++-- src/libstd/workcache.rs | 13 ++-- src/libsyntax/ext/auto_encode.rs | 45 +++++++++++++- src/libsyntax/fold.rs | 6 +- src/test/auxiliary/issue-2526.rs | 3 - 8 files changed, 193 insertions(+), 84 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index abe8bd7c8d1..522eebaf327 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -395,24 +395,55 @@ pub mod oneshot { } /// The send end of a oneshot pipe. -pub type ChanOne = oneshot::client::Oneshot; +pub struct ChanOne { + contents: oneshot::client::Oneshot +} + +impl ChanOne { + pub fn new(contents: oneshot::client::Oneshot) -> ChanOne { + ChanOne { + contents: contents + } + } +} + /// The receive end of a oneshot pipe. -pub type PortOne = oneshot::server::Oneshot; +pub struct PortOne { + contents: oneshot::server::Oneshot +} + +impl PortOne { + pub fn new(contents: oneshot::server::Oneshot) -> PortOne { + PortOne { + contents: contents + } + } +} /// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair. pub fn oneshot() -> (PortOne, ChanOne) { let (chan, port) = oneshot::init(); - (port, chan) + (PortOne::new(port), ChanOne::new(chan)) } pub impl PortOne { fn recv(self) -> T { recv_one(self) } fn try_recv(self) -> Option { try_recv_one(self) } + fn unwrap(self) -> oneshot::server::Oneshot { + match self { + PortOne { contents: s } => s + } + } } pub impl ChanOne { fn send(self, data: T) { send_one(self, data) } fn try_send(self, data: T) -> bool { try_send_one(self, data) } + fn unwrap(self) -> oneshot::client::Oneshot { + match self { + ChanOne { contents: s } => s + } + } } /** @@ -420,33 +451,47 @@ pub impl ChanOne { * closed. */ pub fn recv_one(port: PortOne) -> T { - let oneshot::send(message) = recv(port); - message + match port { + PortOne { contents: port } => { + let oneshot::send(message) = recv(port); + message + } + } } /// Receive a message from a oneshot pipe unless the connection was closed. pub fn try_recv_one (port: PortOne) -> Option { - let message = try_recv(port); - - if message.is_none() { None } - else { - let oneshot::send(message) = message.unwrap(); - Some(message) + match port { + PortOne { contents: port } => { + let message = try_recv(port); + + if message.is_none() { + None + } else { + let oneshot::send(message) = message.unwrap(); + Some(message) + } + } } } /// Send a message on a oneshot pipe, failing if the connection was closed. pub fn send_one(chan: ChanOne, data: T) { - oneshot::client::send(chan, data); + match chan { + ChanOne { contents: chan } => oneshot::client::send(chan, data), + } } /** * Send a message on a oneshot pipe, or return false if the connection was * closed. */ -pub fn try_send_one(chan: ChanOne, data: T) - -> bool { - oneshot::client::try_send(chan, data).is_some() +pub fn try_send_one(chan: ChanOne, data: T) -> bool { + match chan { + ChanOne { contents: chan } => { + oneshot::client::try_send(chan, data).is_some() + } + } } diff --git a/src/libcore/path.rs b/src/libcore/path.rs index edc61299af9..462c5be3bcf 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -21,6 +21,11 @@ use str; use to_str::ToStr; use ascii::{AsciiCast, AsciiStr}; +#[cfg(windows)] +pub use Path = self::WindowsPath; +#[cfg(unix)] +pub use Path = self::PosixPath; + #[deriving(Clone, Eq)] pub struct WindowsPath { host: Option<~str>, @@ -72,22 +77,6 @@ pub trait GenericPath { fn is_absolute(&self) -> bool; } -#[cfg(windows)] -pub type Path = WindowsPath; - -#[cfg(windows)] -pub fn Path(s: &str) -> Path { - WindowsPath(s) -} - -#[cfg(unix)] -pub type Path = PosixPath; - -#[cfg(unix)] -pub fn Path(s: &str) -> Path { - PosixPath(s) -} - #[cfg(target_os = "linux")] #[cfg(target_os = "android")] mod stat { diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 14c9bc36d7f..05b2f6f577b 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -38,8 +38,9 @@ use middle::typeck::infer::combine::Combine; use middle::typeck::infer::InferCtxt; use middle::typeck::infer::{new_infer_ctxt, resolve_ivar}; use middle::typeck::infer::{resolve_nested_tvar, resolve_type}; -use syntax::ast::{crate, def_id, def_mod, def_trait}; -use syntax::ast::{item, item_impl, item_mod, local_crate, method, trait_ref}; +use syntax::ast::{crate, def_id, def_mod, def_struct, def_trait, def_ty}; +use syntax::ast::{item, item_enum, item_impl, item_mod, item_struct}; +use syntax::ast::{local_crate, method, trait_ref, ty_path}; use syntax::ast; use syntax::ast_map::node_item; use syntax::ast_map; @@ -661,7 +662,19 @@ pub impl CoherenceChecker { // Then visit the module items. visit_mod(module_, item.span, item.id, (), visitor); } - item_impl(_, opt_trait, _, _) => { + item_impl(_, None, ast_ty, _) => { + if !self.ast_type_is_defined_in_local_crate(ast_ty) { + // This is an error. + let session = self.crate_context.tcx.sess; + session.span_err(item.span, + ~"cannot associate methods with \ + a type outside the crate the \ + type is defined in; define \ + and implement a trait or new \ + type instead"); + } + } + item_impl(_, Some(trait_ref), _, _) => { // `for_ty` is `Type` in `impl Trait for Type` let for_ty = ty::node_id_to_type(self.crate_context.tcx, @@ -671,40 +684,16 @@ pub impl CoherenceChecker { // type. This still might be OK if the trait is // defined in the same crate. - match opt_trait { - None => { - // There is no trait to implement, so - // this is an error. - - let session = self.crate_context.tcx.sess; - session.span_err(item.span, - ~"cannot implement \ - inherent methods for a \ - type outside the crate \ - the type was defined \ - in; define and \ - implement a trait or \ - new type instead"); - } + let trait_def_id = + self.trait_ref_to_trait_def_id(trait_ref); - Some(trait_ref) => { - // This is OK if and only if the trait was - // defined in this crate. - - let trait_def_id = - self.trait_ref_to_trait_def_id( - trait_ref); - - if trait_def_id.crate != local_crate { - let session = self.crate_context.tcx.sess; - session.span_err(item.span, - ~"cannot provide an \ - extension \ - implementation for a \ - trait not defined in \ - this crate"); - } - } + if trait_def_id.crate != local_crate { + let session = self.crate_context.tcx.sess; + session.span_err(item.span, + ~"cannot provide an \ + extension implementation \ + for a trait not defined \ + in this crate"); } } @@ -754,6 +743,46 @@ pub impl CoherenceChecker { } } + /// For coherence, when we have `impl Type`, we need to guarantee that + /// `Type` is "local" to the crate. For our purposes, this means that it + /// must precisely name some nominal type defined in this crate. + pub fn ast_type_is_defined_in_local_crate(&self, original_type: @ast::Ty) + -> bool { + match original_type.node { + ty_path(_, path_id) => { + match *self.crate_context.tcx.def_map.get(&path_id) { + def_ty(def_id) | def_struct(def_id) => { + if def_id.crate != local_crate { + return false; + } + + // Make sure that this type precisely names a nominal + // type. + match self.crate_context + .tcx + .items + .find(&def_id.node) { + None => { + self.crate_context.tcx.sess.span_bug( + original_type.span, + ~"resolve didn't resolve this type?!"); + } + Some(&node_item(item, _)) => { + match item.node { + item_struct(*) | item_enum(*) => true, + _ => false, + } + } + Some(_) => false, + } + } + _ => false + } + } + _ => false + } + } + // Converts an implementation in the AST to an Impl structure. fn create_impl_from_item(&self, item: @item) -> @Impl { fn add_provided_methods(all_methods: &mut ~[@MethodInfo], diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 264f3072cb1..c6c593d7b4a 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -23,7 +23,7 @@ use core::cast; use core::cell::Cell; -use core::comm::{oneshot, PortOne, send_one}; +use core::comm::{ChanOne, PortOne, oneshot, send_one}; use core::pipes::recv; use core::task; @@ -120,8 +120,7 @@ pub fn from_value(val: A) -> Future { Future {state: Forced(val)} } -pub fn from_port(port: PortOne) -> - Future { +pub fn from_port(port: PortOne) -> Future { /*! * Create a future from a port * @@ -131,7 +130,7 @@ pub fn from_port(port: PortOne) -> let port = Cell(port); do from_fn || { - let port = port.take(); + let port = port.take().unwrap(); match recv(port) { oneshot::send(data) => data } @@ -158,10 +157,10 @@ pub fn spawn(blk: ~fn() -> A) -> Future { * value of the future. */ - let (chan, port) = oneshot::init(); + let (port, chan) = oneshot(); let chan = Cell(chan); - do task::spawn || { + do task::spawn { let chan = chan.take(); send_one(chan, blk()); } @@ -186,7 +185,7 @@ mod test { #[test] fn test_from_port() { - let (ch, po) = oneshot::init(); + let (ch, po) = oneshot(); send_one(ch, ~"whale"); let f = from_port(po); assert!(f.get() == ~"whale"); diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index ae09b9b9026..bb4a9e97ea1 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -16,10 +16,13 @@ use serialize::{Encoder, Encodable, Decoder, Decodable}; use sort; use core::cell::Cell; -use core::comm::{oneshot, PortOne, send_one}; +use core::cmp; +use core::comm::{ChanOne, PortOne, oneshot, send_one}; +use core::either::{Either, Left, Right}; +use core::hashmap::HashMap; +use core::io; use core::pipes::recv; use core::run; -use core::hashmap::HashMap; use core::to_bytes; /** @@ -340,13 +343,13 @@ impl TPrep for Prep { } _ => { - let (chan, port) = oneshot::init(); + let (port, chan) = oneshot(); let mut blk = None; blk <-> bo; let blk = blk.unwrap(); let chan = Cell(chan); - do task::spawn || { + do task::spawn { let exe = Exec { discovered_inputs: WorkMap::new(), discovered_outputs: WorkMap::new(), @@ -383,7 +386,7 @@ fn unwrap fail!(), Some(Left(v)) => v, Some(Right(port)) => { - let (exe, v) = match recv(port) { + let (exe, v) = match recv(port.unwrap()) { oneshot::send(data) => data }; diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index da7b9570131..2ceb6f0c4bb 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -215,7 +215,50 @@ pub fn expand_auto_decode( } } -priv impl @ext_ctxt { +trait ExtCtxtMethods { + fn bind_path(&self, + span: span, + ident: ast::ident, + path: @ast::Path, + bounds: @OptVec) + -> ast::TyParam; + fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; + fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path_tps(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) + -> @ast::Path; + fn path_tps_global(&self, + span: span, + strs: ~[ast::ident], + tps: ~[@ast::Ty]) + -> @ast::Path; + fn ty_path(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) + -> @ast::Ty; + fn binder_pat(&self, span: span, nm: ast::ident) -> @ast::pat; + fn stmt(&self, expr: @ast::expr) -> @ast::stmt; + fn lit_str(&self, span: span, s: @~str) -> @ast::expr; + fn lit_uint(&self, span: span, i: uint) -> @ast::expr; + fn lambda(&self, blk: ast::blk) -> @ast::expr; + fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk; + fn expr_blk(&self, expr: @ast::expr) -> ast::blk; + fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; + fn expr_path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::expr; + fn expr_var(&self, span: span, var: ~str) -> @ast::expr; + fn expr_field(&self, span: span, expr: @ast::expr, ident: ast::ident) + -> @ast::expr; + fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) + -> @ast::expr; + fn expr_method_call(&self, + span: span, + expr: @ast::expr, + ident: ast::ident, + args: ~[@ast::expr]) + -> @ast::expr; + fn lambda_expr(&self, expr: @ast::expr) -> @ast::expr; + fn lambda_stmts(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr; +} + +impl ExtCtxtMethods for @ext_ctxt { fn bind_path( &self, _span: span, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index cee1f531176..d82608846ab 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -867,7 +867,11 @@ impl ast_fold for AstFoldFns { } } -pub impl @ast_fold { +pub trait AstFoldExtensions { + fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute]; +} + +impl AstFoldExtensions for @ast_fold { fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute] { attrs.map(|x| fold_attribute_(*x, *self)) } diff --git a/src/test/auxiliary/issue-2526.rs b/src/test/auxiliary/issue-2526.rs index 775955ff38c..fa32b9603a5 100644 --- a/src/test/auxiliary/issue-2526.rs +++ b/src/test/auxiliary/issue-2526.rs @@ -56,6 +56,3 @@ fn context_res() -> context_res { pub type context = arc_destruct; -pub impl context { - fn socket(&self) { } -} -- cgit 1.4.1-3-g733a5 From 39693e7b61c4ff3ea5a62fcc662e8ee9340c7d4f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 27 Apr 2013 22:05:39 -0700 Subject: test: Fix more tests. --- src/libcore/comm.rs | 6 +++--- src/libcore/pipes.rs | 4 ++-- src/libstd/future.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 522eebaf327..50a3bba049b 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -565,11 +565,11 @@ mod test { #[test] fn test_oneshot() { - let (c, p) = oneshot::init(); + let (p, c) = oneshot(); - oneshot::client::send(c, ()); + c.send(()); - recv_one(p) + p.recv() } #[test] diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 7364e50cc04..95b24d20a4b 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -885,9 +885,9 @@ mod test { #[test] fn test_oneshot() { - let (c, p) = oneshot::init(); + let (p, c) = oneshot(); - oneshot::client::send(c, ()); + c.send(()); recv_one(p) } diff --git a/src/libstd/future.rs b/src/libstd/future.rs index c6c593d7b4a..f59abfa81ca 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -185,7 +185,7 @@ mod test { #[test] fn test_from_port() { - let (ch, po) = oneshot(); + let (po, ch) = oneshot(); send_one(ch, ~"whale"); let f = from_port(po); assert!(f.get() == ~"whale"); -- cgit 1.4.1-3-g733a5 From a9da34bf6eb88ac20a7240d05022d6ebf136a6eb Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sun, 28 Apr 2013 10:53:42 -0700 Subject: librustc: Fix merge fallout. --- src/librustc/middle/trans/common.rs | 1 + src/libstd/net_ip.rs | 1 + 2 files changed, 2 insertions(+) (limited to 'src/libstd') diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 96071377a45..f8fb0f4b7cf 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -41,6 +41,7 @@ use middle::ty; use middle::typeck; use util::ppaux::{Repr}; +use core::cast::transmute; use core::hash; use core::hashmap::{HashMap, HashSet}; use core::libc::{c_uint, c_longlong, c_ulonglong}; diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index bf1b9dc0cda..0608d9dc3f2 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -151,6 +151,7 @@ pub mod v4 { use uv_ip4_addr = uv::ll::ip4_addr; use uv_ip4_name = uv::ll::ip4_name; + use core::cast::transmute; use core::ptr; use core::result; use core::str; -- cgit 1.4.1-3-g733a5 From 78f33437b66793b10eb2a72d0d20cbf2bf0eacb5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 29 Apr 2013 10:47:26 -0700 Subject: libstd: Fix merge fallout. --- src/libstd/net_ip.rs | 1 - src/libstd/priority_queue.rs | 1 - src/libsyntax/parse/mod.rs | 30 ++++++++++++++---------------- 3 files changed, 14 insertions(+), 18 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 0608d9dc3f2..800144c0ca7 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -152,7 +152,6 @@ pub mod v4 { use uv_ip4_name = uv::ll::ip4_name; use core::cast::transmute; - use core::ptr; use core::result; use core::str; use core::uint; diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 6f408823410..47af3576c90 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -11,7 +11,6 @@ //! A priority queue implemented with a binary heap use core::old_iter::BaseIter; -use core::ptr::addr_of; #[abi = "rust-intrinsic"] extern "rust-intrinsic" mod rusti { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d27d788e23a..7e7931bbb60 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -569,9 +569,8 @@ mod test { let parser = string_to_parser(@~"b : int"); assert_eq!(parser.parse_arg_general(true), ast::arg{ - mode: ast::infer(1), is_mutbl: false, - ty: @ast::Ty{id:4, // fixme + ty: @ast::Ty{id:3, // fixme node: ast::ty_path(@ast::Path{ span:sp(4,4), // this is bizarre... // check this in the original parser? @@ -579,9 +578,9 @@ mod test { idents:~[mk_ident(105)], rp: None, types: ~[]}, - 3), + 2), span:sp(4,7)}, - pat: @ast::pat{id:2, + pat: @ast::pat{id:1, node: ast::pat_ident(ast::bind_by_copy, @ast::Path{ span:sp(0,1), @@ -592,7 +591,7 @@ mod test { None // no idea ), span: sp(0,3)}, // really? - id: 5 // fixme + id: 4 // fixme }) } @@ -604,21 +603,20 @@ mod test { Some( @ast::item{ident:mk_ident(100), attrs:~[], - id: 11, // fixme + id: 10, // fixme node: ast::item_fn(ast::fn_decl{ inputs: ~[ast::arg{ - mode: ast::infer(1), is_mutbl: false, - ty: @ast::Ty{id:4, // fixme + ty: @ast::Ty{id:3, // fixme node: ast::ty_path(@ast::Path{ span:sp(10,13), global:false, idents:~[mk_ident(106)], rp: None, types: ~[]}, - 3), + 2), span:sp(10,13)}, - pat: @ast::pat{id:2, // fixme + pat: @ast::pat{id:1, // fixme node: ast::pat_ident( ast::bind_by_copy, @ast::Path{ @@ -630,9 +628,9 @@ mod test { None // no idea ), span: sp(6,9)}, // bleah. - id: 5 // fixme + id: 4 // fixme }], - output: @ast::Ty{id:6, // fixme + output: @ast::Ty{id:5, // fixme node: ast::ty_nil, span:sp(15,15)}, // not sure cf: ast::return_val @@ -649,8 +647,8 @@ mod test { view_items: ~[], stmts: ~[@spanned{ node: ast::stmt_semi(@ast::expr{ - id: 7, - callee_id: 8, + id: 6, + callee_id: 7, node: ast::expr_path( @ast::Path{ span:sp(17,18), @@ -659,10 +657,10 @@ mod test { rp:None, types: ~[]}), span: sp(17,18)}, - 9), // fixme + 8), // fixme span: sp(17,18)}], expr: None, - id: 10, // fixme + id: 9, // fixme rules: ast::default_blk // no idea }}), vis: ast::inherited, -- cgit 1.4.1-3-g733a5