diff options
| author | bors <bors@rust-lang.org> | 2014-05-11 02:26:43 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-11 02:26:43 -0700 |
| commit | fb569fd3986247ac3ce6a498e52a82bb4c535824 (patch) | |
| tree | 97bea161eb7fff71a0e9a484aa9f190dbe037f58 /src/libnative | |
| parent | adb8b0b230d5e5c79b4f873825b3d3cff8d1bc8f (diff) | |
| parent | f94d671bfae5d8e9a4a4add310b1c40af0ab62a6 (diff) | |
| download | rust-fb569fd3986247ac3ce6a498e52a82bb4c535824.tar.gz rust-fb569fd3986247ac3ce6a498e52a82bb4c535824.zip | |
auto merge of #14069 : alexcrichton/rust/cast-module, r=brson
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/addrinfo.rs | 8 | ||||
| -rw-r--r-- | src/libnative/io/file_win32.rs | 3 | ||||
| -rw-r--r-- | src/libnative/io/net.rs | 9 | ||||
| -rw-r--r-- | src/libnative/io/pipe_unix.rs | 3 | ||||
| -rw-r--r-- | src/libnative/io/process.rs | 6 | ||||
| -rw-r--r-- | src/libnative/io/timer_helper.rs | 6 | ||||
| -rw-r--r-- | src/libnative/lib.rs | 4 | ||||
| -rw-r--r-- | src/libnative/task.rs | 12 |
8 files changed, 24 insertions, 27 deletions
diff --git a/src/libnative/io/addrinfo.rs b/src/libnative/io/addrinfo.rs index 57b87f21521..8ebae70f73c 100644 --- a/src/libnative/io/addrinfo.rs +++ b/src/libnative/io/addrinfo.rs @@ -9,11 +9,11 @@ // except according to those terms. use ai = std::io::net::addrinfo; +use libc::{c_char, c_int}; +use libc; use std::c_str::CString; -use std::cast; use std::io::IoError; -use libc; -use libc::{c_char, c_int}; +use std::mem; use std::ptr::{null, mut_null}; use super::net::sockaddr_to_addr; @@ -61,7 +61,7 @@ impl GetAddrInfoRequest { let mut rp = res; while rp.is_not_null() { unsafe { - let addr = match sockaddr_to_addr(cast::transmute((*rp).ai_addr), + let addr = match sockaddr_to_addr(mem::transmute((*rp).ai_addr), (*rp).ai_addrlen as uint) { Ok(a) => a, Err(e) => return Err(e) diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index 5fc9e506cf2..fc08a7f128f 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -11,7 +11,6 @@ //! Blocking win32-based file I/O use std::c_str::CString; -use std::cast; use std::io::IoError; use std::io; use libc::{c_int, c_void}; @@ -175,7 +174,7 @@ impl rtio::RtioFileStream for FileDesc { // This transmute is fine because our seek implementation doesn't // actually use the mutable self at all. // FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes - unsafe { cast::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) } + unsafe { mem::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) } } fn fsync(&mut self) -> Result<(), IoError> { diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index 218f8a4ef49..40b66cc526f 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -9,7 +9,6 @@ // except according to those terms. use libc; -use std::cast; use std::io::net::ip; use std::io; use std::mem; @@ -72,14 +71,14 @@ fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) { let storage: libc::sockaddr_storage = mem::init(); let len = match ip_to_inaddr(addr.ip) { InAddr(inaddr) => { - let storage: *mut libc::sockaddr_in = cast::transmute(&storage); + let storage: *mut libc::sockaddr_in = mem::transmute(&storage); (*storage).sin_family = libc::AF_INET as libc::sa_family_t; (*storage).sin_port = htons(addr.port); (*storage).sin_addr = inaddr; mem::size_of::<libc::sockaddr_in>() } In6Addr(inaddr) => { - let storage: *mut libc::sockaddr_in6 = cast::transmute(&storage); + let storage: *mut libc::sockaddr_in6 = mem::transmute(&storage); (*storage).sin6_family = libc::AF_INET6 as libc::sa_family_t; (*storage).sin6_port = htons(addr.port); (*storage).sin6_addr = inaddr; @@ -173,7 +172,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage, libc::AF_INET => { assert!(len as uint >= mem::size_of::<libc::sockaddr_in>()); let storage: &libc::sockaddr_in = unsafe { - cast::transmute(storage) + mem::transmute(storage) }; let addr = storage.sin_addr.s_addr as u32; let a = (addr >> 0) as u8; @@ -188,7 +187,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage, libc::AF_INET6 => { assert!(len as uint >= mem::size_of::<libc::sockaddr_in6>()); let storage: &libc::sockaddr_in6 = unsafe { - cast::transmute(storage) + mem::transmute(storage) }; let a = ntohs(storage.sin6_addr.s6_addr[0]); let b = ntohs(storage.sin6_addr.s6_addr[1]); diff --git a/src/libnative/io/pipe_unix.rs b/src/libnative/io/pipe_unix.rs index 36ae2ba06d5..d66075f4419 100644 --- a/src/libnative/io/pipe_unix.rs +++ b/src/libnative/io/pipe_unix.rs @@ -10,7 +10,6 @@ use libc; use std::c_str::CString; -use std::cast; use std::intrinsics; use std::io; use std::mem; @@ -36,7 +35,7 @@ fn addr_to_sockaddr_un(addr: &CString) -> IoResult<(libc::sockaddr_storage, uint assert!(mem::size_of::<libc::sockaddr_storage>() >= mem::size_of::<libc::sockaddr_un>()); let mut storage: libc::sockaddr_storage = unsafe { intrinsics::init() }; - let s: &mut libc::sockaddr_un = unsafe { cast::transmute(&mut storage) }; + let s: &mut libc::sockaddr_un = unsafe { mem::transmute(&mut storage) }; let len = addr.len(); if len > s.sun_path.len() - 1 { diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index c83af20d1d8..81c76bba7a0 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -19,7 +19,7 @@ use p = std::io::process; use super::IoResult; use super::file; -#[cfg(windows)] use std::cast; +#[cfg(windows)] use std::mem; #[cfg(windows)] use std::strbuf::StrBuf; #[cfg(not(windows))] use super::retry; @@ -326,7 +326,7 @@ fn spawn_process_os(config: p::ProcessConfig, with_envp(env, |envp| { with_dirp(dir, |dirp| { cmd.with_c_str(|cmdp| { - let created = CreateProcessA(ptr::null(), cast::transmute(cmdp), + let created = CreateProcessA(ptr::null(), mem::transmute(cmdp), ptr::mut_null(), ptr::mut_null(), TRUE, flags, envp, dirp, &mut si, &mut pi); @@ -714,7 +714,7 @@ fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T { #[cfg(windows)] fn free_handle(handle: *()) { assert!(unsafe { - libc::CloseHandle(cast::transmute(handle)) != 0 + libc::CloseHandle(mem::transmute(handle)) != 0 }) } diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs index 3bf967cb426..95b2620f3c7 100644 --- a/src/libnative/io/timer_helper.rs +++ b/src/libnative/io/timer_helper.rs @@ -20,7 +20,7 @@ //! can be created in the future and there must be no active timers at that //! time. -use std::cast; +use std::mem; use std::rt::bookkeeping; use std::rt; use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; @@ -48,7 +48,7 @@ pub fn boot(helper: fn(imp::signal, Receiver<Req>)) { let (tx, rx) = channel(); // promote this to a shared channel drop(tx.clone()); - HELPER_CHAN = cast::transmute(box tx); + HELPER_CHAN = mem::transmute(box tx); let (receive, send) = imp::new(); HELPER_SIGNAL = send; @@ -86,7 +86,7 @@ fn shutdown() { // Clean up after ther helper thread unsafe { imp::close(HELPER_SIGNAL); - let _chan: Box<Sender<Req>> = cast::transmute(HELPER_CHAN); + let _chan: Box<Sender<Req>> = mem::transmute(HELPER_CHAN); HELPER_CHAN = 0 as *mut Sender<Req>; HELPER_SIGNAL = 0 as imp::signal; } diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index 4c0c4dcc18e..0df45f7d5a0 100644 --- a/src/libnative/lib.rs +++ b/src/libnative/lib.rs @@ -73,9 +73,9 @@ static OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20); #[lang = "start"] #[cfg(not(test))] pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int { - use std::cast; + use std::mem; start(argc, argv, proc() { - let main: extern "Rust" fn() = unsafe { cast::transmute(main) }; + let main: extern "Rust" fn() = unsafe { mem::transmute(main) }; main(); }) } diff --git a/src/libnative/task.rs b/src/libnative/task.rs index d5b02dc007b..4183dec19d0 100644 --- a/src/libnative/task.rs +++ b/src/libnative/task.rs @@ -15,7 +15,7 @@ //! in order to spawn new tasks and deschedule the current task. use std::any::Any; -use std::cast; +use std::mem; use std::rt::bookkeeping; use std::rt::env; use std::rt::local::Local; @@ -169,7 +169,7 @@ impl rt::Runtime for Ops { // for both tasks because these operations are all done inside of a mutex. // // You'll also find that if blocking fails (the `f` function hands the - // BlockedTask back to us), we will `cast::forget` the handles. The + // BlockedTask back to us), we will `mem::forget` the handles. The // reasoning for this is the same logic as above in that the task silently // transfers ownership via the `uint`, not through normal compiler // semantics. @@ -198,7 +198,7 @@ impl rt::Runtime for Ops { guard.wait(); } } - Err(task) => { cast::forget(task.wake()); } + Err(task) => { mem::forget(task.wake()); } } } else { let iter = task.make_selectable(times); @@ -217,7 +217,7 @@ impl rt::Runtime for Ops { Some(task) => { match task.wake() { Some(task) => { - cast::forget(task); + mem::forget(task); (*me).awoken = true; } None => {} @@ -229,7 +229,7 @@ impl rt::Runtime for Ops { } } // re-acquire ownership of the task - cur_task = cast::transmute(cur_task_dupe); + cur_task = mem::transmute(cur_task_dupe); } // put the task back in TLS, and everything is as it once was. @@ -242,7 +242,7 @@ impl rt::Runtime for Ops { unsafe { let me = &mut *self as *mut Ops; to_wake.put_runtime(self); - cast::forget(to_wake); + mem::forget(to_wake); let guard = (*me).lock.lock(); (*me).awoken = true; guard.signal(); |
