From f94d671bfae5d8e9a4a4add310b1c40af0ab62a6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 9 May 2014 10:34:51 -0700 Subject: [PATCH] core: Remove the cast module 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] [breaking-change] --- src/doc/guide-unsafe.md | 4 +- src/libarena/lib.rs | 57 +++----- src/libcollections/dlist.rs | 11 +- src/libcollections/enum_set.rs | 4 +- src/libcollections/lru_cache.rs | 9 +- src/libcore/any.rs | 2 +- src/libcore/cast.rs | 127 ------------------ src/libcore/char.rs | 2 +- src/libcore/kinds.rs | 8 +- src/libcore/lib.rs | 1 - src/libcore/mem.rs | 114 +++++++++++++++- src/libcore/option.rs | 4 +- src/libcore/ptr.rs | 38 +++--- src/libcore/raw.rs | 10 +- src/libcore/should_not_exist.rs | 15 +-- src/libcore/slice.rs | 7 +- src/libcore/str.rs | 23 ++-- src/libcore/ty.rs | 3 +- src/libgreen/basic.rs | 9 +- src/libgreen/context.rs | 4 +- src/libgreen/sched.rs | 22 +-- src/libgreen/simple.rs | 8 +- src/libgreen/task.rs | 8 +- src/liblog/lib.rs | 6 +- src/libnative/io/addrinfo.rs | 8 +- src/libnative/io/file_win32.rs | 3 +- src/libnative/io/net.rs | 9 +- src/libnative/io/pipe_unix.rs | 3 +- src/libnative/io/process.rs | 6 +- src/libnative/io/timer_helper.rs | 6 +- src/libnative/lib.rs | 4 +- src/libnative/task.rs | 12 +- src/librand/distributions/exponential.rs | 2 +- src/librand/distributions/normal.rs | 2 +- src/librand/lib.rs | 8 +- src/librand/os.rs | 6 +- src/librand/reader.rs | 6 +- src/librustc/back/archive.rs | 12 +- src/librustc/metadata/common.rs | 4 +- src/librustc/metadata/encoder.rs | 8 +- src/librustc/metadata/loader.rs | 6 +- src/librustc/middle/astencode.rs | 6 +- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/trans/type_.rs | 14 +- src/librustc/middle/ty.rs | 12 +- src/librustuv/access.rs | 4 +- src/librustuv/addrinfo.rs | 6 +- src/librustuv/async.rs | 8 +- src/librustuv/file.rs | 13 +- src/librustuv/homing.rs | 4 +- src/librustuv/idle.rs | 10 +- src/librustuv/lib.rs | 16 +-- src/librustuv/net.rs | 21 ++- src/librustuv/pipe.rs | 6 +- src/librustuv/queue.rs | 10 +- src/librustuv/stream.rs | 10 +- src/librustuv/timeout.rs | 5 +- src/librustuv/uvio.rs | 4 +- src/libserialize/ebml.rs | 14 +- src/libstd/ascii.rs | 32 ++--- src/libstd/c_str.rs | 23 ++-- src/libstd/c_vec.rs | 6 +- src/libstd/comm/select.rs | 12 +- src/libstd/comm/sync.rs | 3 +- src/libstd/fmt/mod.rs | 22 +-- src/libstd/hash/mod.rs | 6 +- src/libstd/io/extensions.rs | 4 +- src/libstd/io/mod.rs | 22 +-- src/libstd/io/net/udp.rs | 1 + src/libstd/lib.rs | 1 - src/libstd/local_data.rs | 8 +- src/libstd/num/f32.rs | 10 +- src/libstd/num/f64.rs | 8 +- src/libstd/path/windows.rs | 8 +- src/libstd/rc.rs | 2 +- src/libstd/repr.rs | 4 +- src/libstd/rt/args.rs | 11 +- src/libstd/rt/at_exit_imp.rs | 9 +- src/libstd/rt/backtrace.rs | 4 +- src/libstd/rt/local_heap.rs | 19 ++- src/libstd/rt/local_ptr.rs | 34 ++--- src/libstd/rt/rtio.rs | 8 +- src/libstd/rt/task.rs | 22 +-- src/libstd/rt/thread.rs | 21 ++- src/libstd/rt/thread_local_storage.rs | 2 +- src/libstd/rt/unwind.rs | 11 +- src/libstd/slice.rs | 9 +- src/libstd/str.rs | 32 ++--- src/libstd/strbuf.rs | 6 +- src/libstd/sync/arc.rs | 6 +- src/libstd/sync/atomics.rs | 20 +-- src/libstd/sync/deque.rs | 23 ++-- src/libstd/sync/mpsc_queue.rs | 8 +- src/libstd/sync/spsc_queue.rs | 8 +- src/libstd/unstable/dynamic_lib.rs | 4 +- src/libstd/vec.rs | 82 ++++++----- src/libsync/arc.rs | 6 +- src/libsync/mpsc_intrusive.rs | 8 +- src/libsync/raw.rs | 17 ++- src/libsyntax/ext/expand.rs | 6 +- src/libsyntax/owned_slice.rs | 8 +- src/libsyntax/parse/token.rs | 4 +- src/libsyntax/print/pprust.rs | 6 +- src/libsyntax/util/interner.rs | 4 +- src/libuuid/lib.rs | 2 +- src/test/auxiliary/issue_8401.rs | 4 +- .../compile-fail/coerce-unsafe-to-closure.rs | 2 +- src/test/compile-fail/issue-6458-3.rs | 4 +- .../packed-struct-generic-transmute.rs | 4 +- .../compile-fail/packed-struct-transmute.rs | 4 +- src/test/debuginfo/nil-enum.rs | 4 +- src/test/debuginfo/option-like-enum.rs | 10 +- src/test/run-fail/unwind-box-res.rs | 8 +- src/test/run-make/mixing-deps/dylib.rs | 4 +- src/test/run-make/mixing-deps/prog.rs | 4 +- src/test/run-pass/binops.rs | 10 +- src/test/run-pass/closure-reform.rs | 4 +- src/test/run-pass/enum-alignment.rs | 3 +- src/test/run-pass/enum-clike-ffi-as-int.rs | 2 +- src/test/run-pass/foreign-call-no-runtime.rs | 6 +- src/test/run-pass/ifmt.rs | 2 +- src/test/run-pass/intrinsic-move-val.rs | 2 +- src/test/run-pass/issue-2214.rs | 4 +- src/test/run-pass/issue-2718.rs | 18 +-- src/test/run-pass/issue-4735.rs | 2 +- .../nullable-pointer-iotareduction.rs | 6 +- .../run-pass/packed-struct-generic-layout.rs | 6 +- src/test/run-pass/packed-struct-layout.rs | 6 +- .../run-pass/packed-tuple-struct-layout.rs | 6 +- src/test/run-pass/pub-extern-privacy.rs | 2 +- src/test/run-pass/regions-mock-tcx.rs | 1 - src/test/run-pass/regions-mock-trans.rs | 5 +- src/test/run-pass/tag-align-dyn-u64.rs | 4 +- src/test/run-pass/tag-align-dyn-variants.rs | 4 +- src/test/run-pass/tag-align-u64.rs | 4 +- .../transmute-non-immediate-to-immediate.rs | 2 +- src/test/run-pass/unify-return-ty.rs | 4 +- 137 files changed, 723 insertions(+), 766 deletions(-) delete mode 100644 src/libcore/cast.rs diff --git a/src/doc/guide-unsafe.md b/src/doc/guide-unsafe.md index fc6a12b495e2e..d78e2103daca1 100644 --- a/src/doc/guide-unsafe.md +++ b/src/doc/guide-unsafe.md @@ -66,11 +66,11 @@ restrictions is undefined behaviour. For example, the following creates two aliasing `&mut` pointers, and is invalid. ``` -use std::cast; +use std::mem; let mut x: u8 = 1; let ref_1: &mut u8 = &mut x; -let ref_2: &mut u8 = unsafe { cast::transmute_mut_lifetime(ref_1) }; +let ref_2: &mut u8 = unsafe { mem::transmute(&mut *ref_1) }; // oops, ref_1 and ref_2 point to the same piece of data (x) and are // both usable diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 526b72e9b86ac..af9ffd5a4b6bf 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -26,8 +26,6 @@ extern crate collections; -use std::cast::{transmute, transmute_mut_lifetime}; -use std::cast; use std::cell::{Cell, RefCell}; use std::cmp; use std::intrinsics::{TyDesc, get_tydesc}; @@ -137,7 +135,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) { let fill = chunk.fill.get(); while idx < fill { - let tydesc_data: *uint = transmute(buf.offset(idx as int)); + let tydesc_data: *uint = mem::transmute(buf.offset(idx as int)); let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data); let (size, align) = ((*tydesc).size, (*tydesc).align); @@ -187,18 +185,17 @@ impl Arena { #[inline] fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 { unsafe { - let this = transmute_mut_lifetime(self); - let start = round_up(this.copy_head.fill.get(), align); + let start = round_up(self.copy_head.fill.get(), align); let end = start + n_bytes; if end > self.chunk_size() { - return this.alloc_copy_grow(n_bytes, align); + return self.alloc_copy_grow(n_bytes, align); } - this.copy_head.fill.set(end); + self.copy_head.fill.set(end); //debug!("idx = {}, size = {}, align = {}, fill = {}", // start, n_bytes, align, head.fill.get()); - this.copy_head.as_ptr().offset(start as int) + self.copy_head.as_ptr().offset(start as int) } } @@ -206,9 +203,9 @@ impl Arena { fn alloc_copy<'a, T>(&'a mut self, op: || -> T) -> &'a T { unsafe { let ptr = self.alloc_copy_inner(mem::size_of::(), min_align_of::()); - let ptr: *mut T = transmute(ptr); + let ptr = ptr as *mut T; mem::move_val_init(&mut (*ptr), op()); - return transmute(ptr); + return &*ptr; } } @@ -228,26 +225,16 @@ impl Arena { fn alloc_noncopy_inner(&mut self, n_bytes: uint, align: uint) -> (*u8, *u8) { unsafe { - let start; - let end; - let tydesc_start; - let after_tydesc; - - { - let head = transmute_mut_lifetime(&mut self.head); - - tydesc_start = head.fill.get(); - after_tydesc = head.fill.get() + mem::size_of::<*TyDesc>(); - start = round_up(after_tydesc, align); - end = start + n_bytes; - } + let tydesc_start = self.head.fill.get(); + let after_tydesc = self.head.fill.get() + mem::size_of::<*TyDesc>(); + let start = round_up(after_tydesc, align); + let end = start + n_bytes; if end > self.head.capacity() { return self.alloc_noncopy_grow(n_bytes, align); } - let head = transmute_mut_lifetime(&mut self.head); - head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>())); + self.head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>())); //debug!("idx = {}, size = {}, align = {}, fill = {}", // start, n_bytes, align, head.fill); @@ -263,18 +250,18 @@ impl Arena { let tydesc = get_tydesc::(); let (ty_ptr, ptr) = self.alloc_noncopy_inner(mem::size_of::(), min_align_of::()); - let ty_ptr: *mut uint = transmute(ty_ptr); - let ptr: *mut T = transmute(ptr); + let ty_ptr = ty_ptr as *mut uint; + let ptr = ptr as *mut T; // Write in our tydesc along with a bit indicating that it // has *not* been initialized yet. - *ty_ptr = transmute(tydesc); + *ty_ptr = mem::transmute(tydesc); // Actually initialize it mem::move_val_init(&mut(*ptr), op()); // Now that we are done, update the tydesc to indicate that // the object is there. *ty_ptr = bitpack_tydesc_ptr(tydesc, true); - return transmute(ptr); + return &*ptr; } } @@ -283,7 +270,7 @@ impl Arena { pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T { unsafe { // FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes - let this: &mut Arena = transmute::<&_, &mut _>(self); + let this: &mut Arena = mem::transmute::<&_, &mut _>(self); if intrinsics::needs_drop::() { this.alloc_noncopy(op) } else { @@ -366,7 +353,7 @@ impl TypedArenaChunk { let mut chunk = unsafe { let chunk = exchange_malloc(size); - let mut chunk: Box> = cast::transmute(chunk); + let mut chunk: Box> = mem::transmute(chunk); mem::move_val_init(&mut chunk.next, next); chunk }; @@ -387,7 +374,7 @@ impl TypedArenaChunk { let mut chunk = unsafe { let chunk = exchange_malloc(size, min_align_of::>()); - let mut chunk: Box> = cast::transmute(chunk); + let mut chunk: Box> = mem::transmute(chunk); mem::move_val_init(&mut chunk.next, next); chunk }; @@ -425,7 +412,7 @@ impl TypedArenaChunk { fn start(&self) -> *u8 { let this: *TypedArenaChunk = self; unsafe { - cast::transmute(round_up(this.offset(1) as uint, min_align_of::())) + mem::transmute(round_up(this.offset(1) as uint, min_align_of::())) } } @@ -463,12 +450,12 @@ impl TypedArena { pub fn alloc<'a>(&'a self, object: T) -> &'a T { unsafe { // FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes - let this: &mut TypedArena = cast::transmute::<&_, &mut _>(self); + let this: &mut TypedArena = mem::transmute::<&_, &mut _>(self); if this.ptr == this.end { this.grow() } - let ptr: &'a mut T = cast::transmute(this.ptr); + let ptr: &'a mut T = mem::transmute(this.ptr); mem::move_val_init(ptr, object); this.ptr = this.ptr.offset(1); let ptr: &'a T = ptr; diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 6763b32afd03b..3a797cc935461 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -21,10 +21,9 @@ // Backlinks over DList::prev are raw pointers that form a full chain in // the reverse direction. -use std::cast; use std::iter::Rev; use std::iter; -use std::mem::{replace, swap}; +use std::mem; use std::ptr; use deque::Deque; @@ -93,13 +92,13 @@ impl Rawlink { if self.p.is_null() { None } else { - Some(unsafe { cast::transmute(self.p) }) + Some(unsafe { mem::transmute(self.p) }) } } /// Return the `Rawlink` and replace with `Rawlink::none()` fn take(&mut self) -> Rawlink { - replace(self, Rawlink::none()) + mem::replace(self, Rawlink::none()) } } @@ -159,7 +158,7 @@ impl DList { Some(ref mut head) => { new_head.prev = Rawlink::none(); head.prev = Rawlink::some(new_head); - swap(head, &mut new_head); + mem::swap(head, &mut new_head); head.next = Some(new_head); } } @@ -317,7 +316,7 @@ impl DList { /// O(1) #[inline] pub fn prepend(&mut self, mut other: DList) { - swap(self, &mut other); + mem::swap(self, &mut other); self.append(other); } diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 8249faad19a08..41501f2d261ec 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -137,7 +137,7 @@ impl Iterator for Items { #[cfg(test)] mod test { - use std::cast; + use std::mem; use enum_set::{EnumSet, CLike}; @@ -153,7 +153,7 @@ mod test { } fn from_uint(v: uint) -> Foo { - unsafe { cast::transmute(v) } + unsafe { mem::transmute(v) } } } diff --git a/src/libcollections/lru_cache.rs b/src/libcollections/lru_cache.rs index 13297df902a07..c062fc74c1d0e 100644 --- a/src/libcollections/lru_cache.rs +++ b/src/libcollections/lru_cache.rs @@ -37,7 +37,6 @@ //! assert!(cache.get(&2).is_none()); //! ``` -use std::cast; use std::container::Container; use std::hash::Hash; use std::fmt; @@ -93,7 +92,7 @@ impl LruCache { let cache = LruCache { map: HashMap::new(), max_size: capacity, - head: unsafe{ cast::transmute(box mem::uninit::>()) }, + head: unsafe{ mem::transmute(box mem::uninit::>()) }, }; unsafe { (*cache.head).next = cache.head; @@ -241,11 +240,11 @@ impl Mutable for LruCache { impl Drop for LruCache { fn drop(&mut self) { unsafe { - let node: Box> = cast::transmute(self.head); + let node: Box> = mem::transmute(self.head); // Prevent compiler from trying to drop the un-initialized field in the sigil node. let box LruEntry { key: k, value: v, .. } = node; - cast::forget(k); - cast::forget(v); + mem::forget(k); + mem::forget(v); } } } diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 459015445eb6a..b0227fd60bfeb 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -20,7 +20,7 @@ //! value. `Box` adds the `move` method, which will unwrap a `Box` from the object. See //! the extension traits (`*Ext`) for the full details. -use cast::{transmute, transmute_copy}; +use mem::{transmute, transmute_copy}; use option::{Option, Some, None}; use owned::Box; use raw::TraitObject; diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs deleted file mode 100644 index cf99fdbd5d4c2..0000000000000 --- a/src/libcore/cast.rs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2012-2014 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. - -//! Unsafe casting functions - -use mem; -use intrinsics; -use ptr::copy_nonoverlapping_memory; - -/** - * Transform a value of one type into a value of another type. - * Both types must have the same size and alignment. - * - * # Example - * - * ```rust - * use std::cast; - * - * let v: &[u8] = unsafe { cast::transmute("L") }; - * assert!(v == [76u8]); - * ``` - */ -#[inline] -pub unsafe fn transmute(thing: T) -> U { - intrinsics::transmute(thing) -} - -/** - * Move a thing into the void - * - * The forget function will take ownership of the provided value but neglect - * to run any required cleanup or memory-management operations on it. - */ -#[inline] -pub unsafe fn forget(thing: T) { intrinsics::forget(thing); } - -/// Casts the value at `src` to U. The two types must have the same length. -#[inline] -pub unsafe fn transmute_copy(src: &T) -> U { - let mut dest: U = mem::uninit(); - let dest_ptr: *mut u8 = transmute(&mut dest); - let src_ptr: *u8 = transmute(src); - copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::()); - dest -} - -/// Coerce an immutable reference to be mutable. -#[inline] -#[deprecated="casting &T to &mut T is undefined behaviour: use Cell, RefCell or Unsafe"] -pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) } - -/// Coerce a reference to have an arbitrary associated lifetime. -#[inline] -pub unsafe fn transmute_lifetime<'a,'b,T>(ptr: &'a T) -> &'b T { - transmute(ptr) -} - -/// Coerce an immutable reference to be mutable. -#[inline] -pub unsafe fn transmute_mut_unsafe(ptr: *T) -> *mut T { - transmute(ptr) -} - -/// Coerce a mutable reference to have an arbitrary associated lifetime. -#[inline] -pub unsafe fn transmute_mut_lifetime<'a,'b,T>(ptr: &'a mut T) -> &'b mut T { - transmute(ptr) -} - -/// Transforms lifetime of the second pointer to match the first. -#[inline] -pub unsafe fn copy_lifetime<'a,S,T>(_ptr: &'a S, ptr: &T) -> &'a T { - transmute_lifetime(ptr) -} - -/// Transforms lifetime of the second pointer to match the first. -#[inline] -pub unsafe fn copy_mut_lifetime<'a,S,T>(_ptr: &'a mut S, ptr: &mut T) -> &'a mut T { - transmute_mut_lifetime(ptr) -} - -/// Transforms lifetime of the second pointer to match the first. -#[inline] -pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T { - transmute_lifetime(ptr) -} - - -/**************************************************************************** - * Tests - ****************************************************************************/ - -#[cfg(test)] -mod tests { - use cast::transmute; - use raw; - use realstd::str::StrAllocating; - - #[test] - fn test_transmute_copy() { - assert_eq!(1u, unsafe { ::cast::transmute_copy(&1) }); - } - - #[test] - fn test_transmute() { - unsafe { - let x = @100u8; - let x: *raw::Box = transmute(x); - assert!((*x).data == 100); - let _x: @int = transmute(x); - } - } - - #[test] - fn test_transmute2() { - unsafe { - assert_eq!(box [76u8], transmute("L".to_owned())); - } - } -} diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 1e31486c63f1c..7f2deb81f8c90 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -24,7 +24,7 @@ //! and, as such, should be performed via the `from_u32` function.. -use cast::transmute; +use mem::transmute; use option::{None, Option, Some}; use iter::{Iterator, range_step}; use unicode::{derived_property, property, general_category, decompose, conversions}; diff --git a/src/libcore/kinds.rs b/src/libcore/kinds.rs index 6ef71d3360a75..148b63dfbfeae 100644 --- a/src/libcore/kinds.rs +++ b/src/libcore/kinds.rs @@ -112,12 +112,12 @@ pub mod marker { /// but does not actually *reference* that type parameter: /// /// ```ignore - /// use std::cast; + /// use std::mem; /// /// struct S { x: *() } /// fn get(s: &S) -> T { /// unsafe { - /// let x: *T = cast::transmute(s.x); + /// let x: *T = mem::transmute(s.x); /// *x /// } /// } @@ -153,12 +153,12 @@ pub mod marker { /// but does not actually *reference* that type parameter: /// /// ``` - /// use std::cast; + /// use std::mem; /// /// struct S { x: *() } /// fn get(s: &S, v: T) { /// unsafe { - /// let x: fn(T) = cast::transmute(s.x); + /// let x: fn(T) = mem::transmute(s.x); /// x(v) /// } /// } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 38bce7a4741bf..41719d1354a16 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -63,7 +63,6 @@ pub mod prelude; /* Core modules for ownership management */ -pub mod cast; pub mod intrinsics; pub mod mem; pub mod ptr; diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 0bac90064d6f4..feb66f569645b 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -13,7 +13,6 @@ //! This module contains functions for querying the size and alignment of //! types, initializing and manipulating memory. -use cast; use ptr; use intrinsics; use intrinsics::{bswap16, bswap32, bswap64}; @@ -239,7 +238,7 @@ pub fn swap(x: &mut T, y: &mut T) { // y and t now point to the same thing, but we need to completely forget `t` // because it's no longer relevant. - cast::forget(t); + forget(t); } } @@ -286,14 +285,103 @@ pub fn replace(dest: &mut T, mut src: T) -> T { } /// Disposes of a value. +/// +/// This function can be used to destroy any value by allowing `drop` to take +/// ownership of its argument. +/// +/// # Example +/// +/// ``` +/// use std::cell::RefCell; +/// +/// let x = RefCell::new(1); +/// +/// let mut mutable_borrow = x.borrow_mut(); +/// *mutable_borrow = 1; +/// drop(mutable_borrow); // relinquish the mutable borrow on this slot +/// +/// let borrow = x.borrow(); +/// println!("{}", *borrow); +/// ``` #[inline] pub fn drop(_x: T) { } +/// Moves a thing into the void. +/// +/// The forget function will take ownership of the provided value but neglect +/// to run any required cleanup or memory management operations on it. +/// +/// This function is the unsafe version of the `drop` function because it does +/// not run any destructors. +#[inline] +#[stable] +pub unsafe fn forget(thing: T) { intrinsics::forget(thing) } + +/// Unsafely transforms a value of one type into a value of another type. +/// +/// Both types must have the same size and alignment, and this guarantee is +/// enforced at compile-time. +/// +/// # Example +/// +/// ```rust +/// use std::mem; +/// +/// let v: &[u8] = unsafe { mem::transmute("L") }; +/// assert!(v == [76u8]); +/// ``` +#[inline] +#[unstable = "this function will be modified to reject invocations of it which \ + cannot statically prove that T and U are the same size. For \ + example, this function, as written today, will be rejected in \ + the future because the size of T and U cannot be statically \ + known to be the same"] +pub unsafe fn transmute(thing: T) -> U { + intrinsics::transmute(thing) +} + +/// Interprets `src` as `&U`, and then reads `src` without moving the contained +/// value. +/// +/// This function will unsafely assume the pointer `src` is valid for +/// `sizeof(U)` bytes by transmuting `&T` to `&U` and then reading the `&U`. It +/// will also unsafely create a copy of the contained value instead of moving +/// out of `src`. +/// +/// It is not a compile-time error if `T` and `U` have different sizes, but it +/// is highly encouraged to only invoke this function where `T` and `U` have the +/// same size. This function triggers undefined behavior if `U` is larger than +/// `T`. +#[inline] +#[stable] +pub unsafe fn transmute_copy(src: &T) -> U { + ptr::read(src as *T as *U) +} + +/// Transforms lifetime of the second pointer to match the first. +#[inline] +#[unstable = "this function may be removed in the future due to its \ + questionable utility"] +pub unsafe fn copy_lifetime<'a, S, T>(_ptr: &'a S, ptr: &T) -> &'a T { + transmute(ptr) +} + +/// Transforms lifetime of the second mutable pointer to match the first. +#[inline] +#[unstable = "this function may be removed in the future due to its \ + questionable utility"] +pub unsafe fn copy_mut_lifetime<'a, S, T>(_ptr: &'a mut S, + ptr: &mut T) -> &'a mut T { + transmute(ptr) +} + #[cfg(test)] mod tests { use mem::*; use option::{Some,None}; use realstd::str::StrAllocating; + use owned::Box; + use raw; #[test] fn size_of_basic() { @@ -389,6 +477,28 @@ mod tests { assert!(x.is_none()); assert!(y.is_some()); } + + #[test] + fn test_transmute_copy() { + assert_eq!(1u, unsafe { ::mem::transmute_copy(&1) }); + } + + #[test] + fn test_transmute() { + trait Foo {} + impl Foo for int {} + + let a = box 100 as Box; + unsafe { + let x: raw::TraitObject = transmute(a); + assert!(*(x.data as *int) == 100); + let _x: Box = transmute(x); + } + + unsafe { + assert_eq!(box [76u8], transmute("L".to_owned())); + } + } } // FIXME #13642 (these benchmarks should be in another place) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 2f8457e93f671..fd6d174a7036e 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -604,10 +604,10 @@ mod tests { fn test_get_ptr() { unsafe { let x = box 0; - let addr_x: *int = ::cast::transmute(&*x); + let addr_x: *int = ::mem::transmute(&*x); let opt = Some(x); let y = opt.unwrap(); - let addr_y: *int = ::cast::transmute(&*y); + let addr_y: *int = ::mem::transmute(&*y); assert_eq!(addr_x, addr_y); } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index bb587c0e42d03..438e18d999b6c 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -52,18 +52,18 @@ //! though unsafely, transformed from one type to the other. //! //! ``` -//! use std::cast; +//! use std::mem; //! //! unsafe { //! let my_num: Box = box 10; -//! let my_num: *int = cast::transmute(my_num); +//! let my_num: *int = mem::transmute(my_num); //! let my_speed: Box = box 88; -//! let my_speed: *mut int = cast::transmute(my_speed); +//! let my_speed: *mut int = mem::transmute(my_speed); //! //! // By taking ownership of the original `Box` though //! // we are obligated to transmute it back later to be destroyed. -//! drop(cast::transmute::<_, Box>(my_speed)); -//! drop(cast::transmute::<_, Box>(my_num)); +//! drop(mem::transmute::<_, Box>(my_speed)); +//! drop(mem::transmute::<_, Box>(my_num)); //! } //! ``` //! @@ -92,11 +92,10 @@ //! but C APIs hand out a lot of pointers generally, so are a common source //! of unsafe pointers in Rust. -use cast; +use mem; use clone::Clone; use intrinsics; use iter::{range, Iterator}; -use mem; use option::{Some, None, Option}; #[cfg(not(test))] use cmp::{Eq, TotalEq, Ord, Equiv}; @@ -196,7 +195,6 @@ pub unsafe fn copy_memory(dst: *mut T, src: *T, count: uint) { /// A safe swap function: /// /// ``` -/// use std::cast; /// use std::mem; /// use std::ptr; /// @@ -212,7 +210,7 @@ pub unsafe fn copy_memory(dst: *mut T, src: *T, count: uint) { /// /// // y and t now point to the same thing, but we need to completely forget `tmp` /// // because it's no longer relevant. -/// cast::forget(t); +/// mem::forget(t); /// } /// } /// ``` @@ -256,14 +254,14 @@ pub unsafe fn swap(x: *mut T, y: *mut T) { // y and t now point to the same thing, but we need to completely forget `tmp` // because it's no longer relevant. - cast::forget(tmp); + mem::forget(tmp); } /// Replace the value at a mutable location with a new one, returning the old /// value, without deinitialising either. #[inline] pub unsafe fn replace(dest: *mut T, mut src: T) -> T { - mem::swap(cast::transmute(dest), &mut src); // cannot overlap + mem::swap(mem::transmute(dest), &mut src); // cannot overlap src } @@ -361,7 +359,7 @@ impl RawPtr for *T { if self.is_null() { None } else { - Some(cast::transmute(*self)) + Some(mem::transmute(*self)) } } } @@ -386,7 +384,7 @@ impl RawPtr for *mut T { if self.is_null() { None } else { - Some(cast::transmute(*self)) + Some(mem::transmute(*self)) } } } @@ -436,14 +434,14 @@ impl Equiv<*T> for *mut T { // Equality for extern "C" fn pointers #[cfg(not(test))] mod externfnpointers { - use cast; + use mem; use cmp::Eq; impl<_R> Eq for extern "C" fn() -> _R { #[inline] fn eq(&self, other: &extern "C" fn() -> _R) -> bool { - let self_: *() = unsafe { cast::transmute(*self) }; - let other_: *() = unsafe { cast::transmute(*other) }; + let self_: *() = unsafe { mem::transmute(*self) }; + let other_: *() = unsafe { mem::transmute(*other) }; self_ == other_ } } @@ -452,8 +450,8 @@ mod externfnpointers { impl<_R,$($p),*> Eq for extern "C" fn($($p),*) -> _R { #[inline] fn eq(&self, other: &extern "C" fn($($p),*) -> _R) -> bool { - let self_: *() = unsafe { cast::transmute(*self) }; - let other_: *() = unsafe { cast::transmute(*other) }; + let self_: *() = unsafe { mem::transmute(*self) }; + let other_: *() = unsafe { mem::transmute(*other) }; self_ == other_ } } @@ -485,7 +483,7 @@ pub mod ptr_tests { use realstd::prelude::*; use realstd::c_str::ToCStr; - use cast; + use mem; use libc; use realstd::str; use slice::{ImmutableVector, MutableVector}; @@ -499,7 +497,7 @@ pub mod ptr_tests { }; let mut p = Pair {fst: 10, snd: 20}; let pptr: *mut Pair = &mut p; - let iptr: *mut int = cast::transmute(pptr); + let iptr: *mut int = mem::transmute(pptr); assert_eq!(*iptr, 10); *iptr = 30; assert_eq!(*iptr, 30); diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index d6caa145ae9c8..25f40b358ab25 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -18,7 +18,7 @@ //! //! Their definition should always match the ABI defined in `rustc::back::abi`. -use cast; +use mem; /// The representation of a Rust managed box pub struct Box { @@ -74,7 +74,7 @@ pub trait Repr { /// for the struct. This is a safe method because by default it does not /// enable write-access to the fields of the return value in safe code. #[inline] - fn repr(&self) -> T { unsafe { cast::transmute_copy(self) } } + fn repr(&self) -> T { unsafe { mem::transmute_copy(self) } } } impl<'a, T> Repr> for &'a [T] {} @@ -87,7 +87,7 @@ impl Repr<*String> for ~str {} mod tests { use super::*; - use cast; + use mem; #[test] fn synthesize_closure() { @@ -97,7 +97,7 @@ mod tests { assert_eq!(f(20), 30); - let original_closure: Closure = cast::transmute(f); + let original_closure: Closure = mem::transmute(f); let actual_function_pointer = original_closure.code; let environment = original_closure.env; @@ -107,7 +107,7 @@ mod tests { env: environment }; - let new_f: |int| -> int = cast::transmute(new_closure); + let new_f: |int| -> int = mem::transmute(new_closure); assert_eq!(new_f(20), 30); } } diff --git a/src/libcore/should_not_exist.rs b/src/libcore/should_not_exist.rs index f199aa051d166..d8df20218c5ad 100644 --- a/src/libcore/should_not_exist.rs +++ b/src/libcore/should_not_exist.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use cast; use char::Char; use clone::Clone; use container::Container; @@ -73,7 +72,7 @@ impl Default for ~str { (*ptr).fill = 0; (*ptr).alloc = 0; - cast::transmute(ptr) + mem::transmute(ptr) } } } @@ -91,7 +90,7 @@ impl Clone for ~str { (*ptr).fill = len; (*ptr).alloc = len; - cast::transmute(ptr) + mem::transmute(ptr) } } } @@ -106,7 +105,7 @@ impl FromIterator for ~str { unsafe { let mut ptr = alloc(cap) as *mut Vec; - let mut ret = cast::transmute(ptr); + let mut ret = mem::transmute(ptr); for ch in iterator { let amt = ch.encode_utf8(tmp); @@ -121,8 +120,8 @@ impl FromIterator for ~str { len); // FIXME: #13994: port to the sized deallocation API when available rust_free(ptr as *u8, 0, 8); - cast::forget(ret); - ret = cast::transmute(ptr2); + mem::forget(ret); + ret = mem::transmute(ptr2); ptr = ptr2; } @@ -155,7 +154,7 @@ impl<'a> Add<&'a str,~str> for &'a str { rhs.len()); (*ptr).fill = amt; (*ptr).alloc = amt; - cast::transmute(ptr) + mem::transmute(ptr) } } } @@ -192,7 +191,7 @@ impl Clone for ~[A] { } rust_free(ret as *u8, 0, 8); }); - cast::transmute(ret) + mem::transmute(ret) } } } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index b828ad3361eff..11309b44a6006 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -12,8 +12,7 @@ //! //! For more details `std::slice`. -use cast; -use cast::transmute; +use mem::transmute; use clone::Clone; use container::Container; use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater}; @@ -1012,7 +1011,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { fn mut_split_at(self, mid: uint) -> (&'a mut [T], &'a mut [T]) { unsafe { let len = self.len(); - let self2: &'a mut [T] = cast::transmute_copy(&self); + let self2: &'a mut [T] = mem::transmute_copy(&self); (self.mut_slice(0, mid), self2.mut_slice(mid, len)) } } @@ -1162,7 +1161,7 @@ impl<'a, T:Clone> MutableCloneableVector for &'a mut [T] { /// Unsafe operations pub mod raw { - use cast::transmute; + use mem::transmute; use iter::Iterator; use ptr::RawPtr; use raw::Slice; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 689f59b471c90..e677c4880b58d 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -12,8 +12,7 @@ //! //! For more details, see std::str -use cast::transmute; -use cast; +use mem; use char; use clone::Clone; use cmp::{Eq, TotalEq}; @@ -572,7 +571,7 @@ impl<'a> Iterator for UTF16Items<'a> { if u < 0xD800 || 0xDFFF < u { // not a surrogate - Some(ScalarValue(unsafe {cast::transmute(u as u32)})) + Some(ScalarValue(unsafe {mem::transmute(u as u32)})) } else if u >= 0xDC00 { // a trailing surrogate Some(LoneSurrogate(u)) @@ -594,7 +593,7 @@ impl<'a> Iterator for UTF16Items<'a> { // all ok, so lets decode it. let c = ((u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32) + 0x1_0000; - Some(ScalarValue(unsafe {cast::transmute(c)})) + Some(ScalarValue(unsafe {mem::transmute(c)})) } } @@ -710,7 +709,7 @@ static TAG_CONT_U8: u8 = 128u8; /// Unsafe operations pub mod raw { - use cast; + use mem; use container::Container; use iter::Iterator; use ptr::RawPtr; @@ -721,7 +720,7 @@ pub mod raw { /// Converts a slice of bytes to a string slice without checking /// that the string contains valid UTF-8. pub unsafe fn from_utf8<'a>(v: &'a [u8]) -> &'a str { - cast::transmute(v) + mem::transmute(v) } /// Form a slice from a C string. Unsafe because the caller must ensure the @@ -736,8 +735,8 @@ pub mod raw { curr = s.offset(len as int); } let v = Slice { data: s, len: len }; - assert!(is_utf8(::cast::transmute(v))); - ::cast::transmute(v) + assert!(is_utf8(::mem::transmute(v))); + ::mem::transmute(v) } /// Takes a bytewise (not UTF-8) slice from a string. @@ -762,7 +761,7 @@ pub mod raw { /// Caller must check slice boundaries! #[inline] pub unsafe fn slice_unchecked<'a>(s: &'a str, begin: uint, end: uint) -> &'a str { - cast::transmute(Slice { + mem::transmute(Slice { data: s.as_ptr().offset(begin as int), len: end - begin, }) @@ -1747,7 +1746,7 @@ impl<'a> StrSlice<'a> for &'a str { if w > 2 { val = utf8_acc_cont_byte!(val, s[i + 2]); } if w > 3 { val = utf8_acc_cont_byte!(val, s[i + 3]); } - return CharRange {ch: unsafe { transmute(val) }, next: i + w}; + return CharRange {ch: unsafe { mem::transmute(val) }, next: i + w}; } return multibyte_char_range_at(*self, i); @@ -1776,7 +1775,7 @@ impl<'a> StrSlice<'a> for &'a str { if w > 2 { val = utf8_acc_cont_byte!(val, s[i + 2]); } if w > 3 { val = utf8_acc_cont_byte!(val, s[i + 3]); } - return CharRange {ch: unsafe { transmute(val) }, next: i}; + return CharRange {ch: unsafe { mem::transmute(val) }, next: i}; } return multibyte_char_range_at_reverse(*self, prev); @@ -1794,7 +1793,7 @@ impl<'a> StrSlice<'a> for &'a str { #[inline] fn as_bytes(&self) -> &'a [u8] { - unsafe { cast::transmute(*self) } + unsafe { mem::transmute(*self) } } fn find(&self, mut search: C) -> Option { diff --git a/src/libcore/ty.rs b/src/libcore/ty.rs index 0c9f0b02fdf0a..47a2005fef1e6 100644 --- a/src/libcore/ty.rs +++ b/src/libcore/ty.rs @@ -10,7 +10,6 @@ //! Types dealing with unsafe actions. -use cast; use kinds::marker; /// Unsafe type that wraps a type T and indicates unsafe interior operations on the @@ -63,7 +62,7 @@ impl Unsafe { /// Gets a mutable pointer to the wrapped value #[inline] - pub unsafe fn get(&self) -> *mut T { cast::transmute_mut_unsafe(&self.value) } + pub unsafe fn get(&self) -> *mut T { &self.value as *T as *mut T } /// Unwraps the value #[inline] diff --git a/src/libgreen/basic.rs b/src/libgreen/basic.rs index eba15e6e6d5a8..9e42e2f67c485 100644 --- a/src/libgreen/basic.rs +++ b/src/libgreen/basic.rs @@ -15,8 +15,7 @@ //! This implementation is also used as the fallback implementation of an event //! loop if no other one is provided (and M:N scheduling is desired). -use std::cast; -use std::mem::replace; +use std::mem; use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback}; use std::rt::rtio::{PausableIdleCallback, Callback}; use std::unstable::sync::Exclusive; @@ -50,7 +49,7 @@ impl BasicLoop { /// Process everything in the work queue (continually) fn work(&mut self) { while self.work.len() > 0 { - for work in replace(&mut self.work, vec![]).move_iter() { + for work in mem::replace(&mut self.work, vec![]).move_iter() { work(); } } @@ -60,7 +59,7 @@ impl BasicLoop { let messages = unsafe { self.messages.with(|messages| { if messages.len() > 0 { - Some(replace(messages, vec![])) + Some(mem::replace(messages, vec![])) } else { None } @@ -145,7 +144,7 @@ impl EventLoop for BasicLoop { let callback = box BasicPausable::new(self, cb); rtassert!(self.idle.is_none()); unsafe { - let cb_ptr: &*mut BasicPausable = cast::transmute(&callback); + let cb_ptr: &*mut BasicPausable = mem::transmute(&callback); self.idle = Some(*cb_ptr); } callback as Box diff --git a/src/libgreen/context.rs b/src/libgreen/context.rs index e5dd9c92358f0..0a13ffa0b5e31 100644 --- a/src/libgreen/context.rs +++ b/src/libgreen/context.rs @@ -10,7 +10,7 @@ use stack::Stack; use std::uint; -use std::cast::{transmute, transmute_mut_unsafe}; +use std::mem::transmute; use std::rt::stack; use std::raw; @@ -50,7 +50,7 @@ impl Context { stack: &mut Stack) -> Context { let sp: *uint = stack.end(); - let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) }; + let sp: *mut uint = sp as *mut uint; // Save and then immediately load the current context, // which we will then modify to call the given function when restored let mut regs = new_regs(); diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index 301198a067640..8c294fa2928f0 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; +use std::mem; use std::rt::local::Local; use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop}; use std::rt::task::BlockedTask; @@ -633,7 +633,7 @@ impl Scheduler { unsafe { let sched: &mut Scheduler = - cast::transmute_mut_lifetime(*next_task.sched.get_mut_ref()); + mem::transmute(&**next_task.sched.get_mut_ref()); let current_task: &mut GreenTask = match sched.cleanup_job { Some(CleanupJob { task: ref mut task, .. }) => &mut **task, @@ -647,7 +647,7 @@ impl Scheduler { // works because due to transmute the borrow checker // believes that we have no internal pointers to // next_task. - cast::forget(next_task); + mem::forget(next_task); // The raw context swap operation. The next action taken // will be running the cleanup job from the context of the @@ -659,7 +659,7 @@ impl Scheduler { // run the cleanup job, as expected by the previously called // swap_contexts function. let mut current_task: Box = unsafe { - cast::transmute(current_task_dupe) + mem::transmute(current_task_dupe) }; current_task.sched.get_mut_ref().run_cleanup_job(); @@ -677,15 +677,17 @@ impl Scheduler { // references to keep even when we don't own the tasks. It looks // kinda safe because we are doing transmutes before passing in // the arguments. - pub fn get_contexts<'a>(current_task: &mut GreenTask, next_task: &mut GreenTask) -> - (&'a mut Context, &'a mut Context) { + pub fn get_contexts<'a>(current_task: &mut GreenTask, + next_task: &mut GreenTask) + -> (&'a mut Context, &'a mut Context) + { let current_task_context = &mut current_task.coroutine.get_mut_ref().saved_context; let next_task_context = &mut next_task.coroutine.get_mut_ref().saved_context; unsafe { - (cast::transmute_mut_lifetime(current_task_context), - cast::transmute_mut_lifetime(next_task_context)) + (mem::transmute(current_task_context), + mem::transmute(next_task_context)) } } @@ -961,10 +963,10 @@ trait ClosureConverter { } impl ClosureConverter for UnsafeTaskReceiver { fn from_fn(f: |&mut Scheduler, Box|) -> UnsafeTaskReceiver { - unsafe { cast::transmute(f) } + unsafe { mem::transmute(f) } } fn to_fn(self) -> |&mut Scheduler, Box| { - unsafe { cast::transmute(self) } + unsafe { mem::transmute(self) } } } diff --git a/src/libgreen/simple.rs b/src/libgreen/simple.rs index 007084fa14d78..49aef15f93b61 100644 --- a/src/libgreen/simple.rs +++ b/src/libgreen/simple.rs @@ -12,7 +12,7 @@ //! scheduler pool and then interacting with it. use std::any::Any; -use std::cast; +use std::mem; use std::rt::Runtime; use std::rt::local::Local; use std::rt::rtio; @@ -48,10 +48,10 @@ impl Runtime for SimpleTask { guard.wait(); } } - Err(task) => { cast::forget(task.wake()); } + Err(task) => { mem::forget(task.wake()); } } drop(guard); - cur_task = cast::transmute(cur_dupe); + cur_task = mem::transmute(cur_dupe); } Local::put(cur_task); } @@ -59,7 +59,7 @@ impl Runtime for SimpleTask { let me = &mut *self as *mut SimpleTask; to_wake.put_runtime(self); unsafe { - cast::forget(to_wake); + mem::forget(to_wake); let guard = (*me).lock.lock(); (*me).awoken = true; guard.signal(); diff --git a/src/libgreen/task.rs b/src/libgreen/task.rs index bc7752e98ea5e..f50f65af6f9eb 100644 --- a/src/libgreen/task.rs +++ b/src/libgreen/task.rs @@ -19,7 +19,7 @@ //! values. use std::any::Any; -use std::cast; +use std::mem; use std::raw; use std::rt::Runtime; use std::rt::env; @@ -93,11 +93,11 @@ pub enum Home { extern fn bootstrap_green_task(task: uint, code: *(), env: *()) -> ! { // Acquire ownership of the `proc()` let start: proc() = unsafe { - cast::transmute(raw::Procedure { code: code, env: env }) + mem::transmute(raw::Procedure { code: code, env: env }) }; // Acquire ownership of the `Box` - let mut task: Box = unsafe { cast::transmute(task) }; + let mut task: Box = unsafe { mem::transmute(task) }; // First code after swap to this new context. Run our cleanup job task.pool_id = { @@ -271,7 +271,7 @@ impl GreenTask { } pub unsafe fn from_uint(val: uint) -> Box { - cast::transmute(val) + mem::transmute(val) } // Runtime glue functions and helpers diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 09e9cd83f3d4f..dbff4150d7274 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -118,10 +118,10 @@ if logging is disabled, none of the components of the log will be executed. extern crate sync; -use std::cast; use std::fmt; use std::io::LineBufferedWriter; use std::io; +use std::mem; use std::os; use std::rt; use std::slice; @@ -343,13 +343,13 @@ fn init() { LOG_LEVEL = max_level; assert!(DIRECTIVES.is_null()); - DIRECTIVES = cast::transmute(box directives); + DIRECTIVES = mem::transmute(box directives); // Schedule the cleanup for this global for when the runtime exits. rt::at_exit(proc() { assert!(!DIRECTIVES.is_null()); let _directives: Box> = - cast::transmute(DIRECTIVES); + mem::transmute(DIRECTIVES); DIRECTIVES = 0 as *Vec; }); } diff --git a/src/libnative/io/addrinfo.rs b/src/libnative/io/addrinfo.rs index 57b87f21521e8..8ebae70f73c04 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 5fc9e506cf267..fc08a7f128fec 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 218f8a4ef4994..40b66cc526f2a 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::() } 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::()); 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::()); 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 36ae2ba06d52b..d66075f44190d 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::() >= mem::size_of::()); 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 c83af20d1d84e..81c76bba7a0eb 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(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 3bf967cb4263c..95b2620f3c798 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)) { 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> = cast::transmute(HELPER_CHAN); + let _chan: Box> = mem::transmute(HELPER_CHAN); HELPER_CHAN = 0 as *mut Sender; HELPER_SIGNAL = 0 as imp::signal; } diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index 4c0c4dcc18e9e..0df45f7d5a0a9 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 d5b02dc007b90..4183dec19d02d 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(); diff --git a/src/librand/distributions/exponential.rs b/src/librand/distributions/exponential.rs index 05d0160cfe9dc..03c87eb931d60 100644 --- a/src/librand/distributions/exponential.rs +++ b/src/librand/distributions/exponential.rs @@ -18,7 +18,7 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample}; /// /// See `Exp` for the general exponential distribution.Note that this // has to be unwrapped before use as an `f64` (using either -/// `*` or `cast::transmute` is safe). +/// `*` or `mem::transmute` is safe). /// /// Implemented via the ZIGNOR variant[1] of the Ziggurat method. The /// exact description in the paper was adjusted to use tables for the diff --git a/src/librand/distributions/normal.rs b/src/librand/distributions/normal.rs index 5755ad00223eb..dea73945b4384 100644 --- a/src/librand/distributions/normal.rs +++ b/src/librand/distributions/normal.rs @@ -19,7 +19,7 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample}; /// /// See `Normal` for the general normal distribution. That this has to /// be unwrapped before use as an `f64` (using either `*` or -/// `cast::transmute` is safe). +/// `mem::transmute` is safe). /// /// Implemented via the ZIGNOR variant[1] of the Ziggurat method. /// diff --git a/src/librand/lib.rs b/src/librand/lib.rs index cb27f2f0ff821..006c4d89e2f85 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -76,9 +76,9 @@ println!("{:?}", tuple_ptr) #[cfg(test)] #[phase(syntax, link)] extern crate log; -use std::cast; use std::io::IoResult; use std::kinds::marker; +use std::mem; use std::strbuf::StrBuf; pub use isaac::{IsaacRng, Isaac64Rng}; @@ -454,11 +454,11 @@ impl<'a> SeedableRng<&'a [uint]> for StdRng { fn reseed(&mut self, seed: &'a [uint]) { // the internal RNG can just be seeded from the above // randomness. - self.rng.reseed(unsafe {cast::transmute(seed)}) + self.rng.reseed(unsafe {mem::transmute(seed)}) } fn from_seed(seed: &'a [uint]) -> StdRng { - StdRng { rng: SeedableRng::from_seed(unsafe {cast::transmute(seed)}) } + StdRng { rng: SeedableRng::from_seed(unsafe {mem::transmute(seed)}) } } } @@ -547,7 +547,7 @@ impl XorShiftRng { break; } } - let s: [u32, ..4] = unsafe { cast::transmute(s) }; + let s: [u32, ..4] = unsafe { mem::transmute(s) }; Ok(SeedableRng::from_seed(s)) } } diff --git a/src/librand/os.rs b/src/librand/os.rs index ed4c7299dffb8..f41d7a628631c 100644 --- a/src/librand/os.rs +++ b/src/librand/os.rs @@ -61,8 +61,8 @@ mod imp { extern crate libc; use Rng; - use std::cast; use std::io::{IoResult, IoError}; + use std::mem; use std::os; use std::rt::stack; use self::libc::{c_ulong, DWORD, BYTE, LPCSTR, BOOL}; @@ -156,12 +156,12 @@ mod imp { fn next_u32(&mut self) -> u32 { let mut v = [0u8, .. 4]; self.fill_bytes(v); - unsafe { cast::transmute(v) } + unsafe { mem::transmute(v) } } fn next_u64(&mut self) -> u64 { let mut v = [0u8, .. 8]; self.fill_bytes(v); - unsafe { cast::transmute(v) } + unsafe { mem::transmute(v) } } fn fill_bytes(&mut self, v: &mut [u8]) { let ret = unsafe { diff --git a/src/librand/reader.rs b/src/librand/reader.rs index d098c2cf0c144..184146d9a29c8 100644 --- a/src/librand/reader.rs +++ b/src/librand/reader.rs @@ -72,14 +72,14 @@ impl Rng for ReaderRng { mod test { use super::ReaderRng; use std::io::MemReader; - use std::cast; + use std::mem; use Rng; #[test] fn test_reader_rng_u64() { // transmute from the target to avoid endianness concerns. let v = box [1u64, 2u64, 3u64]; - let bytes: ~[u8] = unsafe {cast::transmute(v)}; + let bytes: ~[u8] = unsafe {mem::transmute(v)}; let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect())); assert_eq!(rng.next_u64(), 1); @@ -90,7 +90,7 @@ mod test { fn test_reader_rng_u32() { // transmute from the target to avoid endianness concerns. let v = box [1u32, 2u32, 3u32]; - let bytes: ~[u8] = unsafe {cast::transmute(v)}; + let bytes: ~[u8] = unsafe {mem::transmute(v)}; let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect())); assert_eq!(rng.next_u32(), 1); diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index 7ecea29db2ead..a0b38700ecf0a 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -15,14 +15,14 @@ use driver::session::Session; use metadata::filesearch; use lib::llvm::{ArchiveRef, llvm}; -use std::cast; -use std::io; -use std::io::{fs, TempDir}; use libc; -use std::os; use std::io::process::{ProcessConfig, Process, ProcessOutput}; -use std::str; +use std::io::{fs, TempDir}; +use std::io; +use std::mem; +use std::os; use std::raw; +use std::str; use syntax::abi; pub static METADATA_FILENAME: &'static str = "rust.metadata.bin"; @@ -230,7 +230,7 @@ impl ArchiveRO { if ptr.is_null() { None } else { - Some(cast::transmute(raw::Slice { + Some(mem::transmute(raw::Slice { data: ptr, len: size as uint, })) diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 26f5ead37bec8..518dc4b05ca20 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -10,7 +10,7 @@ #![allow(non_camel_case_types)] -use std::cast; +use std::mem; use syntax::crateid::CrateId; use back::svh::Svh; @@ -147,7 +147,7 @@ impl astencode_tag { pub fn from_uint(value : uint) -> Option { let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag; if !is_a_tag { None } else { - Some(unsafe { cast::transmute(value) }) + Some(unsafe { mem::transmute(value) }) } } } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 5faae72791d7e..70f740f7557e1 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -27,7 +27,7 @@ use middle; use util::nodemap::{NodeMap, NodeSet}; use serialize::Encodable; -use std::cast; +use std::mem; use std::cell::RefCell; use std::hash; use std::hash::Hash; @@ -1247,7 +1247,7 @@ fn my_visit_item(i: &Item, index: &mut Vec>) { let mut ebml_w = unsafe { ebml_w.unsafe_clone() }; // See above - let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; + let ecx: &EncodeContext = unsafe { mem::transmute(ecx_ptr) }; ecx.tcx.map.with_path(i.id, |path| { encode_info_for_item(ecx, &mut ebml_w, i, index, path, i.vis); }); @@ -1258,7 +1258,7 @@ fn my_visit_foreign_item(ni: &ForeignItem, ecx_ptr:*int, index: &mut Vec>) { // See above - let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; + let ecx: &EncodeContext = unsafe { mem::transmute(ecx_ptr) }; debug!("writing foreign item {}::{}", ecx.tcx.map.path_to_str(ni.id), token::get_ident(ni.ident)); @@ -1320,7 +1320,7 @@ fn encode_info_for_items(ecx: &EncodeContext, Public); // See comment in `encode_side_tables_for_ii` in astencode - let ecx_ptr: *int = unsafe { cast::transmute(ecx) }; + let ecx_ptr: *int = unsafe { mem::transmute(ecx) }; visit::walk_crate(&mut EncodeVisitor { index: &mut index, ecx_ptr: ecx_ptr, diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index ebe3ce69dabe9..c872df3deade9 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -25,9 +25,9 @@ use syntax::attr::AttrMetaMethods; use util::fs; use std::c_str::ToCStr; -use std::cast; use std::cmp; use std::io; +use std::mem; use std::ptr; use std::slice; use std::str; @@ -469,7 +469,7 @@ impl ArchiveMetadata { // Hence, we're guaranteed that the buffer will never be used after // this object is dead, so this is a safe operation to transmute and // store the data as a static buffer. - unsafe { cast::transmute(data) } + unsafe { mem::transmute(data) } }; Some(ArchiveMetadata { archive: ar, @@ -532,7 +532,7 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Result ast_util::IdVisitingOperation for }; // See above let ecx: &e::EncodeContext = unsafe { - cast::transmute(self.ecx_ptr) + mem::transmute(self.ecx_ptr) }; encode_side_tables_for_id(ecx, &mut new_ebml_w, id) } @@ -932,7 +932,7 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext, // tied to the CrateContext that lives throughout this entire section. ast_util::visit_ids_for_inlined_item(ii, &SideTableEncodingIdVisitor { ecx_ptr: unsafe { - cast::transmute(ecx) + mem::transmute(ecx) }, new_ebml_w: &mut new_ebml_w, }); diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 518dcff42bfea..0ca1a07e1a370 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -109,7 +109,7 @@ use middle::pat_util; use middle::ty; use util::nodemap::NodeMap; -use std::cast::transmute; +use std::mem::transmute; use std::fmt; use std::io; use std::rc::Rc; diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index e49e9539980f4..a0744037dc008 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -19,7 +19,7 @@ use syntax::ast; use syntax::abi::{X86, X86_64, Arm, Mips}; use std::c_str::ToCStr; -use std::cast; +use std::mem; use libc::{c_uint}; @@ -140,19 +140,19 @@ impl Type { } pub fn func(args: &[Type], ret: &Type) -> Type { - let vec : &[TypeRef] = unsafe { cast::transmute(args) }; + let vec : &[TypeRef] = unsafe { mem::transmute(args) }; ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(), args.len() as c_uint, False)) } pub fn variadic_func(args: &[Type], ret: &Type) -> Type { - let vec : &[TypeRef] = unsafe { cast::transmute(args) }; + let vec : &[TypeRef] = unsafe { mem::transmute(args) }; ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(), args.len() as c_uint, True)) } pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type { - let els : &[TypeRef] = unsafe { cast::transmute(els) }; + let els : &[TypeRef] = unsafe { mem::transmute(els) }; ty!(llvm::LLVMStructTypeInContext(ccx.llcx, els.as_ptr(), els.len() as c_uint, packed as Bool)) @@ -245,7 +245,7 @@ impl Type { pub fn set_struct_body(&mut self, els: &[Type], packed: bool) { unsafe { - let vec : &[TypeRef] = cast::transmute(els); + let vec : &[TypeRef] = mem::transmute(els); llvm::LLVMStructSetBody(self.to_ref(), vec.as_ptr(), els.len() as c_uint, packed as Bool) } @@ -281,7 +281,7 @@ impl Type { } let mut elts = Vec::from_elem(n_elts, 0 as TypeRef); llvm::LLVMGetStructElementTypes(self.to_ref(), elts.get_mut(0)); - cast::transmute(elts) + mem::transmute(elts) } } @@ -294,7 +294,7 @@ impl Type { let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as uint; let args = Vec::from_elem(n_args, 0 as TypeRef); llvm::LLVMGetParamTypes(self.to_ref(), args.as_ptr()); - cast::transmute(args) + mem::transmute(args) } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index e61961f999c8e..f37a4ab0aaa4a 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -34,13 +34,13 @@ use util::ppaux::{Repr, UserString}; use util::common::{indenter}; use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet, FnvHashMap}; -use std::cast; use std::cell::{Cell, RefCell}; use std::cmp; use std::fmt::Show; use std::fmt; use std::hash::{Hash, sip}; use std::iter::AdditiveIterator; +use std::mem; use std::ops; use std::rc::Rc; use collections::{HashMap, HashSet}; @@ -394,7 +394,7 @@ impl fmt::Show for t { pub fn get(t: t) -> t_box { unsafe { - let t2: t_box = cast::transmute(t); + let t2: t_box = mem::transmute(t); t2 } } @@ -854,7 +854,7 @@ impl CLike for BuiltinBound { *self as uint } fn from_uint(v: uint) -> BuiltinBound { - unsafe { cast::transmute(v) } + unsafe { mem::transmute(v) } } } @@ -1158,7 +1158,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t { let key = intern_key { sty: &st }; match cx.interner.borrow().find(&key) { - Some(t) => unsafe { return cast::transmute(&t.sty); }, + Some(t) => unsafe { return mem::transmute(&t.sty); }, _ => () } @@ -1259,14 +1259,14 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t { cx.next_id.set(cx.next_id.get() + 1); unsafe { - cast::transmute::<*sty, t>(sty_ptr) + mem::transmute::<*sty, t>(sty_ptr) } } #[inline] pub fn mk_prim_t(primitive: &'static t_box_) -> t { unsafe { - cast::transmute::<&'static t_box_, t>(primitive) + mem::transmute::<&'static t_box_, t>(primitive) } } diff --git a/src/librustuv/access.rs b/src/librustuv/access.rs index 433073b43c44a..81ddc9d32eb2c 100644 --- a/src/librustuv/access.rs +++ b/src/librustuv/access.rs @@ -14,7 +14,7 @@ /// It is assumed that all invocations of this struct happen on the same thread /// (the uv event loop). -use std::cast; +use std::mem; use std::rt::local::Local; use std::rt::task::{BlockedTask, Task}; use std::sync::arc::UnsafeArc; @@ -110,7 +110,7 @@ impl<'a> Drop for Guard<'a> { // on the same I/O event loop, so this unsafety should be ok. assert!(self.missile.is_some()); let inner: &mut Inner = unsafe { - cast::transmute(self.access.inner.get()) + mem::transmute(self.access.inner.get()) }; match inner.queue.shift() { diff --git a/src/librustuv/addrinfo.rs b/src/librustuv/addrinfo.rs index 4766630b0f421..1e18f2ea9ec25 100644 --- a/src/librustuv/addrinfo.rs +++ b/src/librustuv/addrinfo.rs @@ -9,9 +9,9 @@ // except according to those terms. use ai = std::io::net::addrinfo; -use std::cast; -use libc; use libc::c_int; +use libc; +use std::mem; use std::ptr::null; use std::rt::task::BlockedTask; @@ -140,7 +140,7 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> Vec { let mut addrs = Vec::new(); loop { - let rustaddr = net::sockaddr_to_addr(cast::transmute((*addr).ai_addr), + let rustaddr = net::sockaddr_to_addr(mem::transmute((*addr).ai_addr), (*addr).ai_addrlen as uint); let mut flags = 0; diff --git a/src/librustuv/async.rs b/src/librustuv/async.rs index 155dee3cfa82c..7a16baaa9f2a6 100644 --- a/src/librustuv/async.rs +++ b/src/librustuv/async.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; +use std::mem; use std::rt::rtio::{Callback, RemoteCallback}; use std::unstable::sync::Exclusive; @@ -39,7 +39,7 @@ impl AsyncWatcher { let flag = Exclusive::new(false); let payload = box Payload { callback: cb, exit_flag: flag.clone() }; unsafe { - let payload: *u8 = cast::transmute(payload); + let payload: *u8 = mem::transmute(payload); uvll::set_data_for_uv_handle(handle, payload); } return AsyncWatcher { handle: handle, exit_flag: flag, }; @@ -55,7 +55,7 @@ impl UvHandle for AsyncWatcher { extern fn async_cb(handle: *uvll::uv_async_t) { let payload: &mut Payload = unsafe { - cast::transmute(uvll::get_data_for_uv_handle(handle)) + mem::transmute(uvll::get_data_for_uv_handle(handle)) }; // The synchronization logic here is subtle. To review, @@ -94,7 +94,7 @@ extern fn async_cb(handle: *uvll::uv_async_t) { extern fn close_cb(handle: *uvll::uv_handle_t) { // drop the payload let _payload: Box = unsafe { - cast::transmute(uvll::get_data_for_uv_handle(handle)) + mem::transmute(uvll::get_data_for_uv_handle(handle)) }; // and then free the handle unsafe { uvll::free_handle(handle) } diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs index 0e69db1f1f308..cd56e76aff667 100644 --- a/src/librustuv/file.rs +++ b/src/librustuv/file.rs @@ -8,16 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::c_str::CString; -use std::c_str; -use std::cast::transmute; -use std::cast; use libc::{c_int, c_char, c_void, ssize_t}; use libc; -use std::rt::task::BlockedTask; +use std::c_str::CString; +use std::c_str; use std::io::{FileStat, IoError}; use std::io; +use std::mem; use std::rt::rtio; +use std::rt::task::BlockedTask; use homing::{HomingIO, HomeHandle}; use super::{Loop, UvError, uv_error_to_io_error, wait_until_woken_after, wakeup}; @@ -341,7 +340,7 @@ fn execute(f: |*uvll::uv_fs_t, uvll::uv_fs_cb| -> c_int) extern fn fs_cb(req: *uvll::uv_fs_t) { let slot: &mut Option = unsafe { - cast::transmute(uvll::get_data_for_req(req)) + mem::transmute(uvll::get_data_for_req(req)) }; wakeup(slot); } @@ -448,7 +447,7 @@ impl rtio::RtioFileStream for FileWatcher { use libc::SEEK_CUR; // this is temporary // FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes - let self_ = unsafe { cast::transmute::<&_, &mut FileWatcher>(self) }; + let self_ = unsafe { mem::transmute::<&_, &mut FileWatcher>(self) }; self_.seek_common(0, SEEK_CUR) } fn fsync(&mut self) -> Result<(), IoError> { diff --git a/src/librustuv/homing.rs b/src/librustuv/homing.rs index 50825bab493b3..b9025397b8d22 100644 --- a/src/librustuv/homing.rs +++ b/src/librustuv/homing.rs @@ -33,7 +33,7 @@ #![allow(dead_code)] -use std::cast; +use std::mem; use std::rt::local::Local; use std::rt::rtio::LocalIo; use std::rt::task::{Task, BlockedTask}; @@ -77,7 +77,7 @@ pub fn local_id() -> uint { }; let io = io.get(); unsafe { - let (_vtable, ptr): (uint, uint) = cast::transmute(io); + let (_vtable, ptr): (uint, uint) = mem::transmute(io); return ptr; } } diff --git a/src/librustuv/idle.rs b/src/librustuv/idle.rs index ba72e5db27319..f5cde39bc8343 100644 --- a/src/librustuv/idle.rs +++ b/src/librustuv/idle.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; use libc::c_void; +use std::mem; use uvll; use super::{Loop, UvHandle}; @@ -41,7 +41,7 @@ impl IdleWatcher { let handle = UvHandle::alloc(None::, uvll::UV_IDLE); unsafe { assert_eq!(uvll::uv_idle_init(loop_.handle, handle), 0); - let data: *c_void = cast::transmute(box f); + let data: *c_void = mem::transmute(box f); uvll::set_data_for_uv_handle(handle, data); assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0) } @@ -49,7 +49,7 @@ impl IdleWatcher { extern fn onetime_cb(handle: *uvll::uv_idle_t) { unsafe { let data = uvll::get_data_for_uv_handle(handle); - let f: Box = cast::transmute(data); + let f: Box = mem::transmute(data); (*f)(); assert_eq!(uvll::uv_idle_stop(handle), 0); uvll::uv_close(handle, close_cb); @@ -95,7 +95,7 @@ impl Drop for IdleWatcher { #[cfg(test)] mod test { - use std::cast; + use std::mem; use std::cell::RefCell; use std::rc::Rc; use std::rt::rtio::{Callback, PausableIdleCallback}; @@ -130,7 +130,7 @@ mod test { let rc = Rc::new(RefCell::new((None, 0))); let cb = box MyCallback(rc.clone(), v); let cb = cb as Box; - let cb = unsafe { cast::transmute(cb) }; + let cb = unsafe { mem::transmute(cb) }; (IdleWatcher::new(&mut local_loop().loop_, cb), rc) } diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index 968029a6edc8c..6568254237620 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -48,10 +48,10 @@ via `close` and `delete` methods. extern crate libc; use libc::{c_int, c_void}; -use std::cast; use std::fmt; use std::io::IoError; use std::io; +use std::mem; use std::ptr::null; use std::ptr; use std::rt::local::Local; @@ -147,12 +147,12 @@ pub trait UvHandle { } unsafe fn from_uv_handle<'a>(h: &'a *T) -> &'a mut Self { - cast::transmute(uvll::get_data_for_uv_handle(*h)) + mem::transmute(uvll::get_data_for_uv_handle(*h)) } fn install(~self) -> Box { unsafe { - let myptr = cast::transmute::<&Box, &*u8>(&self); + let myptr = mem::transmute::<&Box, &*u8>(&self); uvll::set_data_for_uv_handle(self.uv_handle(), *myptr); } self @@ -188,7 +188,7 @@ pub trait UvHandle { let data = uvll::get_data_for_uv_handle(handle); uvll::free_handle(handle); if data == ptr::null() { return } - let slot: &mut Option = cast::transmute(data); + let slot: &mut Option = mem::transmute(data); wakeup(slot); } } @@ -284,7 +284,7 @@ impl Request { pub unsafe fn get_data(&self) -> &'static mut T { let data = uvll::get_data_for_req(self.handle); assert!(data != null()); - cast::transmute(data) + mem::transmute(data) } // This function should be used when the request handle has been given to an @@ -459,11 +459,11 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf { #[cfg(test)] fn local_loop() -> &'static mut uvio::UvIoFactory { unsafe { - cast::transmute({ + mem::transmute({ let mut task = Local::borrow(None::); let mut io = task.local_io().unwrap(); let (_vtable, uvio): (uint, &'static mut uvio::UvIoFactory) = - cast::transmute(io.get()); + mem::transmute(io.get()); uvio }) } @@ -471,7 +471,7 @@ fn local_loop() -> &'static mut uvio::UvIoFactory { #[cfg(test)] mod test { - use std::cast::transmute; + use std::mem::transmute; use std::unstable::run_in_bare_thread; use super::{slice_to_uv_buf, Loop}; diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 999da1cfda718..798c9ac3cab16 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -10,7 +10,6 @@ use libc::{size_t, ssize_t, c_int, c_void, c_uint}; use libc; -use std::cast; use std::io; use std::io::IoError; use std::io::net::ip; @@ -42,7 +41,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage, libc::AF_INET => { assert!(len as uint >= mem::size_of::()); 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; @@ -57,7 +56,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage, libc::AF_INET6 => { assert!(len as uint >= mem::size_of::()); 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]); @@ -84,7 +83,7 @@ fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) { let len = match addr.ip { ip::Ipv4Addr(a, b, c, d) => { let storage: &mut libc::sockaddr_in = - cast::transmute(&mut storage); + mem::transmute(&mut storage); (*storage).sin_family = libc::AF_INET as libc::sa_family_t; (*storage).sin_port = htons(addr.port); (*storage).sin_addr = libc::in_addr { @@ -97,7 +96,7 @@ fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) { } ip::Ipv6Addr(a, b, c, d, e, f, g, h) => { let storage: &mut libc::sockaddr_in6 = - cast::transmute(&mut storage); + mem::transmute(&mut storage); storage.sin6_family = libc::AF_INET6 as libc::sa_family_t; storage.sin6_port = htons(addr.port); storage.sin6_addr = libc::in6_addr { @@ -316,7 +315,7 @@ impl rtio::RtioTcpStream for TcpWatcher { &self.stream as *_ as uint); fn cancel_read(stream: uint) -> Option { - let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) }; + let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) }; stream.cancel_read(uvll::ECANCELED as ssize_t) } } @@ -328,7 +327,7 @@ impl rtio::RtioTcpStream for TcpWatcher { &self.stream as *_ as uint); fn cancel_write(stream: uint) -> Option { - let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) }; + let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) }; stream.cancel_write() } } @@ -602,7 +601,7 @@ impl rtio::RtioUdpSocket for UdpWatcher { None } else { let len = mem::size_of::(); - Some(sockaddr_to_addr(unsafe { cast::transmute(addr) }, len)) + Some(sockaddr_to_addr(unsafe { mem::transmute(addr) }, len)) }; cx.result = Some((nread, addr)); wakeup(&mut cx.task); @@ -652,7 +651,7 @@ impl rtio::RtioUdpSocket for UdpWatcher { }; unsafe { req.set_data(&*new_cx); - cast::forget(new_cx); + mem::forget(new_cx); } Err(uv_error_to_io_error(UvError(cx.result))) } @@ -670,7 +669,7 @@ impl rtio::RtioUdpSocket for UdpWatcher { let udp: &mut UdpWatcher = unsafe { &mut *cx.udp }; wakeup(&mut udp.blocked_sender); } else { - let _cx: Box = unsafe { cast::transmute(cx) }; + let _cx: Box = unsafe { mem::transmute(cx) }; } } } @@ -789,7 +788,7 @@ impl rtio::RtioUdpSocket for UdpWatcher { self as *mut _ as uint); fn cancel_write(stream: uint) -> Option { - let stream: &mut UdpWatcher = unsafe { cast::transmute(stream) }; + let stream: &mut UdpWatcher = unsafe { mem::transmute(stream) }; stream.blocked_sender.take() } } diff --git a/src/librustuv/pipe.rs b/src/librustuv/pipe.rs index 76bf92bd5557c..ba39f8a7f5f32 100644 --- a/src/librustuv/pipe.rs +++ b/src/librustuv/pipe.rs @@ -10,9 +10,9 @@ use libc; use std::c_str::CString; -use std::cast; use std::io::IoError; use std::io; +use std::mem; use std::rt::rtio::{RtioPipe, RtioUnixListener, RtioUnixAcceptor}; use std::rt::task::BlockedTask; @@ -185,7 +185,7 @@ impl RtioPipe for PipeWatcher { &self.stream as *_ as uint); fn cancel_read(stream: uint) -> Option { - let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) }; + let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) }; stream.cancel_read(uvll::ECANCELED as libc::ssize_t) } } @@ -197,7 +197,7 @@ impl RtioPipe for PipeWatcher { &self.stream as *_ as uint); fn cancel_write(stream: uint) -> Option { - let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) }; + let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) }; stream.cancel_write() } } diff --git a/src/librustuv/queue.rs b/src/librustuv/queue.rs index 561c1f6f95f5c..57b5e7105b20e 100644 --- a/src/librustuv/queue.rs +++ b/src/librustuv/queue.rs @@ -21,10 +21,10 @@ #![allow(dead_code)] use libc::c_void; -use std::cast; +use std::mem; use std::rt::task::BlockedTask; -use std::unstable::mutex::NativeMutex; use std::sync::arc::UnsafeArc; +use std::unstable::mutex::NativeMutex; use mpsc = std::sync::mpsc_queue; use async::AsyncWatcher; @@ -57,9 +57,9 @@ pub struct Queue { extern fn async_cb(handle: *uvll::uv_async_t) { let pool: &mut QueuePool = unsafe { - cast::transmute(uvll::get_data_for_uv_handle(handle)) + mem::transmute(uvll::get_data_for_uv_handle(handle)) }; - let state: &mut State = unsafe { cast::transmute(pool.queue.get()) }; + let state: &mut State = unsafe { mem::transmute(pool.queue.get()) }; // Remember that there is no guarantee about how many times an async // callback is called with relation to the number of sends, so process the @@ -183,7 +183,7 @@ impl Drop for Queue { impl Drop for State { fn drop(&mut self) { unsafe { - uvll::uv_close(self.handle, cast::transmute(0)); + uvll::uv_close(self.handle, mem::transmute(0)); // Note that this does *not* free the handle, that is the // responsibility of the caller because the uv loop must be closed // before we deallocate this uv handle. diff --git a/src/librustuv/stream.rs b/src/librustuv/stream.rs index 36b6ed09ca566..8ce985eb76d65 100644 --- a/src/librustuv/stream.rs +++ b/src/librustuv/stream.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; use libc::{c_int, size_t, ssize_t}; +use std::mem; use std::ptr; use std::rt::task::BlockedTask; @@ -212,7 +212,7 @@ impl StreamWatcher { }; unsafe { req.set_data(&*new_wcx); - cast::forget(new_wcx); + mem::forget(new_wcx); } Err(UvError(wcx.result)) } @@ -232,7 +232,7 @@ extern fn alloc_cb(stream: *uvll::uv_stream_t, _hint: size_t, buf: *mut Buf) { uvdebug!("alloc_cb"); unsafe { let rcx: &mut ReadContext = - cast::transmute(uvll::get_data_for_uv_handle(stream)); + mem::transmute(uvll::get_data_for_uv_handle(stream)); *buf = rcx.buf.take().expect("stream alloc_cb called more than once"); } } @@ -243,7 +243,7 @@ extern fn read_cb(handle: *uvll::uv_stream_t, nread: ssize_t, _buf: *Buf) { uvdebug!("read_cb {}", nread); assert!(nread != uvll::ECANCELED as ssize_t); let rcx: &mut ReadContext = unsafe { - cast::transmute(uvll::get_data_for_uv_handle(handle)) + mem::transmute(uvll::get_data_for_uv_handle(handle)) }; // Stop reading so that no read callbacks are // triggered before the user calls `read` again. @@ -272,6 +272,6 @@ extern fn write_cb(req: *uvll::uv_write_t, status: c_int) { let stream: &mut StreamWatcher = unsafe { &mut *wcx.stream }; wakeup(&mut stream.blocked_writer); } else { - let _wcx: Box = unsafe { cast::transmute(wcx) }; + let _wcx: Box = unsafe { mem::transmute(wcx) }; } } diff --git a/src/librustuv/timeout.rs b/src/librustuv/timeout.rs index 3dbb34bb17a87..99b568b12605c 100644 --- a/src/librustuv/timeout.rs +++ b/src/librustuv/timeout.rs @@ -9,7 +9,6 @@ // except according to those terms. use libc::c_int; -use std::cast; use std::io::IoResult; use std::mem; use std::rt::task::BlockedTask; @@ -127,7 +126,7 @@ impl AccessTimeout { }; unsafe { timer.set_data(&*cx); - cast::forget(cx); + mem::forget(cx); } self.timer = Some(timer); } @@ -199,7 +198,7 @@ impl Drop for AccessTimeout { match self.timer { Some(ref timer) => unsafe { let data = uvll::get_data_for_uv_handle(timer.handle); - let _data: Box = cast::transmute(data); + let _data: Box = mem::transmute(data); }, None => {} } diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs index 50258c2583c65..c42b17cc3256e 100644 --- a/src/librustuv/uvio.rs +++ b/src/librustuv/uvio.rs @@ -11,7 +11,6 @@ //! The implementation of `rtio` for libuv use std::c_str::CString; -use std::cast; use std::io::IoError; use std::io::net::ip::SocketAddr; use std::io::process::ProcessConfig; @@ -19,6 +18,7 @@ use std::io::signal::Signum; use std::io::{FileMode, FileAccess, Open, Append, Truncate, Read, Write, ReadWrite, FileStat}; use std::io; +use std::mem; use libc::c_int; use libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY, S_IRUSR, S_IWUSR}; @@ -140,7 +140,7 @@ impl UvIoFactory { pub fn make_handle(&mut self) -> HomeHandle { // It's understood by the homing code that the "local id" is just the // pointer of the local I/O factory cast to a uint. - let id: uint = unsafe { cast::transmute_copy(&self) }; + let id: uint = unsafe { mem::transmute_copy(&self) }; HomeHandle::new(id, &mut **self.handle_pool.get_mut_ref()) } } diff --git a/src/libserialize/ebml.rs b/src/libserialize/ebml.rs index 486150f1741f6..ea506931d76ee 100644 --- a/src/libserialize/ebml.rs +++ b/src/libserialize/ebml.rs @@ -88,7 +88,7 @@ pub enum Error { pub mod reader { use std::char; - use std::cast::transmute; + use std::mem::transmute; use std::int; use std::option::{None, Option, Some}; use std::io::extensions::u64_from_be_bytes; @@ -617,11 +617,11 @@ pub mod reader { } pub mod writer { - use std::cast; use std::clone::Clone; - use std::io; - use std::io::{Writer, Seek}; use std::io::extensions::u64_to_be_bytes; + use std::io::{Writer, Seek}; + use std::io; + use std::mem; use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey, EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8, @@ -679,7 +679,7 @@ pub mod writer { /// FIXME(pcwalton): Workaround for badness in trans. DO NOT USE ME. pub unsafe fn unsafe_clone(&self) -> Encoder<'a, W> { Encoder { - writer: cast::transmute_copy(&self.writer), + writer: mem::transmute_copy(&self.writer), size_positions: self.size_positions.clone(), } } @@ -853,11 +853,11 @@ pub mod writer { } fn emit_f64(&mut self, v: f64) -> EncodeResult { - let bits = unsafe { cast::transmute(v) }; + let bits = unsafe { mem::transmute(v) }; self.wr_tagged_u64(EsF64 as uint, bits) } fn emit_f32(&mut self, v: f32) -> EncodeResult { - let bits = unsafe { cast::transmute(v) }; + let bits = unsafe { mem::transmute(v) }; self.wr_tagged_u32(EsF32 as uint, bits) } fn emit_char(&mut self, v: char) -> EncodeResult { diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index f45ec8a6742a2..e087b3d177499 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -10,18 +10,18 @@ //! Operations on ASCII strings and characters -use to_str::{IntoStr}; -use str; -use str::Str; -use str::{StrAllocating, StrSlice}; -use str::OwnedStr; use container::Container; -use cast; use fmt; use iter::Iterator; +use mem; +use option::{Option, Some, None}; use slice::{ImmutableVector, MutableVector, Vector}; +use str::OwnedStr; +use str::Str; +use str::{StrAllocating, StrSlice}; +use str; +use to_str::{IntoStr}; use vec::Vec; -use option::{Option, Some, None}; /// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero. #[deriving(Clone, Eq, Ord, TotalOrd, TotalEq, Hash)] @@ -162,7 +162,7 @@ pub trait AsciiCast { impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] { #[inline] unsafe fn to_ascii_nocheck(&self) -> &'a[Ascii] { - cast::transmute(*self) + mem::transmute(*self) } #[inline] @@ -177,7 +177,7 @@ impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] { impl<'a> AsciiCast<&'a [Ascii]> for &'a str { #[inline] unsafe fn to_ascii_nocheck(&self) -> &'a [Ascii] { - cast::transmute(*self) + mem::transmute(*self) } #[inline] @@ -245,7 +245,7 @@ impl OwnedAsciiCast for ~[u8] { #[inline] unsafe fn into_ascii_nocheck(self) -> Vec { - cast::transmute(Vec::from_slice(self.as_slice())) + mem::transmute(Vec::from_slice(self.as_slice())) } } @@ -257,7 +257,7 @@ impl OwnedAsciiCast for ~str { #[inline] unsafe fn into_ascii_nocheck(self) -> Vec { - let v: ~[u8] = cast::transmute(self); + let v: ~[u8] = mem::transmute(self); v.into_ascii_nocheck() } } @@ -270,7 +270,7 @@ impl OwnedAsciiCast for Vec { #[inline] unsafe fn into_ascii_nocheck(self) -> Vec { - cast::transmute(self) + mem::transmute(self) } } @@ -293,7 +293,7 @@ pub trait AsciiStr { impl<'a> AsciiStr for &'a [Ascii] { #[inline] fn as_str_ascii<'a>(&'a self) -> &'a str { - unsafe { cast::transmute(*self) } + unsafe { mem::transmute(*self) } } #[inline] @@ -315,7 +315,7 @@ impl<'a> AsciiStr for &'a [Ascii] { impl IntoStr for ~[Ascii] { #[inline] fn into_str(self) -> ~str { - unsafe { cast::transmute(self) } + unsafe { mem::transmute(self) } } } @@ -323,7 +323,7 @@ impl IntoStr for Vec { #[inline] fn into_str(self) -> ~str { unsafe { - let s: &str = cast::transmute(self.as_slice()); + let s: &str = mem::transmute(self.as_slice()); s.to_owned() } } @@ -337,7 +337,7 @@ pub trait IntoBytes { impl IntoBytes for Vec { fn into_bytes(self) -> Vec { - unsafe { cast::transmute(self) } + unsafe { mem::transmute(self) } } } diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index b33d211aa1928..0885a7af00b4d 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -65,24 +65,23 @@ fn main() { */ -use cast; +use clone::Clone; +use cmp::Eq; use container::Container; use iter::{Iterator, range}; -use libc; use kinds::marker; -use ops::Drop; -use cmp::Eq; -use clone::Clone; +use libc; use mem; +use ops::Drop; use option::{Option, Some, None}; use ptr::RawPtr; use ptr; -use str::StrSlice; -use str; +use raw::Slice; +use rt::libc_heap::malloc_raw; use slice::{ImmutableVector, MutableVector}; use slice; -use rt::libc_heap::malloc_raw; -use raw::Slice; +use str::StrSlice; +use str; /// The representation of a C String. /// @@ -154,7 +153,7 @@ impl CString { /// Fails if the CString is null. pub fn with_mut_ref(&mut self, f: |*mut libc::c_char| -> T) -> T { if self.buf.is_null() { fail!("CString is null!"); } - f(unsafe { cast::transmute_mut_unsafe(self.buf) }) + f(self.buf as *mut libc::c_char) } /// Returns true if the CString is a null. @@ -182,7 +181,7 @@ impl CString { pub fn as_bytes<'a>(&'a self) -> &'a [u8] { if self.buf.is_null() { fail!("CString is null!"); } unsafe { - cast::transmute(Slice { data: self.buf, len: self.len() + 1 }) + mem::transmute(Slice { data: self.buf, len: self.len() + 1 }) } } @@ -196,7 +195,7 @@ impl CString { pub fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8] { if self.buf.is_null() { fail!("CString is null!"); } unsafe { - cast::transmute(Slice { data: self.buf, len: self.len() }) + mem::transmute(Slice { data: self.buf, len: self.len() }) } } diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 8c2c4fd1f0be7..817b54fb692f2 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -33,9 +33,9 @@ //! handled correctly, i.e. that allocated memory is eventually freed //! if necessary. -use cast; use container::Container; use kinds::Send; +use mem; use ops::Drop; use option::{Option, Some, None}; use ptr::RawPtr; @@ -102,14 +102,14 @@ impl CVec { /// View the stored data as a slice. pub fn as_slice<'a>(&'a self) -> &'a [T] { unsafe { - cast::transmute(raw::Slice { data: self.base as *T, len: self.len }) + mem::transmute(raw::Slice { data: self.base as *T, len: self.len }) } } /// View the stored data as a mutable slice. pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { - cast::transmute(raw::Slice { data: self.base as *T, len: self.len }) + mem::transmute(raw::Slice { data: self.base as *T, len: self.len }) } } diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs index cebfeb5399e9d..ed884647fb6ff 100644 --- a/src/libstd/comm/select.rs +++ b/src/libstd/comm/select.rs @@ -45,11 +45,11 @@ #![allow(dead_code)] -use cast; use cell::Cell; use iter::Iterator; -use kinds::marker; use kinds::Send; +use kinds::marker; +use mem; use ops::Drop; use option::{Some, None, Option}; use owned::Box; @@ -247,8 +247,8 @@ impl<'rx, T: Send> Handle<'rx, T> { /// while it is added to the `Select` set. pub unsafe fn add(&mut self) { if self.added { return } - let selector: &mut Select = cast::transmute(&*self.selector); - let me: *mut Handle<'static, ()> = cast::transmute(&*self); + let selector: &mut Select = mem::transmute(&*self.selector); + let me: *mut Handle<'static, ()> = mem::transmute(&*self); if selector.head.is_null() { selector.head = me; @@ -268,8 +268,8 @@ impl<'rx, T: Send> Handle<'rx, T> { pub unsafe fn remove(&mut self) { if !self.added { return } - let selector: &mut Select = cast::transmute(&*self.selector); - let me: *mut Handle<'static, ()> = cast::transmute(&*self); + let selector: &mut Select = mem::transmute(&*self.selector); + let me: *mut Handle<'static, ()> = mem::transmute(&*self); if self.prev.is_null() { assert_eq!(selector.head, me); diff --git a/src/libstd/comm/sync.rs b/src/libstd/comm/sync.rs index db3f90cad5a04..819e885526cbf 100644 --- a/src/libstd/comm/sync.rs +++ b/src/libstd/comm/sync.rs @@ -33,7 +33,6 @@ /// of a synchronous channel. There are a few branches for the unbuffered case, /// but they're mostly just relevant to blocking senders. -use cast; use container::Container; use iter::Iterator; use kinds::Send; @@ -187,7 +186,7 @@ impl Packet { NoneBlocked if state.cap == 0 => { let mut canceled = false; assert!(state.canceled.is_none()); - state.canceled = Some(unsafe { cast::transmute(&mut canceled) }); + state.canceled = Some(unsafe { mem::transmute(&mut canceled) }); wait(&mut state.blocker, BlockedSender, &self.lock); if canceled {Err(state.buf.dequeue())} else {Ok(())} } diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 7363593bacf07..b4bb6236f08ab 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -484,26 +484,26 @@ will look like `"\\{"`. */ use any; -use cast; use cell::Cell; use char::Char; use cmp; use container::Container; +use intrinsics::TypeId; use io::MemWriter; use io; -use iter; use iter::{Iterator, range}; +use iter; use kinds::Copy; +use mem; use num::Signed; use option::{Option, Some, None}; use owned::Box; use repr; use result::{Ok, Err, ResultUnwrap}; -use str::{StrSlice, StrAllocating, UTF16Item, ScalarValue, LoneSurrogate}; -use str; use slice::{Vector, ImmutableVector}; use slice; -use intrinsics::TypeId; +use str::{StrSlice, StrAllocating, UTF16Item, ScalarValue, LoneSurrogate}; +use str; pub use self::num::radix; pub use self::num::Radix; @@ -552,7 +552,7 @@ impl<'a> Arguments<'a> { #[doc(hidden)] #[inline] pub unsafe fn new<'a>(fmt: &'static [rt::Piece<'static>], args: &'a [Argument<'a>]) -> Arguments<'a> { - Arguments{ fmt: cast::transmute(fmt), args: args } + Arguments{ fmt: mem::transmute(fmt), args: args } } } @@ -870,7 +870,7 @@ impl<'a> Formatter<'a> { rt::Plural(offset, ref selectors, ref default) => { // This is validated at compile-time to be a pointer to a // '&uint' value. - let value: &uint = unsafe { cast::transmute(arg.value) }; + let value: &uint = unsafe { mem::transmute(arg.value) }; let value = *value; // First, attempt to match against explicit values without the @@ -913,7 +913,7 @@ impl<'a> Formatter<'a> { rt::Select(ref selectors, ref default) => { // This is validated at compile-time to be a pointer to a // string slice, - let value: & &str = unsafe { cast::transmute(arg.value) }; + let value: & &str = unsafe { mem::transmute(arg.value) }; let value = *value; for s in selectors.iter() { @@ -1093,8 +1093,8 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result, t: &'a T) -> Argument<'a> { unsafe { Argument { - formatter: cast::transmute(f), - value: cast::transmute(t) + formatter: mem::transmute(f), + value: mem::transmute(t) } } } @@ -1141,7 +1141,7 @@ impl Char for char { fn fmt(&self, f: &mut Formatter) -> Result { let mut utf8 = [0u8, ..4]; let amt = self.encode_utf8(utf8); - let s: &str = unsafe { cast::transmute(utf8.slice_to(amt)) }; + let s: &str = unsafe { mem::transmute(utf8.slice_to(amt)) }; secret_string(&s, f) } } diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index c8207a4c37cce..a510aa90343e5 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -307,7 +307,7 @@ impl, U: Hash> Hash for Result { #[cfg(test)] mod tests { - use cast; + use mem; use io::{IoResult, Writer}; use iter::{Iterator}; use option::{Some, None}; @@ -367,12 +367,12 @@ mod tests { assert_eq!(hasher.hash(& &[1u8, 2u8, 3u8]), 9); unsafe { - let ptr: *int = cast::transmute(5); + let ptr: *int = mem::transmute(5); assert_eq!(hasher.hash(&ptr), 5); } unsafe { - let ptr: *mut int = cast::transmute(5); + let ptr: *mut int = mem::transmute(5); assert_eq!(hasher.hash(&ptr), 5); } } diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index c2e8fbeeb784e..bb4bd50815a90 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -77,7 +77,7 @@ impl<'r, R: Reader> Iterator> for Bytes<'r, R> { /// This function returns the value returned by the callback, for convenience. pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { use mem::{to_le16, to_le32, to_le64}; - use cast::transmute; + use mem::transmute; // LLVM fails to properly optimize this when using shifts instead of the to_le* intrinsics assert!(size <= 8u); @@ -117,7 +117,7 @@ pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { /// This function returns the value returned by the callback, for convenience. pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { use mem::{to_be16, to_be32, to_be64}; - use cast::transmute; + use mem::transmute; // LLVM fails to properly optimize this when using shifts instead of the to_be* intrinsics assert!(size <= 8u); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 4a53a064610cb..37edab9991598 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -217,24 +217,24 @@ responding to errors that may occur while attempting to read the numbers. #![deny(unused_must_use)] -use cast; use char::Char; use container::Container; use fmt; use int; use iter::Iterator; use libc; +use mem::transmute; use ops::{BitOr, BitAnd, Sub}; -use os; use option::{Option, Some, None}; +use os; use owned::Box; use path::Path; use result::{Ok, Err, Result}; +use slice::{Vector, MutableVector, ImmutableVector}; use str::{StrSlice, StrAllocating}; use str; use uint; use unstable::finally::try_finally; -use slice::{Vector, MutableVector, ImmutableVector}; use vec::Vec; // Reexports @@ -729,7 +729,7 @@ pub trait Reader { /// `f64`s are 8 byte, IEEE754 double-precision floating point numbers. fn read_be_f64(&mut self) -> IoResult { self.read_be_u64().map(|i| unsafe { - cast::transmute::(i) + transmute::(i) }) } @@ -738,7 +738,7 @@ pub trait Reader { /// `f32`s are 4 byte, IEEE754 single-precision floating point numbers. fn read_be_f32(&mut self) -> IoResult { self.read_be_u32().map(|i| unsafe { - cast::transmute::(i) + transmute::(i) }) } @@ -789,7 +789,7 @@ pub trait Reader { /// `f64`s are 8 byte, IEEE754 double-precision floating point numbers. fn read_le_f64(&mut self) -> IoResult { self.read_le_u64().map(|i| unsafe { - cast::transmute::(i) + transmute::(i) }) } @@ -798,7 +798,7 @@ pub trait Reader { /// `f32`s are 4 byte, IEEE754 single-precision floating point numbers. fn read_le_f32(&mut self) -> IoResult { self.read_le_u32().map(|i| unsafe { - cast::transmute::(i) + transmute::(i) }) } @@ -995,14 +995,14 @@ pub trait Writer { /// Write a big-endian IEEE754 double-precision floating-point (8 bytes). fn write_be_f64(&mut self, f: f64) -> IoResult<()> { unsafe { - self.write_be_u64(cast::transmute(f)) + self.write_be_u64(transmute(f)) } } /// Write a big-endian IEEE754 single-precision floating-point (4 bytes). fn write_be_f32(&mut self, f: f32) -> IoResult<()> { unsafe { - self.write_be_u32(cast::transmute(f)) + self.write_be_u32(transmute(f)) } } @@ -1040,7 +1040,7 @@ pub trait Writer { /// (8 bytes). fn write_le_f64(&mut self, f: f64) -> IoResult<()> { unsafe { - self.write_le_u64(cast::transmute(f)) + self.write_le_u64(transmute(f)) } } @@ -1048,7 +1048,7 @@ pub trait Writer { /// (4 bytes). fn write_le_f32(&mut self, f: f32) -> IoResult<()> { unsafe { - self.write_le_u32(cast::transmute(f)) + self.write_le_u32(transmute(f)) } } diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index e66b2107bb107..864a70105412a 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -226,6 +226,7 @@ impl Writer for UdpStream { } #[cfg(test)] +#[allow(experimental)] mod test { use super::*; use io::net::ip::{SocketAddr}; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 3f22a76c1f4e7..8f0c1e4130971 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -143,7 +143,6 @@ extern crate core; pub use core::any; pub use core::bool; -pub use core::cast; pub use core::cell; pub use core::char; pub use core::clone; diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 5d18ca4141b1f..1a971594837df 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -38,11 +38,11 @@ assert_eq!(*key_vector.get().unwrap(), ~[4]); // Casting 'Arcane Sight' reveals an overwhelming aura of Transmutation // magic. -use cast; use iter::{Iterator}; use kinds::Send; use kinds::marker; use mem::replace; +use mem; use ops::{Drop, Deref}; use option::{None, Option, Some}; use owned::Box; @@ -172,7 +172,7 @@ impl KeyValue { // anything. let newval = data.map(|d| { let d = box d as Box; - let d: Box = unsafe { cast::transmute(d) }; + let d: Box = unsafe { mem::transmute(d) }; (keyval, d, 0) }); @@ -188,8 +188,8 @@ impl KeyValue { replace(map.get_mut(i), newval).map(|(_, data, _)| { // Move `data` into transmute to get out the memory that it // owns, we must free it manually later. - let t: raw::TraitObject = unsafe { cast::transmute(data) }; - let alloc: Box = unsafe { cast::transmute(t.data) }; + let t: raw::TraitObject = unsafe { mem::transmute(data) }; + let alloc: Box = unsafe { mem::transmute(t.data) }; // Now that we own `alloc`, we can just move out of it as we // would with any other data. diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index ea248b6d40def..29c206b32fc36 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -15,13 +15,13 @@ use prelude::*; -use cast; use from_str::FromStr; +use intrinsics; use libc::c_int; -use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal}; +use mem; use num::strconv; +use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal}; use num; -use intrinsics; pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE}; pub use core::f32::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP}; @@ -111,7 +111,7 @@ impl Float for f32 { static EXP_MASK: u32 = 0x7f800000; static MAN_MASK: u32 = 0x007fffff; - let bits: u32 = unsafe { cast::transmute(self) }; + let bits: u32 = unsafe { mem::transmute(self) }; match (bits & MAN_MASK, bits & EXP_MASK) { (0, 0) => FPZero, (_, 0) => FPSubnormal, @@ -168,7 +168,7 @@ impl Float for f32 { /// Returns the mantissa, exponent and sign as integers. fn integer_decode(self) -> (u64, i16, i8) { - let bits: u32 = unsafe { cast::transmute(self) }; + let bits: u32 = unsafe { mem::transmute(self) }; let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 }; let mut exponent: i16 = ((bits >> 23) & 0xff) as i16; let mantissa = if exponent == 0 { diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 77171a00befef..c18ea5caba629 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -14,13 +14,13 @@ use prelude::*; -use cast; use from_str::FromStr; +use intrinsics; use libc::{c_int}; +use mem; use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal}; use num::{strconv}; use num; -use intrinsics; pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE}; pub use core::f64::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP}; @@ -119,7 +119,7 @@ impl Float for f64 { static EXP_MASK: u64 = 0x7ff0000000000000; static MAN_MASK: u64 = 0x000fffffffffffff; - let bits: u64 = unsafe { cast::transmute(self) }; + let bits: u64 = unsafe { mem::transmute(self) }; match (bits & MAN_MASK, bits & EXP_MASK) { (0, 0) => FPZero, (_, 0) => FPSubnormal, @@ -176,7 +176,7 @@ impl Float for f64 { /// Returns the mantissa, exponent and sign as integers. fn integer_decode(self) -> (u64, i16, i8) { - let bits: u64 = unsafe { cast::transmute(self) }; + let bits: u64 = unsafe { mem::transmute(self) }; let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 }; let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16; let mantissa = if exponent == 0 { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index f21fbe1b6e669..dfe7241d7af03 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -12,13 +12,13 @@ use ascii::AsciiCast; use c_str::{CString, ToCStr}; -use cast; use clone::Clone; -use container::Container; use cmp::{Eq, TotalEq}; +use container::Container; use from_str::FromStr; use io::Writer; use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Rev, Iterator, Map}; +use mem; use option::{Option, Some, None}; use slice::{Vector, OwnedVector, ImmutableVector}; use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice}; @@ -389,13 +389,13 @@ impl GenericPath for Path { #[inline] fn filestem_str<'a>(&'a self) -> Option<&'a str> { // filestem() returns a byte vector that's guaranteed valid UTF-8 - self.filestem().map(|t| unsafe { cast::transmute(t) }) + self.filestem().map(|t| unsafe { mem::transmute(t) }) } #[inline] fn extension_str<'a>(&'a self) -> Option<&'a str> { // extension() returns a byte vector that's guaranteed valid UTF-8 - self.extension().map(|t| unsafe { cast::transmute(t) }) + self.extension().map(|t| unsafe { mem::transmute(t) }) } fn dir_path(&self) -> Path { diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index e0fe75fd90710..bc489bc399f84 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -23,7 +23,7 @@ pointers, and then storing the parent pointers as `Weak` pointers. */ -use cast::transmute; +use mem::transmute; use cell::Cell; use clone::Clone; use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering}; diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 6e47203b56c0a..6029f504d10b6 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -16,7 +16,7 @@ More runtime type reflection #![allow(missing_doc)] -use cast::transmute; +use mem::transmute; use char; use container::Container; use io; @@ -157,7 +157,7 @@ impl<'a> ReprVisitor<'a> { ptr: ptr, ptr_stk: vec!(), var_stk: vec!(), - writer: ::cast::transmute_copy(&self.writer), + writer: ::mem::transmute_copy(&self.writer), last_err: None, }; let mut v = reflect::MovePtrAdaptor(u); diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index df0f1d8d449e4..95d0eabd336d8 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -40,7 +40,7 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } #[cfg(not(test))] pub fn take() -> Option> { imp::take() } #[cfg(test)] pub fn take() -> Option> { match realargs::take() { - realstd::option::Some(v) => Some(unsafe{ ::cast::transmute(v) }), + realstd::option::Some(v) => Some(unsafe{ ::mem::transmute(v) }), realstd::option::None => None, } } @@ -49,13 +49,13 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } /// /// It is an error if the arguments already exist. #[cfg(not(test))] pub fn put(args: Vec<~[u8]>) { imp::put(args) } -#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::cast::transmute(args) }) } +#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::mem::transmute(args) }) } /// Make a clone of the global arguments. #[cfg(not(test))] pub fn clone() -> Option> { imp::clone() } #[cfg(test)] pub fn clone() -> Option> { match realargs::clone() { - realstd::option::Some(v) => Some(unsafe { ::cast::transmute(v) }), + realstd::option::Some(v) => Some(unsafe { ::mem::transmute(v) }), realstd::option::None => None, } } @@ -64,10 +64,9 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } #[cfg(target_os = "android")] #[cfg(target_os = "freebsd")] mod imp { - use cast; use clone::Clone; - use option::{Option, Some, None}; use iter::Iterator; + use option::{Option, Some, None}; use owned::Box; use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; use mem; @@ -120,7 +119,7 @@ mod imp { } fn get_global_ptr() -> *mut Option>> { - unsafe { cast::transmute(&global_args_ptr) } + unsafe { mem::transmute(&global_args_ptr) } } // Copied from `os`. diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 051bc494adc7f..c892a73d93484 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -12,15 +12,14 @@ //! //! Documentation can be found on the `rt::at_exit` function. -use cast; use iter::Iterator; use kinds::Send; use mem; use option::{Some, None}; use owned::Box; use ptr::RawPtr; -use unstable::sync::Exclusive; use slice::OwnedVector; +use unstable::sync::Exclusive; use vec::Vec; type Queue = Exclusive>; @@ -38,7 +37,7 @@ pub fn init() { rtassert!(!RUNNING); rtassert!(QUEUE.is_null()); let state: Box = box Exclusive::new(vec!()); - QUEUE = cast::transmute(state); + QUEUE = mem::transmute(state); } } @@ -46,7 +45,7 @@ pub fn push(f: proc():Send) { unsafe { rtassert!(!RUNNING); rtassert!(!QUEUE.is_null()); - let state: &mut Queue = cast::transmute(QUEUE); + let state: &mut Queue = mem::transmute(QUEUE); let mut f = Some(f); state.with(|arr| { arr.push(f.take_unwrap()); @@ -59,7 +58,7 @@ pub fn run() { rtassert!(!RUNNING); rtassert!(!QUEUE.is_null()); RUNNING = true; - let state: Box = cast::transmute(QUEUE); + let state: Box = mem::transmute(QUEUE); QUEUE = 0 as *mut Queue; let mut vec = None; state.with(|arr| { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index ee8041f68802c..f4cb770544c46 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -237,9 +237,9 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { #[cfg(unix)] mod imp { use c_str::CString; - use cast; use io::{IoResult, IoError, Writer}; use libc; + use mem; use option::{Some, None, Option}; use result::{Ok, Err}; use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; @@ -280,7 +280,7 @@ mod imp { extern fn trace_fn(ctx: *uw::_Unwind_Context, arg: *libc::c_void) -> uw::_Unwind_Reason_Code { - let cx: &mut Context = unsafe { cast::transmute(arg) }; + let cx: &mut Context = unsafe { mem::transmute(arg) }; let ip = unsafe { uw::_Unwind_GetIP(ctx) as *libc::c_void }; // dladdr() on osx gets whiny when we use FindEnclosingFunction, and // it appears to work fine without it, so we only use diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index efc8072594bbf..5feec7fd9d2d9 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -10,18 +10,17 @@ //! The local, garbage collected heap -use cast; use iter::Iterator; use libc::{c_void, free}; use mem; use ops::Drop; use option::{Option, None, Some}; -use ptr; use ptr::RawPtr; +use ptr; +use raw; use rt::libc_heap; use rt::local::Local; use rt::task::Task; -use raw; use slice::{ImmutableVector, Vector}; use vec::Vec; @@ -63,7 +62,7 @@ impl LocalHeap { let alloc = self.memory_region.malloc(total_size); { // Make sure that we can't use `mybox` outside of this scope - let mybox: &mut Box = unsafe { cast::transmute(alloc) }; + let mybox: &mut Box = unsafe { mem::transmute(alloc) }; // Clear out this box, and move it to the front of the live // allocations list mybox.drop_glue = drop_glue; @@ -85,7 +84,7 @@ impl LocalHeap { let new_box = self.memory_region.realloc(ptr, total_size); { // Fix links because we could have moved around - let mybox: &mut Box = unsafe { cast::transmute(new_box) }; + let mybox: &mut Box = unsafe { mem::transmute(new_box) }; if !mybox.prev.is_null() { unsafe { (*mybox.prev).next = new_box; } } @@ -103,7 +102,7 @@ impl LocalHeap { pub fn free(&mut self, alloc: *mut Box) { { // Make sure that we can't use `mybox` outside of this scope - let mybox: &mut Box = unsafe { cast::transmute(alloc) }; + let mybox: &mut Box = unsafe { mem::transmute(alloc) }; // Unlink it from the linked list if !mybox.prev.is_null() { @@ -167,7 +166,7 @@ impl AllocHeader { fn update_size(&mut self, _size: u32) {} fn as_box(&mut self) -> *mut Box { - let myaddr: uint = unsafe { cast::transmute(self) }; + let myaddr: uint = unsafe { mem::transmute(self) }; (myaddr + AllocHeader::size()) as *mut Box } @@ -191,7 +190,7 @@ impl MemoryRegion { libc_heap::malloc_raw(total_size) as *AllocHeader }; - let alloc: &mut AllocHeader = unsafe { cast::transmute(alloc) }; + let alloc: &mut AllocHeader = unsafe { mem::transmute(alloc) }; alloc.init(size as u32); self.claim(alloc); self.live_allocations += 1; @@ -210,7 +209,7 @@ impl MemoryRegion { libc_heap::realloc_raw(orig_alloc as *mut u8, total_size) as *AllocHeader }; - let alloc: &mut AllocHeader = unsafe { cast::transmute(alloc) }; + let alloc: &mut AllocHeader = unsafe { mem::transmute(alloc) }; alloc.assert_sane(); alloc.update_size(size as u32); self.update(alloc, orig_alloc as *AllocHeader); @@ -223,7 +222,7 @@ impl MemoryRegion { let alloc = AllocHeader::from(alloc); unsafe { (*alloc).assert_sane(); - self.release(cast::transmute(alloc)); + self.release(mem::transmute(alloc)); rtassert!(self.live_allocations > 0); self.live_allocations -= 1; free(alloc as *mut c_void) diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 39c0d9a548207..1197a4ccbe670 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -17,7 +17,7 @@ #![allow(dead_code)] -use cast; +use mem; use ops::{Drop, Deref, DerefMut}; use owned::Box; use ptr::RawPtr; @@ -44,7 +44,7 @@ impl Drop for Borrowed { if self.val.is_null() { rtabort!("Aiee, returning null borrowed object!"); } - let val: Box = cast::transmute(self.val); + let val: Box = mem::transmute(self.val); put::(val); rtassert!(exists()); } @@ -71,7 +71,7 @@ impl DerefMut for Borrowed { /// Does not validate the pointer type. #[inline] pub unsafe fn borrow() -> Borrowed { - let val: *() = cast::transmute(take::()); + let val: *() = mem::transmute(take::()); Borrowed { val: val, } @@ -83,7 +83,7 @@ pub unsafe fn borrow() -> Borrowed { /// it wherever possible. #[cfg(not(windows), not(target_os = "android"))] pub mod compiled { - use cast; + use mem; use option::{Option, Some, None}; use owned::Box; use ptr::RawPtr; @@ -157,7 +157,7 @@ pub mod compiled { /// Does not validate the pointer type. #[inline(never)] // see comments above pub unsafe fn put(sched: Box) { - RT_TLS_PTR = cast::transmute(sched) + RT_TLS_PTR = mem::transmute(sched) } /// Take ownership of a pointer from thread-local storage. @@ -169,9 +169,9 @@ pub mod compiled { pub unsafe fn take() -> Box { let ptr = RT_TLS_PTR; rtassert!(!ptr.is_null()); - let ptr: Box = cast::transmute(ptr); + let ptr: Box = mem::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` - RT_TLS_PTR = cast::transmute(0); + RT_TLS_PTR = mem::transmute(0); ptr } @@ -186,9 +186,9 @@ pub mod compiled { if ptr.is_null() { None } else { - let ptr: Box = cast::transmute(ptr); + let ptr: Box = mem::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` - RT_TLS_PTR = cast::transmute(0); + RT_TLS_PTR = mem::transmute(0); Some(ptr) } } @@ -201,7 +201,7 @@ pub mod compiled { /// Leaves the old pointer in TLS for speed. #[inline(never)] // see comments above pub unsafe fn unsafe_take() -> Box { - cast::transmute(RT_TLS_PTR) + mem::transmute(RT_TLS_PTR) } /// Check whether there is a thread-local pointer installed. @@ -234,11 +234,11 @@ pub mod compiled { /// implementation uses the `thread_local_storage` module to provide a /// thread-local value. pub mod native { - use cast; + use mem; use option::{Option, Some, None}; use owned::Box; - use ptr; use ptr::RawPtr; + use ptr; use tls = rt::thread_local_storage; static mut RT_TLS_KEY: tls::Key = -1; @@ -264,7 +264,7 @@ pub mod native { #[inline] pub unsafe fn put(sched: Box) { let key = tls_key(); - let void_ptr: *mut u8 = cast::transmute(sched); + let void_ptr: *mut u8 = mem::transmute(sched); tls::set(key, void_ptr); } @@ -280,7 +280,7 @@ pub mod native { if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: Box = cast::transmute(void_ptr); + let ptr: Box = mem::transmute(void_ptr); tls::set(key, ptr::mut_null()); return ptr; } @@ -298,7 +298,7 @@ pub mod native { if void_ptr.is_null() { None } else { - let ptr: Box = cast::transmute(void_ptr); + let ptr: Box = mem::transmute(void_ptr); tls::set(key, ptr::mut_null()); Some(ptr) } @@ -320,7 +320,7 @@ pub mod native { if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: Box = cast::transmute(void_ptr); + let ptr: Box = mem::transmute(void_ptr); return ptr; } @@ -398,7 +398,7 @@ pub mod native { pub fn maybe_tls_key() -> Option { use realstd; unsafe { - cast::transmute(realstd::rt::shouldnt_be_public::maybe_tls_key()) + mem::transmute(realstd::rt::shouldnt_be_public::maybe_tls_key()) } } } diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index ccde8d9c96af0..bc3a483f30d2b 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -11,11 +11,11 @@ //! The EventLoop and internal synchronous I/O interface. use c_str::CString; -use cast; use comm::{Sender, Receiver}; +use kinds::Send; use libc::c_int; use libc; -use kinds::Send; +use mem; use ops::Drop; use option::{Option, Some, None}; use owned::Box; @@ -118,7 +118,7 @@ impl<'a> LocalIo<'a> { // in order to have what is likely a static lifetime (bad). let mut t: Box = Local::take(); let ret = t.local_io().map(|t| { - unsafe { cast::transmute_copy(&t) } + unsafe { mem::transmute_copy(&t) } }); Local::put(t); return ret; @@ -143,7 +143,7 @@ impl<'a> LocalIo<'a> { // FIXME(pcwalton): I think this is actually sound? Could borrow check // allow this safely? unsafe { - cast::transmute_copy(&self.factory) + mem::transmute_copy(&self.factory) } } } diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 77bcb7b9904ac..cd0445056b290 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -14,7 +14,6 @@ //! to implement this. use any::AnyOwnExt; -use cast; use cleanup; use clone::Clone; use comm::Sender; @@ -22,6 +21,7 @@ use io::Writer; use iter::{Iterator, Take}; use kinds::Send; use local_data; +use mem; use ops::Drop; use option::{Option, Some, None}; use owned::Box; @@ -116,7 +116,7 @@ impl Task { // Unsafely get a handle to the task so we can continue to use it after // putting it in tls (so we can invoke the unwinder). let handle: *mut Task = unsafe { - *cast::transmute::<&Box, &*mut Task>(&self) + *mem::transmute::<&Box, &*mut Task>(&self) }; Local::put(self); @@ -222,13 +222,13 @@ impl Task { // crops up. unsafe { let imp = self.imp.take_unwrap(); - let &(vtable, _): &(uint, uint) = cast::transmute(&imp); + let &(vtable, _): &(uint, uint) = mem::transmute(&imp); match imp.wrap().move::() { Ok(t) => Some(t), Err(t) => { - let (_, obj): (uint, uint) = cast::transmute(t); + let (_, obj): (uint, uint) = mem::transmute(t); let obj: Box = - cast::transmute((vtable, obj)); + mem::transmute((vtable, obj)); self.put_runtime(obj); None } @@ -317,7 +317,7 @@ impl BlockedTask { Shared(arc) => unsafe { match (*arc.get()).swap(0, SeqCst) { 0 => None, - n => Some(cast::transmute(n)), + n => Some(mem::transmute(n)), } } } @@ -343,7 +343,7 @@ impl BlockedTask { pub fn make_selectable(self, num_handles: uint) -> Take { let arc = match self { Owned(task) => { - let flag = unsafe { AtomicUint::new(cast::transmute(task)) }; + let flag = unsafe { AtomicUint::new(mem::transmute(task)) }; UnsafeArc::new(flag) } Shared(arc) => arc.clone(), @@ -357,12 +357,12 @@ impl BlockedTask { pub unsafe fn cast_to_uint(self) -> uint { match self { Owned(task) => { - let blocked_task_ptr: uint = cast::transmute(task); + let blocked_task_ptr: uint = mem::transmute(task); rtassert!(blocked_task_ptr & 0x1 == 0); blocked_task_ptr } Shared(arc) => { - let blocked_task_ptr: uint = cast::transmute(box arc); + let blocked_task_ptr: uint = mem::transmute(box arc); rtassert!(blocked_task_ptr & 0x1 == 0); blocked_task_ptr | 0x1 } @@ -374,10 +374,10 @@ impl BlockedTask { #[inline] pub unsafe fn cast_from_uint(blocked_task_ptr: uint) -> BlockedTask { if blocked_task_ptr & 0x1 == 0 { - Owned(cast::transmute(blocked_task_ptr)) + Owned(mem::transmute(blocked_task_ptr)) } else { let ptr: Box> = - cast::transmute(blocked_task_ptr & !1); + mem::transmute(blocked_task_ptr & !1); Shared(*ptr) } } diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index 89d44473a9462..4f0d7d35ce892 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -17,9 +17,9 @@ #![allow(non_camel_case_types)] #![allow(unsigned_negate)] -use cast; use kinds::Send; use libc; +use mem; use ops::Drop; use option::{Option, Some, None}; use owned::Box; @@ -46,9 +46,9 @@ extern fn thread_start(main: *libc::c_void) -> imp::rust_thread_return { use rt::stack; unsafe { stack::record_stack_bounds(0, uint::MAX); - let f: Box = cast::transmute(main); + let f: Box = mem::transmute(main); (*f)(); - cast::transmute(0 as imp::rust_thread_return) + mem::transmute(0 as imp::rust_thread_return) } } @@ -83,7 +83,7 @@ impl Thread<()> { // so. let packet = box None; let packet2: *mut Option = unsafe { - *cast::transmute::<&Box>, **mut Option>(&packet) + *mem::transmute::<&Box>, **mut Option>(&packet) }; let main = proc() unsafe { *packet2 = Some(main()); }; let native = unsafe { imp::create(stack, box main) }; @@ -146,7 +146,7 @@ impl Drop for Thread { #[cfg(windows)] mod imp { - use cast; + use mem; use cmp; use kinds::Send; use libc; @@ -161,7 +161,7 @@ mod imp { pub type rust_thread_return = DWORD; pub unsafe fn create(stack: uint, p: Box) -> rust_thread { - let arg: *mut libc::c_void = cast::transmute(p); + let arg: *mut libc::c_void = mem::transmute(p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least // PTHREAD_STACK_MIN bytes big. Windows has no such lower limit, it's @@ -177,7 +177,7 @@ mod imp { if ret as uint == 0 { // be sure to not leak the closure - let _p: Box = cast::transmute(arg); + let _p: Box = mem::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } return ret; @@ -213,7 +213,6 @@ mod imp { #[cfg(unix)] mod imp { - use cast; use cmp; use kinds::Send; use libc::consts::os::posix01::{PTHREAD_CREATE_JOINABLE, PTHREAD_STACK_MIN}; @@ -254,13 +253,13 @@ mod imp { }, }; - let arg: *libc::c_void = cast::transmute(p); + let arg: *libc::c_void = mem::transmute(p); let ret = pthread_create(&mut native, &attr, super::thread_start, arg); assert_eq!(pthread_attr_destroy(&mut attr), 0); if ret != 0 { // be sure to not leak the closure - let _p: Box = cast::transmute(arg); + let _p: Box = mem::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } native @@ -302,7 +301,7 @@ mod imp { if __pthread_get_minstack.is_null() { PTHREAD_STACK_MIN } else { - unsafe { cast::transmute::<*(), F>(__pthread_get_minstack)(attr) } + unsafe { mem::transmute::<*(), F>(__pthread_get_minstack)(attr) } } } diff --git a/src/libstd/rt/thread_local_storage.rs b/src/libstd/rt/thread_local_storage.rs index 7706206863617..2551c89972e59 100644 --- a/src/libstd/rt/thread_local_storage.rs +++ b/src/libstd/rt/thread_local_storage.rs @@ -95,7 +95,7 @@ extern "system" { #[test] fn tls_smoke_test() { - use cast::transmute; + use mem::transmute; unsafe { let mut key = 0; let value = box 20; diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 5f3731eb819d3..e10e0716f67f2 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -58,8 +58,8 @@ // Currently Rust uses unwind runtime provided by libgcc. use any::{Any, AnyRefExt}; -use cast; use fmt; +use intrinsics; use kinds::Send; use mem; use option::{Some, None, Option}; @@ -72,7 +72,6 @@ use rt::local::Local; use rt::task::Task; use str::Str; use task::TaskResult; -use intrinsics; use uw = rt::libunwind; @@ -98,7 +97,7 @@ impl Unwinder { use libc::{c_void}; unsafe { - let closure: Closure = cast::transmute(f); + let closure: Closure = mem::transmute(f); let ep = rust_try(try_fn, closure.code as *c_void, closure.env as *c_void); if !ep.is_null() { @@ -109,7 +108,7 @@ impl Unwinder { extern fn try_fn(code: *c_void, env: *c_void) { unsafe { - let closure: || = cast::transmute(Closure { + let closure: || = mem::transmute(Closure { code: code as *(), env: env as *(), }); @@ -146,7 +145,7 @@ impl Unwinder { exception_cleanup: exception_cleanup, private: [0, ..uw::unwinder_private_data_size], }; - let error = uw::_Unwind_RaiseException(cast::transmute(exception)); + let error = uw::_Unwind_RaiseException(mem::transmute(exception)); rtabort!("Could not unwind stack, error = {}", error as int) } @@ -155,7 +154,7 @@ impl Unwinder { rtdebug!("exception_cleanup()"); unsafe { let _: Box = - cast::transmute(exception); + mem::transmute(exception); } } } diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index b97c55ad70139..b0868dd0daf54 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -97,8 +97,7 @@ There are a number of free functions that create or take vectors, for example: */ -use cast::transmute; -use cast; +use mem::transmute; use clone::Clone; use cmp::{TotalOrd, Ordering, Less, Greater}; use cmp; @@ -333,7 +332,7 @@ impl<'a, T: Clone> CloneableVector for &'a [T] { // FIXME: #13994 (should pass align and size here) exchange_free(ret as *mut u8, 0, 8); }); - cast::transmute(ret) + mem::transmute(ret) } } @@ -380,7 +379,7 @@ impl<'a, T: Clone> CloneableVector for &'a [T] { // FIXME: #13994 (should pass align and size here) exchange_free(ret as *mut u8, 0, 8); }); - cast::transmute(ret) + mem::transmute(ret) } } @@ -531,7 +530,7 @@ fn insertion_sort(v: &mut [T], compare: |&T, &T| -> Ordering) { ptr::copy_nonoverlapping_memory(buf_v.offset(j), &tmp as *T, 1); - cast::forget(tmp); + mem::forget(tmp); } } } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index fb3dcc972871d..24cf9681ca84d 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -74,23 +74,23 @@ The actual representation of strings have direct mappings to vectors: */ -use cast; -use cast::transmute; -use char; use char::Char; +use char; use clone::Clone; use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering}; use container::Container; +use default::Default; use fmt; +use from_str::FromStr; use io::Writer; use iter::{Iterator, range, AdditiveIterator}; +use mem::transmute; +use mem; use option::{None, Option, Some}; -use from_str::FromStr; -use slice::{ImmutableVector, MutableVector, CloneableVector}; use slice::Vector; -use vec::Vec; -use default::Default; +use slice::{ImmutableVector, MutableVector, CloneableVector}; use strbuf::StrBuf; +use vec::Vec; pub use core::str::{from_utf8, CharEq, Chars, CharOffsets, RevChars}; pub use core::str::{RevCharOffsets, Bytes, RevBytes, CharSplits, RevCharSplits}; @@ -126,7 +126,7 @@ impl FromStr for ~str { /// Fails if invalid UTF-8 pub fn from_byte(b: u8) -> ~str { assert!(b < 128u8); - unsafe { ::cast::transmute(box [b]) } + unsafe { ::mem::transmute(box [b]) } } /// Convert a char to a string @@ -403,7 +403,7 @@ static TAG_CONT_U8: u8 = 128u8; /// ``` pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> { if is_utf8(v) { - return Slice(unsafe { cast::transmute(v) }) + return Slice(unsafe { mem::transmute(v) }) } static REPLACEMENT: &'static [u8] = bytes!(0xEF, 0xBF, 0xBD); // U+FFFD in UTF-8 @@ -666,8 +666,8 @@ impl<'a> fmt::Show for MaybeOwned<'a> { /// Unsafe operations pub mod raw { - use cast; use libc; + use mem; use ptr::RawPtr; use raw::Slice; use slice::CloneableVector; @@ -679,9 +679,9 @@ pub mod raw { /// Create a Rust string from a *u8 buffer of the given length pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str { let v = Slice { data: buf, len: len }; - let bytes: &[u8] = ::cast::transmute(v); + let bytes: &[u8] = ::mem::transmute(v); assert!(is_utf8(bytes)); - let s: &str = ::cast::transmute(bytes); + let s: &str = ::mem::transmute(bytes); s.to_owned() } @@ -707,7 +707,7 @@ pub mod raw { /// that the utf-8-ness of the vector has already been validated #[inline] pub unsafe fn from_utf8_owned(v: ~[u8]) -> ~str { - cast::transmute(v) + mem::transmute(v) } /// Converts a byte to a string. @@ -717,7 +717,7 @@ pub mod raw { /// The caller must preserve the valid UTF-8 property when modifying. #[inline] pub unsafe fn as_owned_vec<'a>(s: &'a mut ~str) -> &'a mut ~[u8] { - cast::transmute(s) + mem::transmute(s) } /// Sets the length of a string @@ -823,7 +823,7 @@ pub trait StrAllocating: Str { use slice::Vector; unsafe { - ::cast::transmute(self.as_slice().as_bytes().to_owned()) + ::mem::transmute(self.as_slice().as_bytes().to_owned()) } } @@ -933,7 +933,7 @@ pub trait OwnedStr { impl OwnedStr for ~str { #[inline] fn into_bytes(self) -> ~[u8] { - unsafe { cast::transmute(self) } + unsafe { mem::transmute(self) } } #[inline] diff --git a/src/libstd/strbuf.rs b/src/libstd/strbuf.rs index 8e05b2f527d08..45ab690b0a2be 100644 --- a/src/libstd/strbuf.rs +++ b/src/libstd/strbuf.rs @@ -11,12 +11,12 @@ //! An owned, growable string that enforces that its contents are valid UTF-8. use c_vec::CVec; -use cast; use char::Char; use container::Container; use fmt; use io::Writer; use iter::{Extendable, FromIterator, Iterator, range}; +use mem; use option::{None, Option, Some}; use ptr::RawPtr; use slice::{OwnedVector, Vector, CloneableVector}; @@ -265,7 +265,7 @@ impl Str for StrBuf { #[inline] fn as_slice<'a>(&'a self) -> &'a str { unsafe { - cast::transmute(self.vec.as_slice()) + mem::transmute(self.vec.as_slice()) } } } @@ -274,7 +274,7 @@ impl StrAllocating for StrBuf { #[inline] fn into_owned(self) -> ~str { unsafe { - cast::transmute(self.vec.as_slice().to_owned()) + mem::transmute(self.vec.as_slice().to_owned()) } } diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 676c836c459d7..7dcfe62ffb8a6 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -21,10 +21,10 @@ //! the underlying data will remain valid (not free'd) so long as the reference //! count is greater than one. -use cast; use clone::Clone; use iter::Iterator; use kinds::Send; +use mem; use ops::Drop; use owned::Box; use ptr::RawPtr; @@ -50,7 +50,7 @@ unsafe fn new_inner(data: T, refcount: uint) -> *mut ArcData { count: AtomicUint::new(refcount), data: Unsafe::new(data) }; - cast::transmute(data) + mem::transmute(data) } impl UnsafeArc { @@ -158,7 +158,7 @@ impl Drop for UnsafeArc{ // happened before), and an "acquire" operation before deleting the object. // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html) fence(Acquire); - let _: Box> = cast::transmute(self.data); + let _: Box> = mem::transmute(self.data); } } } diff --git a/src/libstd/sync/atomics.rs b/src/libstd/sync/atomics.rs index 2fba59c3233e2..6ddae97e901ae 100644 --- a/src/libstd/sync/atomics.rs +++ b/src/libstd/sync/atomics.rs @@ -108,11 +108,11 @@ #![allow(missing_doc)] use intrinsics; -use cast; -use std::kinds::marker; -use option::{Option,Some,None}; +use mem; use ops::Drop; +use option::{Option,Some,None}; use owned::Box; +use std::kinds::marker; use ty::Unsafe; /// An atomic boolean type. @@ -665,7 +665,7 @@ impl AtomicPtr { impl AtomicOption { /// Create a new `AtomicOption` pub fn new(p: Box) -> AtomicOption { - unsafe { AtomicOption { p: Unsafe::new(cast::transmute(p)) } } + unsafe { AtomicOption { p: Unsafe::new(mem::transmute(p)) } } } /// Create a new `AtomicOption` that doesn't contain a value @@ -675,13 +675,13 @@ impl AtomicOption { #[inline] pub fn swap(&self, val: Box, order: Ordering) -> Option> { unsafe { - let val = cast::transmute(val); + let val = mem::transmute(val); let p = atomic_swap(self.p.get(), val, order); if p as uint == 0 { None } else { - Some(cast::transmute(p)) + Some(mem::transmute(p)) } } } @@ -689,7 +689,7 @@ impl AtomicOption { /// Remove the value, leaving the `AtomicOption` empty. #[inline] pub fn take(&self, order: Ordering) -> Option> { - unsafe { self.swap(cast::transmute(0), order) } + unsafe { self.swap(mem::transmute(0), order) } } /// Replace an empty value with a non-empty value. @@ -700,13 +700,13 @@ impl AtomicOption { #[inline] pub fn fill(&self, val: Box, order: Ordering) -> Option> { unsafe { - let val = cast::transmute(val); - let expected = cast::transmute(0); + let val = mem::transmute(val); + let expected = mem::transmute(0); let oldval = atomic_compare_and_swap(self.p.get(), expected, val, order); if oldval == expected { None } else { - Some(cast::transmute(val)) + Some(mem::transmute(val)) } } } diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index 8dfd691e6ffdc..175bb03d2620c 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -48,7 +48,6 @@ // FIXME: all atomic operations in this module use a SeqCst ordering. That is // probably overkill -use cast; use clone::Clone; use iter::{range, Iterator}; use kinds::Send; @@ -57,12 +56,12 @@ use mem; use ops::Drop; use option::{Option, Some, None}; use owned::Box; -use ptr; use ptr::RawPtr; +use ptr; +use slice::ImmutableVector; use sync::arc::UnsafeArc; use sync::atomics::{AtomicInt, AtomicPtr, SeqCst}; use unstable::sync::Exclusive; -use slice::ImmutableVector; use vec::Vec; // Once the queue is less than 1/K full, then it will be downsized. Note that @@ -230,7 +229,7 @@ impl Deque { Deque { bottom: AtomicInt::new(0), top: AtomicInt::new(0), - array: AtomicPtr::new(unsafe { cast::transmute(buf) }), + array: AtomicPtr::new(unsafe { mem::transmute(buf) }), pool: pool, } } @@ -272,7 +271,7 @@ impl Deque { return Some(data); } else { self.bottom.store(t + 1, SeqCst); - cast::forget(data); // someone else stole this value + mem::forget(data); // someone else stole this value return None; } } @@ -294,7 +293,7 @@ impl Deque { if self.top.compare_and_swap(t, t + 1, SeqCst) == t { Data(data) } else { - cast::forget(data); // someone else stole this value + mem::forget(data); // someone else stole this value Abort } } @@ -315,7 +314,7 @@ impl Deque { // continue to be read after we flag this buffer for reclamation. unsafe fn swap_buffer(&mut self, b: int, old: *mut Buffer, buf: Buffer) -> *mut Buffer { - let newbuf: *mut Buffer = cast::transmute(box buf); + let newbuf: *mut Buffer = mem::transmute(box buf); self.array.store(newbuf, SeqCst); let ss = (*newbuf).size(); self.bottom.store(b + ss, SeqCst); @@ -323,7 +322,7 @@ impl Deque { if self.top.compare_and_swap(t, t + ss, SeqCst) != t { self.bottom.store(b, SeqCst); } - self.pool.free(cast::transmute(old)); + self.pool.free(mem::transmute(old)); return newbuf; } } @@ -340,7 +339,7 @@ impl Drop for Deque { for i in range(t, b) { let _: T = unsafe { (*a).get(i) }; } - self.pool.free(unsafe { cast::transmute(a) }); + self.pool.free(unsafe { mem::transmute(a) }); } } @@ -373,7 +372,7 @@ impl Buffer { unsafe fn put(&mut self, i: int, t: T) { let ptr = self.storage.offset(i & self.mask()); ptr::copy_nonoverlapping_memory(ptr as *mut T, &t as *T, 1); - cast::forget(t); + mem::forget(t); } // Again, unsafe because this has incredibly dubious ownership violations. @@ -400,7 +399,7 @@ mod tests { use prelude::*; use super::{Data, BufferPool, Abort, Empty, Worker, Stealer}; - use cast; + use mem; use owned::Box; use rt::thread::Thread; use rand; @@ -607,7 +606,7 @@ mod tests { let s = s.clone(); let unique_box = box AtomicUint::new(0); let thread_box = unsafe { - *cast::transmute::<&Box, + *mem::transmute::<&Box, **mut AtomicUint>(&unique_box) }; (Thread::start(proc() { diff --git a/src/libstd/sync/mpsc_queue.rs b/src/libstd/sync/mpsc_queue.rs index e05959e25918b..4cdcd05e9b450 100644 --- a/src/libstd/sync/mpsc_queue.rs +++ b/src/libstd/sync/mpsc_queue.rs @@ -38,8 +38,8 @@ // http://www.1024cores.net/home/lock-free-algorithms // /queues/non-intrusive-mpsc-node-based-queue -use cast; use kinds::Send; +use mem; use ops::Drop; use option::{Option, None, Some}; use owned::Box; @@ -74,7 +74,7 @@ pub struct Queue { impl Node { unsafe fn new(v: Option) -> *mut Node { - cast::transmute(box Node { + mem::transmute(box Node { next: AtomicPtr::new(0 as *mut Node), value: v, }) @@ -121,7 +121,7 @@ impl Queue { assert!((*tail).value.is_none()); assert!((*next).value.is_some()); let ret = (*next).value.take_unwrap(); - let _: Box> = cast::transmute(tail); + let _: Box> = mem::transmute(tail); return Data(ret); } @@ -146,7 +146,7 @@ impl Drop for Queue { let mut cur = self.tail; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _: Box> = cast::transmute(cur); + let _: Box> = mem::transmute(cur); cur = next; } } diff --git a/src/libstd/sync/spsc_queue.rs b/src/libstd/sync/spsc_queue.rs index 7854a0e168ebd..ed6d690def06a 100644 --- a/src/libstd/sync/spsc_queue.rs +++ b/src/libstd/sync/spsc_queue.rs @@ -33,8 +33,8 @@ //! concurrently between two tasks. This data structure is safe to use and //! enforces the semantics that there is one pusher and one popper. -use cast; use kinds::Send; +use mem; use ops::Drop; use option::{Some, None, Option}; use owned::Box; @@ -74,7 +74,7 @@ pub struct Queue { impl Node { fn new() -> *mut Node { unsafe { - cast::transmute(box Node { + mem::transmute(box Node { value: None, next: AtomicPtr::new(0 as *mut Node), }) @@ -188,7 +188,7 @@ impl Queue { (*self.tail_prev.load(Relaxed)).next.store(next, Relaxed); // We have successfully erased all references to 'tail', so // now we can safely drop it. - let _: Box> = cast::transmute(tail); + let _: Box> = mem::transmute(tail); } } return ret; @@ -216,7 +216,7 @@ impl Drop for Queue { let mut cur = self.first; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _n: Box> = cast::transmute(cur); + let _n: Box> = mem::transmute(cur); cur = next; } } diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index e2a9f6a5c4821..87d531cc627e0 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -17,8 +17,8 @@ A simple wrapper over the platform's dynamic library facilities */ use c_str::ToCStr; -use cast; use iter::Iterator; +use mem; use ops::*; use option::*; use os; @@ -97,7 +97,7 @@ impl DynamicLibrary { // the destructor does not run. match maybe_symbol_value { Err(err) => Err(err), - Ok(symbol_value) => Ok(cast::transmute(symbol_value)) + Ok(symbol_value) => Ok(mem::transmute(symbol_value)) } } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index aa10be1d1be47..528ab72762aab 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -10,23 +10,21 @@ //! An owned, growable vector. -use cast::{forget, transmute}; +use RawVec = raw::Vec; use clone::Clone; use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd, max}; use container::{Container, Mutable}; use default::Default; use fmt; use iter::{DoubleEndedIterator, FromIterator, Extendable, Iterator, range}; -use mem::{min_align_of, move_val_init, size_of}; use mem; -use num; use num::{CheckedMul, CheckedAdd}; +use num; use ops::{Add, Drop}; use option::{None, Option, Some, Expect}; use ptr::RawPtr; use ptr; use raw::Slice; -use RawVec = raw::Vec; use rt::heap::{allocate, reallocate, deallocate}; use slice::{ImmutableEqVector, ImmutableVector, Items, MutItems, MutableVector}; use slice::{MutableTotalOrdVector, OwnedVector, Vector}; @@ -91,12 +89,14 @@ impl Vec { /// let vec: Vec = Vec::with_capacity(10); /// ``` pub fn with_capacity(capacity: uint) -> Vec { - if size_of::() == 0 { return Vec { len: 0, cap: ::uint::MAX, ptr: 0 as *mut T } } - if capacity == 0 { + if mem::size_of::() == 0 { + Vec { len: 0, cap: ::uint::MAX, ptr: 0 as *mut T } + } else if capacity == 0 { Vec::new() } else { - let size = capacity.checked_mul(&size_of::()).expect("capacity overflow"); - let ptr = unsafe { allocate(size, min_align_of::()) }; + let size = capacity.checked_mul(&mem::size_of::()) + .expect("capacity overflow"); + let ptr = unsafe { allocate(size, mem::min_align_of::()) }; Vec { len: 0, cap: capacity, ptr: ptr as *mut T } } } @@ -117,7 +117,8 @@ impl Vec { unsafe { let mut xs = Vec::with_capacity(length); while xs.len < length { - move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), op(xs.len)); + mem::move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), + op(xs.len)); xs.len += 1; } xs @@ -133,7 +134,8 @@ impl Vec { /// - there must be `length` valid instances of type `T` at the /// beginning of that allocation /// - `ptr` must be allocated by the default `Vec` allocator - pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut T) -> Vec { + pub unsafe fn from_raw_parts(length: uint, capacity: uint, + ptr: *mut T) -> Vec { Vec { len: length, cap: capacity, ptr: ptr } } @@ -212,7 +214,8 @@ impl Vec { unsafe { let mut xs = Vec::with_capacity(length); while xs.len < length { - move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), value.clone()); + mem::move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), + value.clone()); xs.len += 1; } xs @@ -405,16 +408,19 @@ impl Container for Vec { #[inline(never)] unsafe fn alloc_or_realloc(ptr: *mut T, size: uint, old_size: uint) -> *mut T { if old_size == 0 { - allocate(size, min_align_of::()) as *mut T + allocate(size, mem::min_align_of::()) as *mut T } else { - reallocate(ptr as *mut u8, size, min_align_of::(), old_size) as *mut T + reallocate(ptr as *mut u8, size, + mem::min_align_of::(), old_size) as *mut T } } #[inline] unsafe fn dealloc(ptr: *mut T, len: uint) { - if size_of::() != 0 { - deallocate(ptr as *mut u8, len * size_of::(), min_align_of::()) + if mem::size_of::() != 0 { + deallocate(ptr as *mut u8, + len * mem::size_of::(), + mem::min_align_of::()) } } @@ -494,11 +500,14 @@ impl Vec { /// assert_eq!(vec.capacity(), 11); /// ``` pub fn reserve_exact(&mut self, capacity: uint) { - if size_of::() == 0 { return } + if mem::size_of::() == 0 { return } + if capacity > self.cap { - let size = capacity.checked_mul(&size_of::()).expect("capacity overflow"); + let size = capacity.checked_mul(&mem::size_of::()) + .expect("capacity overflow"); unsafe { - self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::()); + self.ptr = alloc_or_realloc(self.ptr, size, + self.cap * mem::size_of::()); } self.cap = capacity; } @@ -513,7 +522,8 @@ impl Vec { /// vec.shrink_to_fit(); /// ``` pub fn shrink_to_fit(&mut self) { - if size_of::() == 0 { return } + if mem::size_of::() == 0 { return } + if self.len == 0 { if self.cap != 0 { unsafe { @@ -523,9 +533,12 @@ impl Vec { } } else { unsafe { - // Overflow check is unnecessary as the vector is already at least this large. - self.ptr = reallocate(self.ptr as *mut u8, self.len * size_of::(), - min_align_of::(), self.cap * size_of::()) as *mut T; + // Overflow check is unnecessary as the vector is already at + // least this large. + self.ptr = reallocate(self.ptr as *mut u8, + self.len * mem::size_of::(), + mem::min_align_of::(), + self.cap * mem::size_of::()) as *mut T; } self.cap = self.len; } @@ -568,25 +581,26 @@ impl Vec { /// ``` #[inline] pub fn push(&mut self, value: T) { - if size_of::() == 0 { + if mem::size_of::() == 0 { // zero-size types consume no memory, so we can't rely on the address space running out self.len = self.len.checked_add(&1).expect("length overflow"); - unsafe { forget(value); } + unsafe { mem::forget(value); } return } if self.len == self.cap { - let old_size = self.cap * size_of::(); - let size = max(old_size, 2 * size_of::()) * 2; + let old_size = self.cap * mem::size_of::(); + let size = max(old_size, 2 * mem::size_of::()) * 2; if old_size > size { fail!("capacity overflow") } unsafe { - self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::()); + self.ptr = alloc_or_realloc(self.ptr, size, + self.cap * mem::size_of::()); } self.cap = max(self.cap, 2) * 2; } unsafe { let end = (self.ptr as *T).offset(self.len as int) as *mut T; - move_val_init(&mut *end, value); + mem::move_val_init(&mut *end, value); self.len += 1; } } @@ -644,7 +658,7 @@ impl Vec { #[inline] pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { - transmute(Slice { data: self.as_mut_ptr() as *T, len: self.len }) + mem::transmute(Slice { data: self.as_mut_ptr() as *T, len: self.len }) } } @@ -664,10 +678,10 @@ impl Vec { #[inline] pub fn move_iter(self) -> MoveItems { unsafe { - let iter = transmute(self.as_slice().iter()); + let iter = mem::transmute(self.as_slice().iter()); let ptr = self.ptr; let cap = self.cap; - forget(self); + mem::forget(self); MoveItems { allocation: ptr, cap: cap, iter: iter } } } @@ -949,7 +963,7 @@ impl Vec { ptr::copy_memory(p.offset(1), &*p, len - index); // Write it in, overwriting the first copy of the `index`th // element. - move_val_init(&mut *p, element); + mem::move_val_init(&mut *p, element); } self.set_len(len + 1); } @@ -1395,7 +1409,7 @@ impl Vector for Vec { /// ``` #[inline] fn as_slice<'a>(&'a self) -> &'a [T] { - unsafe { transmute(Slice { data: self.as_ptr(), len: self.len }) } + unsafe { mem::transmute(Slice { data: self.as_ptr(), len: self.len }) } } } @@ -1538,7 +1552,7 @@ impl FromVec for ~[T] { // as it still needs to free its own allocation. v.set_len(0); - transmute(ret) + mem::transmute(ret) } } } diff --git a/src/libsync/arc.rs b/src/libsync/arc.rs index 226eb7afb5f80..4dc965d5d841c 100644 --- a/src/libsync/arc.rs +++ b/src/libsync/arc.rs @@ -13,7 +13,7 @@ * between tasks. */ -use std::cast; +use std::mem; use std::ptr; use std::rt::heap::exchange_free; use std::sync::atomics; @@ -76,7 +76,7 @@ impl Arc { weak: atomics::AtomicUint::new(1), data: data, }; - Arc { x: unsafe { cast::transmute(x) } } + Arc { x: unsafe { mem::transmute(x) } } } #[inline] @@ -149,7 +149,7 @@ impl Arc { // reference count is guaranteed to be 1 at this point, and we required // the Arc itself to be `mut`, so we're returning the only possible // reference to the inner data. - unsafe { cast::transmute::<&_, &mut _>(self.deref()) } + unsafe { mem::transmute::<&_, &mut _>(self.deref()) } } } diff --git a/src/libsync/mpsc_intrusive.rs b/src/libsync/mpsc_intrusive.rs index 14dfa8417fac9..acbb2982c9031 100644 --- a/src/libsync/mpsc_intrusive.rs +++ b/src/libsync/mpsc_intrusive.rs @@ -33,7 +33,7 @@ // http://www.1024cores.net/home/lock-free-algorithms // /queues/intrusive-mpsc-node-based-queue -use std::cast; +use std::mem; use std::sync::atomics; use std::ty::Unsafe; @@ -97,7 +97,7 @@ impl Queue { pub unsafe fn pop(&self) -> Option<*mut Node> { let tail = *self.tail.get(); let mut tail = if !tail.is_null() {tail} else { - cast::transmute(&self.stub) + mem::transmute(&self.stub) }; let mut next = (*tail).next(atomics::Relaxed); if tail as uint == &self.stub as *DummyNode as uint { @@ -116,7 +116,7 @@ impl Queue { if tail != head { return None; } - let stub = cast::transmute(&self.stub); + let stub = mem::transmute(&self.stub); self.push(stub); next = (*tail).next(atomics::Relaxed); if !next.is_null() { @@ -135,6 +135,6 @@ impl Node { } } pub unsafe fn next(&self, ord: atomics::Ordering) -> *mut Node { - cast::transmute::>(self.next.load(ord)) + mem::transmute::>(self.next.load(ord)) } } diff --git a/src/libsync/raw.rs b/src/libsync/raw.rs index 313720fa932dc..990aba3ebff61 100644 --- a/src/libsync/raw.rs +++ b/src/libsync/raw.rs @@ -15,9 +15,8 @@ //! `sync` crate which wrap values directly and provide safer abstractions for //! containing data. -use std::cast; use std::kinds::marker; -use std::mem::replace; +use std::mem; use std::sync::atomics; use std::unstable::finally::Finally; @@ -109,7 +108,7 @@ struct SemGuard<'a, Q> { impl Sem { fn new(count: int, q: Q) -> Sem { let inner = unsafe { - cast::transmute(box SemInner { + mem::transmute(box SemInner { waiters: WaitQueue::new(), count: count, blocked: q, @@ -168,7 +167,7 @@ impl Sem { impl Drop for Sem { fn drop(&mut self) { let _waiters: Box> = unsafe { - cast::transmute(self.inner) + mem::transmute(self.inner) }; self.inner = 0 as *(); } @@ -317,8 +316,8 @@ impl<'a> Condvar<'a> { // To avoid :broadcast_heavy, we make a new waitqueue, // swap it out with the old one, and broadcast on the // old one outside of the little-lock. - queue = Some(replace(state.blocked.get_mut(condvar_id), - WaitQueue::new())); + queue = Some(mem::replace(state.blocked.get_mut(condvar_id), + WaitQueue::new())); } else { out_of_bounds = Some(state.blocked.len()); } @@ -578,7 +577,7 @@ impl<'a> RWLockWriteGuard<'a> { let lock = self.lock; // Don't run the destructor of the write guard, we're in charge of // things from now on - unsafe { cast::forget(self) } + unsafe { mem::forget(self) } let old_count = lock.read_count.fetch_add(1, atomics::Release); // If another reader was already blocking, we need to hand-off @@ -626,7 +625,7 @@ mod tests { use arc::Arc; use super::{Semaphore, Mutex, RWLock, Condvar}; - use std::cast; + use std::mem; use std::result; use std::task; @@ -902,7 +901,7 @@ mod tests { let ptr: *int = &*sharedstate; task::spawn(proc() { let sharedstate: &mut int = - unsafe { cast::transmute(ptr) }; + unsafe { mem::transmute(ptr) }; access_shared(sharedstate, &x2, mode1, 10); tx.send(()); }); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 0f3b96c2132b6..84525718bd95b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -29,9 +29,9 @@ use visit; use visit::Visitor; use util::small_vector::SmallVector; -use std::cast; -use std::unstable::dynamic_lib::DynamicLibrary; +use std::mem; use std::os; +use std::unstable::dynamic_lib::DynamicLibrary; pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr { match e.node { @@ -544,7 +544,7 @@ fn load_extern_macros(krate: &ast::ViewItem, fld: &mut MacroExpander) { // Intentionally leak the dynamic library. We can't ever unload it // since the library can do things that will outlive the expansion // phase (e.g. make an @-box cycle or launch a task). - cast::forget(lib); + mem::forget(lib); } } diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 57529228b51f9..f93c3576943ef 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -10,7 +10,7 @@ use std::default::Default; use std::hash::Hash; -use std::{cast, mem, raw, ptr, slice}; +use std::{mem, raw, ptr, slice}; use serialize::{Encodable, Decodable, Encoder, Decoder}; /// A non-growable owned slice. This would preferably become `~[T]` @@ -48,7 +48,7 @@ impl OwnedSlice { } else { let p = v.as_mut_ptr(); // we own the allocation now - unsafe {cast::forget(v)} + unsafe {mem::forget(v)} OwnedSlice { data: p, len: len } } @@ -60,7 +60,7 @@ impl OwnedSlice { unsafe { let ret = Vec::from_raw_parts(self.len, self.len, self.data); // the vector owns the allocation now - cast::forget(self); + mem::forget(self); ret } } @@ -74,7 +74,7 @@ impl OwnedSlice { self.data as *T }; - let slice: &[T] = unsafe {cast::transmute(raw::Slice { + let slice: &[T] = unsafe {mem::transmute(raw::Slice { data: ptr, len: self.len })}; diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 8fb2fe61b833d..3888ed6b8d1d4 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -17,9 +17,9 @@ use util::interner::{RcStr, StrInterner}; use util::interner; use serialize::{Decodable, Decoder, Encodable, Encoder}; -use std::cast; use std::fmt; use std::path::BytesContainer; +use std::mem; use std::rc::Rc; use std::strbuf::StrBuf; @@ -585,7 +585,7 @@ impl BytesContainer for InternedString { // DST. unsafe { let this = self.get(); - cast::transmute(this.container_as_bytes()) + mem::transmute(this.container_as_bytes()) } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8486a8aeb352c..71c2f6337e0e6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -26,9 +26,9 @@ use print::pp::{break_offset, word, space, zerobreak, hardbreak}; use print::pp::{Breaks, Consistent, Inconsistent, eof}; use print::pp; -use std::cast; use std::io::{IoResult, MemWriter}; use std::io; +use std::mem; use std::rc::Rc; use std::str; use std::strbuf::StrBuf; @@ -140,9 +140,9 @@ pub fn to_str(f: |&mut State| -> IoResult<()>) -> StrBuf { // FIXME(pcwalton): A nasty function to extract the string from an `io::Writer` // that we "know" to be a `MemWriter` that works around the lack of checked // downcasts. - let (_, wr): (uint, Box) = cast::transmute_copy(&s.s.out); + let (_, wr): (uint, Box) = mem::transmute_copy(&s.s.out); let result = str::from_utf8_owned(wr.get_ref().to_owned()).unwrap(); - cast::forget(wr); + mem::forget(wr); result.to_strbuf() } } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 7f85684572286..c3c9596bfc469 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -15,11 +15,11 @@ use ast::Name; use collections::HashMap; -use std::cast; use std::cell::RefCell; use std::cmp::Equiv; use std::fmt; use std::hash::Hash; +use std::mem; use std::rc::Rc; pub struct Interner { @@ -198,7 +198,7 @@ impl StrInterner { let vect = self.vect.borrow(); let s: &str = vect.get(idx as uint).as_slice(); unsafe { - cast::transmute(s) + mem::transmute(s) } } diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 060c40b04d838..25188d699beb4 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -71,7 +71,7 @@ extern crate test; extern crate rand; extern crate serialize; -use std::cast::{transmute,transmute_copy}; +use std::mem::{transmute,transmute_copy}; use std::char::Char; use std::default::Default; use std::fmt; diff --git a/src/test/auxiliary/issue_8401.rs b/src/test/auxiliary/issue_8401.rs index 9e4d90e979ded..0831993119ae8 100644 --- a/src/test/auxiliary/issue_8401.rs +++ b/src/test/auxiliary/issue_8401.rs @@ -10,7 +10,7 @@ // for this issue, this code must be built in a library -use std::cast; +use std::mem; trait A {} struct B; @@ -20,6 +20,6 @@ fn bar(_: &mut A, _: &T) {} fn foo(t: &T) { let b = B; - bar(unsafe { cast::transmute(&b as &A) }, t) + bar(unsafe { mem::transmute(&b as &A) }, t) } diff --git a/src/test/compile-fail/coerce-unsafe-to-closure.rs b/src/test/compile-fail/coerce-unsafe-to-closure.rs index c22c4014f47bf..d9fbc08b3211d 100644 --- a/src/test/compile-fail/coerce-unsafe-to-closure.rs +++ b/src/test/compile-fail/coerce-unsafe-to-closure.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() { - let x: Option<&[u8]> = Some("foo").map(std::cast::transmute); + let x: Option<&[u8]> = Some("foo").map(std::mem::transmute); //~^ ERROR: mismatched types } diff --git a/src/test/compile-fail/issue-6458-3.rs b/src/test/compile-fail/issue-6458-3.rs index ac41cc116825a..4e0131a580128 100644 --- a/src/test/compile-fail/issue-6458-3.rs +++ b/src/test/compile-fail/issue-6458-3.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; +use std::mem; fn main() { - cast::transmute(0); //~ ERROR: cannot determine a type for this expression: unconstrained type + mem::transmute(0); //~ ERROR: cannot determine a type for this expression: unconstrained type } diff --git a/src/test/compile-fail/packed-struct-generic-transmute.rs b/src/test/compile-fail/packed-struct-generic-transmute.rs index c74d80df5dc27..45e6b76e20038 100644 --- a/src/test/compile-fail/packed-struct-generic-transmute.rs +++ b/src/test/compile-fail/packed-struct-generic-transmute.rs @@ -15,7 +15,7 @@ // error-pattern: transmute called on types with different size -use std::cast; +use std::mem; #[packed] struct Foo { @@ -31,7 +31,7 @@ struct Oof { fn main() { let foo = Foo { bar: [1u8, 2, 3, 4, 5], baz: 10i32 }; unsafe { - let oof: Oof<[u8, .. 5], i32> = cast::transmute(foo); + let oof: Oof<[u8, .. 5], i32> = mem::transmute(foo); println!("{:?}", oof); } } diff --git a/src/test/compile-fail/packed-struct-transmute.rs b/src/test/compile-fail/packed-struct-transmute.rs index b9a8a53469d5a..24be7d3a2972f 100644 --- a/src/test/compile-fail/packed-struct-transmute.rs +++ b/src/test/compile-fail/packed-struct-transmute.rs @@ -15,7 +15,7 @@ // error-pattern: transmute called on types with different size -use std::cast; +use std::mem; #[packed] struct Foo { @@ -31,7 +31,7 @@ struct Oof { fn main() { let foo = Foo { bar: 1, baz: 10 }; unsafe { - let oof: Oof = cast::transmute(foo); + let oof: Oof = mem::transmute(foo); println!("{:?}", oof); } } diff --git a/src/test/debuginfo/nil-enum.rs b/src/test/debuginfo/nil-enum.rs index 67c7eb30da6ed..43d82e75c4dda 100644 --- a/src/test/debuginfo/nil-enum.rs +++ b/src/test/debuginfo/nil-enum.rs @@ -32,8 +32,8 @@ enum AnotherNilEnum {} // 2. That gdb prints the string "{}" for empty structs (which may change some time) fn main() { unsafe { - let first: ANilEnum = std::cast::transmute(()); - let second: AnotherNilEnum = std::cast::transmute(()); + let first: ANilEnum = std::mem::transmute(()); + let second: AnotherNilEnum = std::mem::transmute(()); zzz(); } diff --git a/src/test/debuginfo/option-like-enum.rs b/src/test/debuginfo/option-like-enum.rs index b60c9c4a4b967..5c44703f6f2c9 100644 --- a/src/test/debuginfo/option-like-enum.rs +++ b/src/test/debuginfo/option-like-enum.rs @@ -69,21 +69,21 @@ struct NamedFieldsRepr<'a> { fn main() { - let some: Option<&u32> = Some(unsafe { std::cast::transmute(0x12345678) }); + let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678) }); let none: Option<&u32> = None; - let full = Full(454545, unsafe { std::cast::transmute(0x87654321) }, 9988); + let full = Full(454545, unsafe { std::mem::transmute(0x87654321) }, 9988); let int_val = 0; - let empty: &MoreFieldsRepr = unsafe { std::cast::transmute(&Empty) }; + let empty: &MoreFieldsRepr = unsafe { std::mem::transmute(&Empty) }; let droid = Droid { id: 675675, range: 10000001, - internals: unsafe { std::cast::transmute(0x43218765) } + internals: unsafe { std::mem::transmute(0x43218765) } }; - let void_droid: &NamedFieldsRepr = unsafe { std::cast::transmute(&Void) }; + let void_droid: &NamedFieldsRepr = unsafe { std::mem::transmute(&Void) }; zzz(); } diff --git a/src/test/run-fail/unwind-box-res.rs b/src/test/run-fail/unwind-box-res.rs index ecaae7f5cc72d..2044d6f1cc815 100644 --- a/src/test/run-fail/unwind-box-res.rs +++ b/src/test/run-fail/unwind-box-res.rs @@ -12,7 +12,7 @@ #![feature(managed_boxes)] -use std::cast; +use std::mem; fn failfn() { fail!(); @@ -25,7 +25,7 @@ struct r { impl Drop for r { fn drop(&mut self) { unsafe { - let _v2: Box = cast::transmute(self.v); + let _v2: Box = mem::transmute(self.v); } } } @@ -39,8 +39,8 @@ fn r(v: *int) -> r { fn main() { unsafe { let i1 = box 0; - let i1p = cast::transmute_copy(&i1); - cast::forget(i1); + let i1p = mem::transmute_copy(&i1); + mem::forget(i1); let x = @r(i1p); failfn(); println!("{:?}", x); diff --git a/src/test/run-make/mixing-deps/dylib.rs b/src/test/run-make/mixing-deps/dylib.rs index cb74a5eb240ab..d60cc05cc9f9c 100644 --- a/src/test/run-make/mixing-deps/dylib.rs +++ b/src/test/run-make/mixing-deps/dylib.rs @@ -11,6 +11,6 @@ #![crate_type = "dylib"] extern crate both; -use std::cast; +use std::mem; -pub fn addr() -> uint { unsafe { cast::transmute(&both::foo) } } +pub fn addr() -> uint { unsafe { mem::transmute(&both::foo) } } diff --git a/src/test/run-make/mixing-deps/prog.rs b/src/test/run-make/mixing-deps/prog.rs index ed8675eb7064f..8006987e9f349 100644 --- a/src/test/run-make/mixing-deps/prog.rs +++ b/src/test/run-make/mixing-deps/prog.rs @@ -11,9 +11,9 @@ extern crate dylib; extern crate both; -use std::cast; +use std::mem; fn main() { - assert_eq!(unsafe { cast::transmute::<&int, uint>(&both::foo) }, + assert_eq!(unsafe { mem::transmute::<&int, uint>(&both::foo) }, dylib::addr()); } diff --git a/src/test/run-pass/binops.rs b/src/test/run-pass/binops.rs index 3e3d9aab84e89..331e947586ab8 100644 --- a/src/test/run-pass/binops.rs +++ b/src/test/run-pass/binops.rs @@ -48,9 +48,9 @@ fn test_box() { fn test_ptr() { unsafe { - let p1: *u8 = ::std::cast::transmute(0); - let p2: *u8 = ::std::cast::transmute(0); - let p3: *u8 = ::std::cast::transmute(1); + let p1: *u8 = ::std::mem::transmute(0); + let p2: *u8 = ::std::mem::transmute(0); + let p3: *u8 = ::std::mem::transmute(1); assert_eq!(p1, p2); assert!(p1 != p3); @@ -82,8 +82,8 @@ fn test_class() { unsafe { println!("q = {:x}, r = {:x}", - (::std::cast::transmute::<*p, uint>(&q)), - (::std::cast::transmute::<*p, uint>(&r))); + (::std::mem::transmute::<*p, uint>(&q)), + (::std::mem::transmute::<*p, uint>(&r))); } assert_eq!(q, r); r.y = 17; diff --git a/src/test/run-pass/closure-reform.rs b/src/test/run-pass/closure-reform.rs index de7bdd15fa25e..202ec7edb1939 100644 --- a/src/test/run-pass/closure-reform.rs +++ b/src/test/run-pass/closure-reform.rs @@ -11,7 +11,7 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -use std::cast; +use std::mem; use std::io::stdio::println; fn call_it(f: proc(~str) -> ~str) { @@ -74,7 +74,7 @@ pub fn main() { call_cramped(|| 1, || unsafe { static a: uint = 100; - cast::transmute(&a) + mem::transmute(&a) }); // External functions diff --git a/src/test/run-pass/enum-alignment.rs b/src/test/run-pass/enum-alignment.rs index 5763c61379865..2a8293fcba8d0 100644 --- a/src/test/run-pass/enum-alignment.rs +++ b/src/test/run-pass/enum-alignment.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; use std::mem; fn addr_of(ptr: &T) -> uint { @@ -17,7 +16,7 @@ fn addr_of(ptr: &T) -> uint { fn is_aligned(ptr: &T) -> bool { unsafe { - let addr: uint = cast::transmute(ptr); + let addr: uint = mem::transmute(ptr); (addr % mem::min_align_of::()) == 0 } } diff --git a/src/test/run-pass/enum-clike-ffi-as-int.rs b/src/test/run-pass/enum-clike-ffi-as-int.rs index 0c897b959a5a3..41e5381d73c2b 100644 --- a/src/test/run-pass/enum-clike-ffi-as-int.rs +++ b/src/test/run-pass/enum-clike-ffi-as-int.rs @@ -33,7 +33,7 @@ extern "C" fn foo(_x: uint) -> Foo { B } pub fn main() { unsafe { - let f: extern "C" fn(uint) -> u32 = ::std::cast::transmute(foo); + let f: extern "C" fn(uint) -> u32 = ::std::mem::transmute(foo); assert_eq!(f(0xDEADBEEF), B as u32); } } diff --git a/src/test/run-pass/foreign-call-no-runtime.rs b/src/test/run-pass/foreign-call-no-runtime.rs index 147cfb16fa2fd..b56847b2da0d6 100644 --- a/src/test/run-pass/foreign-call-no-runtime.rs +++ b/src/test/run-pass/foreign-call-no-runtime.rs @@ -10,7 +10,7 @@ extern crate libc; -use std::cast; +use std::mem; use std::unstable::run_in_bare_thread; #[link(name = "rustrt")] @@ -23,14 +23,14 @@ pub fn main() { unsafe { run_in_bare_thread(proc() { let i = &100; - rust_dbg_call(callback, cast::transmute(i)); + rust_dbg_call(callback, mem::transmute(i)); }); } } extern fn callback(data: libc::uintptr_t) { unsafe { - let data: *int = cast::transmute(data); + let data: *int = mem::transmute(data); assert_eq!(*data, 100); } } diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 9227477c31e91..1ac3602293807 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -149,7 +149,7 @@ pub fn main() { // make sure that format! doesn't cause spurious unused-unsafe warnings when // it's inside of an outer unsafe block unsafe { - let a: int = ::std::cast::transmute(3u); + let a: int = ::std::mem::transmute(3u); format!("{}", a); } diff --git a/src/test/run-pass/intrinsic-move-val.rs b/src/test/run-pass/intrinsic-move-val.rs index 5f5c1444819d2..752c9464cf620 100644 --- a/src/test/run-pass/intrinsic-move-val.rs +++ b/src/test/run-pass/intrinsic-move-val.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast::transmute; +use std::mem::transmute; mod rusti { extern "rust-intrinsic" { diff --git a/src/test/run-pass/issue-2214.rs b/src/test/run-pass/issue-2214.rs index 1fa9fa8f4fb34..a319ee5e600cc 100644 --- a/src/test/run-pass/issue-2214.rs +++ b/src/test/run-pass/issue-2214.rs @@ -11,12 +11,12 @@ extern crate libc; -use std::cast; +use std::mem; use libc::{c_double, c_int}; fn to_c_int(v: &mut int) -> &mut c_int { unsafe { - cast::transmute_copy(&v) + mem::transmute_copy(&v) } } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 2b1ba332841cb..9636a61269cae 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -14,9 +14,9 @@ pub type Task = int; // tjc: I don't know why pub mod pipes { use super::Task; - use std::cast::{forget, transmute}; - use std::cast; + use std::mem::{forget, transmute}; use std::mem::{replace, swap}; + use std::mem; use std::task; pub struct Stuff { @@ -42,7 +42,7 @@ pub mod pipes { pub fn packet() -> *packet { unsafe { - let p: *packet = cast::transmute(box Stuff{ + let p: *packet = mem::transmute(box Stuff{ state: empty, blocked_task: None::, payload: None:: @@ -60,7 +60,7 @@ pub mod pipes { // We should consider moving this to ::std::unsafe, although I // suspect graydon would want us to use void pointers instead. pub unsafe fn uniquify(x: *T) -> Box { - cast::transmute(x) + mem::transmute(x) } pub fn swap_state_acq(dst: &mut state, src: state) -> state { @@ -165,7 +165,7 @@ pub mod pipes { unsafe { if self.p != None { let self_p: &mut Option<*packet> = - cast::transmute(&self.p); + mem::transmute(&self.p); let p = replace(self_p, None); sender_terminate(p.unwrap()) } @@ -195,7 +195,7 @@ pub mod pipes { unsafe { if self.p != None { let self_p: &mut Option<*packet> = - cast::transmute(&self.p); + mem::transmute(&self.p); let p = replace(self_p, None); receiver_terminate(p.unwrap()) } @@ -222,7 +222,7 @@ pub mod pipes { } pub mod pingpong { - use std::cast; + use std::mem; pub struct ping(::pipes::send_packet); pub struct pong(::pipes::send_packet); @@ -230,7 +230,7 @@ pub mod pingpong { pub fn liberate_ping(p: ping) -> ::pipes::send_packet { unsafe { let _addr : *::pipes::send_packet = match &p { - &ping(ref x) => { cast::transmute(x) } + &ping(ref x) => { mem::transmute(x) } }; fail!() } @@ -239,7 +239,7 @@ pub mod pingpong { pub fn liberate_pong(p: pong) -> ::pipes::send_packet { unsafe { let _addr : *::pipes::send_packet = match &p { - &pong(ref x) => { cast::transmute(x) } + &pong(ref x) => { mem::transmute(x) } }; fail!() } diff --git a/src/test/run-pass/issue-4735.rs b/src/test/run-pass/issue-4735.rs index e89e661e9d847..d96568df63a4d 100644 --- a/src/test/run-pass/issue-4735.rs +++ b/src/test/run-pass/issue-4735.rs @@ -12,7 +12,7 @@ extern crate libc; -use std::cast::transmute; +use std::mem::transmute; use libc::c_void; struct NonCopyable(*c_void); diff --git a/src/test/run-pass/nullable-pointer-iotareduction.rs b/src/test/run-pass/nullable-pointer-iotareduction.rs index 04b2e94f1a0c7..fb61bea83da8d 100644 --- a/src/test/run-pass/nullable-pointer-iotareduction.rs +++ b/src/test/run-pass/nullable-pointer-iotareduction.rs @@ -10,7 +10,7 @@ #![feature(macro_rules)] -use std::{option, cast}; +use std::{option, mem}; // Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions, // which "says that a destructor applied to an object built from a constructor @@ -78,8 +78,8 @@ pub fn main() { check_type!(@19: @int); check_type!("foo".to_owned(): ~str); check_type!(vec!(20, 22): Vec ); - let mint: uint = unsafe { cast::transmute(main) }; + let mint: uint = unsafe { mem::transmute(main) }; check_type!(main: fn(), |pthing| { - assert!(mint == unsafe { cast::transmute(*pthing) }) + assert!(mint == unsafe { mem::transmute(*pthing) }) }); } diff --git a/src/test/run-pass/packed-struct-generic-layout.rs b/src/test/run-pass/packed-struct-generic-layout.rs index 8b20b8e14c483..202697661582f 100644 --- a/src/test/run-pass/packed-struct-generic-layout.rs +++ b/src/test/run-pass/packed-struct-generic-layout.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; +use std::mem; #[packed] struct S { @@ -20,7 +20,7 @@ struct S { pub fn main() { unsafe { let s = S { a: 0xff_ff_ff_ffu32, b: 1, c: 0xaa_aa_aa_aa as i32 }; - let transd : [u8, .. 9] = cast::transmute(s); + let transd : [u8, .. 9] = mem::transmute(s); // Don't worry about endianness, the numbers are palindromic. assert!(transd == [0xff, 0xff, 0xff, 0xff, @@ -29,7 +29,7 @@ pub fn main() { let s = S { a: 1u8, b: 2u8, c: 0b10000001_10000001 as i16}; - let transd : [u8, .. 4] = cast::transmute(s); + let transd : [u8, .. 4] = mem::transmute(s); // Again, no endianness problems. assert!(transd == [1, 2, 0b10000001, 0b10000001]); diff --git a/src/test/run-pass/packed-struct-layout.rs b/src/test/run-pass/packed-struct-layout.rs index 0dc781805007e..7f9bf8e7d57fe 100644 --- a/src/test/run-pass/packed-struct-layout.rs +++ b/src/test/run-pass/packed-struct-layout.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; +use std::mem; #[packed] struct S4 { @@ -25,11 +25,11 @@ struct S5 { pub fn main() { unsafe { let s4 = S4 { a: 1, b: [2,3,4] }; - let transd : [u8, .. 4] = cast::transmute(s4); + let transd : [u8, .. 4] = mem::transmute(s4); assert!(transd == [1, 2, 3, 4]); let s5 = S5 { a: 1, b: 0xff_00_00_ff }; - let transd : [u8, .. 5] = cast::transmute(s5); + let transd : [u8, .. 5] = mem::transmute(s5); // Don't worry about endianness, the u32 is palindromic. assert!(transd == [1, 0xff, 0, 0, 0xff]); } diff --git a/src/test/run-pass/packed-tuple-struct-layout.rs b/src/test/run-pass/packed-tuple-struct-layout.rs index 0cdaeddf25db3..3ec6182beb261 100644 --- a/src/test/run-pass/packed-tuple-struct-layout.rs +++ b/src/test/run-pass/packed-tuple-struct-layout.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast; +use std::mem; #[packed] struct S4(u8,[u8, .. 3]); @@ -19,11 +19,11 @@ struct S5(u8,u32); pub fn main() { unsafe { let s4 = S4(1, [2,3,4]); - let transd : [u8, .. 4] = cast::transmute(s4); + let transd : [u8, .. 4] = mem::transmute(s4); assert!(transd == [1, 2, 3, 4]); let s5 = S5(1, 0xff_00_00_ff); - let transd : [u8, .. 5] = cast::transmute(s5); + let transd : [u8, .. 5] = mem::transmute(s5); // Don't worry about endianness, the u32 is palindromic. assert!(transd == [1, 0xff, 0, 0, 0xff]); } diff --git a/src/test/run-pass/pub-extern-privacy.rs b/src/test/run-pass/pub-extern-privacy.rs index 742df0f5c6d87..26bf06794ca0c 100644 --- a/src/test/run-pass/pub-extern-privacy.rs +++ b/src/test/run-pass/pub-extern-privacy.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast::transmute; +use std::mem::transmute; mod a { extern { diff --git a/src/test/run-pass/regions-mock-tcx.rs b/src/test/run-pass/regions-mock-tcx.rs index fabf4b7b42876..7e071177ff9f1 100644 --- a/src/test/run-pass/regions-mock-tcx.rs +++ b/src/test/run-pass/regions-mock-tcx.rs @@ -21,7 +21,6 @@ extern crate libc; use arena::Arena; use collections::HashMap; -use std::cast; use std::mem; type Type<'tcx> = &'tcx TypeStructure<'tcx>; diff --git a/src/test/run-pass/regions-mock-trans.rs b/src/test/run-pass/regions-mock-trans.rs index b0198d56e05a5..e6b997f758814 100644 --- a/src/test/run-pass/regions-mock-trans.rs +++ b/src/test/run-pass/regions-mock-trans.rs @@ -9,7 +9,6 @@ // except according to those terms. extern crate libc; -use std::cast; use std::mem; struct arena(()); @@ -29,7 +28,7 @@ struct Ccx { fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> { unsafe { - cast::transmute(libc::malloc(mem::size_of::>() + mem::transmute(libc::malloc(mem::size_of::>() as libc::size_t)) } } @@ -42,7 +41,7 @@ fn g(fcx : &Fcx) { let bcx = Bcx { fcx: fcx }; let bcx2 = h(&bcx); unsafe { - libc::free(cast::transmute(bcx2)); + libc::free(mem::transmute(bcx2)); } } diff --git a/src/test/run-pass/tag-align-dyn-u64.rs b/src/test/run-pass/tag-align-dyn-u64.rs index 72f2917a2129a..a260ad66ce294 100644 --- a/src/test/run-pass/tag-align-dyn-u64.rs +++ b/src/test/run-pass/tag-align-dyn-u64.rs @@ -11,7 +11,7 @@ // ignore-linux #7340 fails on 32-bit linux // ignore-macos #7340 fails on 32-bit macos -use std::cast; +use std::mem; enum Tag { Tag(A) @@ -27,7 +27,7 @@ fn mk_rec() -> Rec { } fn is_8_byte_aligned(u: &Tag) -> bool { - let p: uint = unsafe { cast::transmute(u) }; + let p: uint = unsafe { mem::transmute(u) }; return (p & 7u) == 0u; } diff --git a/src/test/run-pass/tag-align-dyn-variants.rs b/src/test/run-pass/tag-align-dyn-variants.rs index 70590b768b1d6..1e22f0f3dee80 100644 --- a/src/test/run-pass/tag-align-dyn-variants.rs +++ b/src/test/run-pass/tag-align-dyn-variants.rs @@ -11,7 +11,7 @@ // ignore-linux #7340 fails on 32-bit linux // ignore-macos #7340 fails on 32-bit macos -use std::cast; +use std::mem; enum Tag { VarA(A), @@ -30,7 +30,7 @@ fn mk_rec(a: A, b: B) -> Rec { } fn is_aligned(amnt: uint, u: &A) -> bool { - let p: uint = unsafe { cast::transmute(u) }; + let p: uint = unsafe { mem::transmute(u) }; return (p & (amnt-1u)) == 0u; } diff --git a/src/test/run-pass/tag-align-u64.rs b/src/test/run-pass/tag-align-u64.rs index 4c126d68fef90..f399606593655 100644 --- a/src/test/run-pass/tag-align-u64.rs +++ b/src/test/run-pass/tag-align-u64.rs @@ -11,7 +11,7 @@ // ignore-linux #7340 fails on 32-bit linux // ignore-macos #7340 fails on 32-bit macos -use std::cast; +use std::mem; enum Tag { Tag(u64) @@ -27,7 +27,7 @@ fn mk_rec() -> Rec { } fn is_8_byte_aligned(u: &Tag) -> bool { - let p: uint = unsafe { cast::transmute(u) }; + let p: uint = unsafe { mem::transmute(u) }; return (p & 7u) == 0u; } diff --git a/src/test/run-pass/transmute-non-immediate-to-immediate.rs b/src/test/run-pass/transmute-non-immediate-to-immediate.rs index 9cdcd8759527a..e070757eaf4ea 100644 --- a/src/test/run-pass/transmute-non-immediate-to-immediate.rs +++ b/src/test/run-pass/transmute-non-immediate-to-immediate.rs @@ -13,6 +13,6 @@ pub fn main() { unsafe { - ::std::cast::transmute::<[int,..1],int>([1]) + ::std::mem::transmute::<[int,..1],int>([1]) }; } diff --git a/src/test/run-pass/unify-return-ty.rs b/src/test/run-pass/unify-return-ty.rs index 953140fcfef92..7f46b0ff6e797 100644 --- a/src/test/run-pass/unify-return-ty.rs +++ b/src/test/run-pass/unify-return-ty.rs @@ -12,11 +12,11 @@ // unified with the type *T, and so the type variable // in that type gets resolved. -use std::cast; +use std::mem; fn null() -> *T { unsafe { - cast::transmute(0) + mem::transmute(0) } }